Skip to content

Commit

Permalink
ops Buddy first version
Browse files Browse the repository at this point in the history
  • Loading branch information
cibinmathew committed Apr 10, 2023
0 parents commit 391e59f
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 0 deletions.
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
junit.xml
dist.zip
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Cibin Mathew

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ops-buddy Chrome Extension
A Chrome Extension to visually differentiate between `QA` and `Prod` jenkins servers based on url pattern.

## Extension in action

![](./docs/screenshot-prod.png)

![](./docs/screenshot-qa.png)


## Installation
[Install](https://chrome.google.com/webstore/category/extensions?hl=en) from chrome webstore

## Configuration


Goto `extension options` page


![](./docs/options.png)

## Motivation
- [AWS Region Color Highlights](https://chrome.google.com/webstore/detail/aws-region-color-highligh/kdjchigefmkankimfkgolpfincgbffkg?hl=en)
- [AWS Colours](https://chrome.google.com/webstore/detail/aws-colours/pafgadpbmhggcdcncekcjllcaancmeej?hl=en)
- [AWS Extend Switch Roles](https://chrome.google.com/webstore/detail/aws-extend-switch-roles/jpmkfafbacpgapdghgdpembnojdlgkdl?hl=en)


## Resources

+ [chrome-extensions-samples](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main)
+ [chrome-extension-template](https://github.com/ClydeDz/chrome-extension-template)


### License

[MIT License](LICENSE)

### Privacy
[Privacy policy](docs/PRIVACY.md)
5 changes: 5 additions & 0 deletions docs/PRIVACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Privacy policy
This extension does not handle personal or sensitive user data and does not collect/share any information with the following exception
- extension settings are synced to logged in user's google account using [storage.sync](https://developer.chrome.com/docs/extensions/reference/storage/#storage-areas)

This can be verified in the source code or by scanning the network requests using Inspect tool of the browser.
Binary file added docs/options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-prod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot-qa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/background/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
chrome.runtime.onInstalled.addListener(function (object) {
if (object.reason === chrome.runtime.OnInstalledReason.INSTALL) {
chrome.tabs.create({ url: "https://github.com/cibinmathew/ops-buddy" });
}
});

chrome.runtime.onMessage.addListener((request) => {
if (request === "showOptions") {
chrome.runtime.openOptionsPage();
}
});
51 changes: 51 additions & 0 deletions src/content_scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const CHROME_SYNC_STORAGE_KEY = "ops-buddy-4633f243";

const componentKey = { qa_sites: "", prod_sites: "" };
const array = ["qa", "prod"]; // priority is more prod

const getStorage = (componentKey, callback) => {
chrome.storage.sync.get([componentKey], function (result) {
callback(result[componentKey]);
});
};

function changeBackground(result) {
var arr;
array.forEach(function (env, index) {
arr = result[env + "_sites"].split("\r\n|\n|\r").filter((e) => e);

for (var i = 0; i < arr.length; i++) {
console.log(i, window.location.origing);
// TODO strip '/' http://localhost:8089/
if (window.location.origin.match("^" + arr[i] + "$")) {
console.log(
"INFO:ops-buddy: matched env: " +
env +
" pattern: " +
arr[i] +
" url: " +
window.location.hostname
);
const acc_color_map = new Map([
["dev", "#968a1b"],
["qa", "green"],
["prod", "red"],
]);
color = acc_color_map.get(env);
if (document.getElementsByClassName("page-header").length > 0)
document.getElementsByClassName("page-header")[0].style.background =
color;
if (document.getElementsByClassName("jenkins-breadcrumbs").length > 0)
document.getElementsByClassName(
"jenkins-breadcrumbs"
)[0].style.background = color;
// if (document.getElementById('jenkins')!=null) document.getElementById('jenkins').style.background='violet'
// if (document.getElementsByTagName('body').length>0) document.getElementsByTagName('body')[0].style.background='gray'
}
}
});
}

window.onload = function () {
getStorage(CHROME_SYNC_STORAGE_KEY, changeBackground);
};
Binary file added src/icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"manifest_version": 3,
"name": "Ops Buddy",
"description": "Identify Jenkins environments to avoid mishaps",
"version": "1.0.0",
"author": "Cibin Mathew",
"icons": {
"128": "icons/icon128.png"
},
"permissions": [
"storage"
],
"options_page": "options/options.html",
"background": {
"service_worker": "background/index.js"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content_scripts/index.js"
]
}
],
"action": {
"default_title": "Open ops-buddy popup"
}
}
36 changes: 36 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title class="text-center">options</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<!-- todo change bootstrap cdn?? -->
<body class="container p-4">
<h2>Ops Buddy options</h1>
<p>
List of QA jenkins hostnames
<textarea id="qa_sites" class="form-control" name="message" rows="8" cols="60" placeholder="http://localhost:8089
http://qa.jenkins.example.com
https://staging2.jenkins.example.com"></textarea>
</p>
<p>
</p>
List of Prod jenkins hostnames
<textarea id="prod_sites" class="form-control" name="message" rows="8" cols="60" placeholder="https://prod.jenkins.example.com
https://jenkins.example.com"></textarea>
</p>
<p>
<div id="status" ></div>
</p>
<p>
<button id="save" class="btn btn-secondary" >Save</button>
</p>
<script src="options.js"></script>
</body>
<footer class="text-center text-lg-start bg-light text-muted">
<p>Settings stored using <a href="https://developer.chrome.com/docs/extensions/reference/storage/#storage-areas">storage.sync</a> </p>
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.05);">
<a href="https://github.com/cibinmathew/ops-buddy">Github</a>
</div>
</footer>
</html>
39 changes: 39 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const CHROME_SYNC_STORAGE_KEY = "ops-buddy-4633f243"; // unique key name to use storage

// Saves options to chrome.storage
const saveOptions = () => {
const qa_sites = document.getElementById("qa_sites").value;
const prod_sites = document.getElementById("prod_sites").value;

chrome.storage.sync.set(
{
[CHROME_SYNC_STORAGE_KEY]: { qa_sites: qa_sites, prod_sites: prod_sites },
},
() => {
// Update status to let user know options were saved.
const status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(() => {
status.textContent = "";
}, 750);
}
);
};

// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{ [CHROME_SYNC_STORAGE_KEY]: { qa_sites: "", prod_sites: "" } },
(items) => {
document.getElementById("prod_sites").value =
items[CHROME_SYNC_STORAGE_KEY]["prod_sites"];
document.getElementById("qa_sites").value =
items[CHROME_SYNC_STORAGE_KEY]["qa_sites"];
}
);
console.info("ops-buddy Options loaded");
};

document.addEventListener("DOMContentLoaded", restoreOptions);
document.getElementById("save").addEventListener("click", saveOptions);

0 comments on commit 391e59f

Please sign in to comment.