Skip to content

Commit

Permalink
Addressed ESLint and SonarQube warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
david-04 committed Apr 15, 2022
1 parent f2759f8 commit d2a90c2
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 642 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Change Log

## [0.3](https://github.com/david-04/aws-link-accountifier/tree/v0.3) (2022-02-25)
## [1.0](https://github.com/david-04/aws-link-accountifier/releases/tag/v1.0) (2022-04-15)

- Performed technical maintenance (ESLint and SonarQube)

## [0.3](https://github.com/david-04/aws-link-accountifier/releases/tag/v0.3) (2022-02-25)

- Added [documentation](https://github.com/david-04/aws-link-accountifier/blob/main/README.md)
- Improved the login page flow for currently unauthenticated SSO users
- Made it easier to customis forks by moving config presets to a [separate file](https://github.com/david-04/aws-link-accountifier/blob/main/src/modules/presets.ts)
- Made it easier to customize forks by moving config presets to a [separate file](https://github.com/david-04/aws-link-accountifier/blob/main/src/modules/presets.ts)
- Fixed an issue with the role-switch that could initiate a second account-switch

## [0.2](https://github.com/david-04/aws-link-accountifier/tree/v0.2) (2022-02-23)
## [0.2](https://github.com/david-04/aws-link-accountifier/releases/tag/v0.2) (2022-02-23)

- Improved link operability by adding a redirect service
- Added the option to re-open the current page with a different role

## [0.1](https://github.com/david-04/aws-link-accountifier/tree/v0.1) (2022-01-26)
## [0.1](https://github.com/david-04/aws-link-accountifier/releases/tag/v0.1) (2022-01-26)

- Added the ability to create "accountified" links
- Added orchestrated redirect flows when opening accountified links
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
autorun : dist/tampermonkey/aws-link-accountifier.js

dist/tampermonkey/aws-link-accountifier.js : $(wildcard src/* src/*/* src/*/*/*)
dist/tampermonkey/aws-link-accountifier.js : $(wildcard src/*.ts src/*/*.ts src/*/*/*.ts)
tsc
77 changes: 40 additions & 37 deletions dist/aws-link-accountifier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name AWS Link Accountifier
// @namespace https://github.com/david-04/aws-link-accountifier
// @version 0.3
// @version 1.0
// @author David Hofmann
// @description Bind AWS console links to an account and - when opening such links - trigger an account change if required
// @homepage https://github.com/david-04/aws-link-accountifier
Expand All @@ -25,7 +25,7 @@ var AwsLinkAccountifier;
const accountId = redirectState.requiredAccount.id;
const accountName = getDescriptiveAccountName(redirectState);
const banner = document.createElement("DIV");
banner.innerHTML = `Please sign in to account <b>${AwsLinkAccountifier.sanitise(accountName)}</b>`;
banner.innerHTML = `Please sign in to account <b>${AwsLinkAccountifier.sanitize(accountName)}</b>`;
const style = banner.style;
style.backgroundColor = "yellow";
style.fontSize = "1.4em";
Expand All @@ -43,20 +43,23 @@ var AwsLinkAccountifier;
//------------------------------------------------------------------------------------------------------------------
// Highlight the given account's login options
//------------------------------------------------------------------------------------------------------------------
function highlightAccount(accountId, colour) {
function highlightAccount(accountId, color) {
document.querySelectorAll("* * .saml-account-name").forEach(node => {
var _a, _b;
const element = node;
const innerText = element.innerText;
if (innerText.endsWith(` ${accountId}`) || innerText.endsWith(` (${accountId})`)) {
const style = element.parentElement.parentElement.style;
if (colour) {
style.backgroundColor = colour;
const style = (_b = (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.style;
if (style) {
if (color) {
style.backgroundColor = color;
}
else {
style.removeProperty("background-color");
}
style.paddingTop = "1.5em";
style.paddingBottom = "0.5em";
}
else {
style.removeProperty("background-color");
}
style.paddingTop = "1.5em";
style.paddingBottom = "0.5em";
}
});
}
Expand Down Expand Up @@ -84,7 +87,7 @@ var AwsLinkAccountifier;
//------------------------------------------------------------------------------------------------------------------
class AwsSession {
//--------------------------------------------------------------------------------------------------------------
// Initialisation
// Initialization
//--------------------------------------------------------------------------------------------------------------
constructor(accountId, accountAlias, role) {
this.accountId = accountId;
Expand Down Expand Up @@ -142,7 +145,7 @@ var AwsLinkAccountifier;
(function (AwsLinkAccountifier) {
let getAwsSessionCount = 0;
const isAwsConsole = window.location.host.toLowerCase().endsWith("aws.amazon.com");
const isAwsSignin = window.location.host.toLowerCase().endsWith("signin.aws.amazon.com");
const isAwsSignIn = window.location.host.toLowerCase().endsWith("signin.aws.amazon.com");
const isRedirectPage = 0 <= window.location.pathname.indexOf("aws-accountified-redirect.htm");
//------------------------------------------------------------------------------------------------------------------
// Extract the URL hint and start or schedule the redirect processing
Expand All @@ -151,7 +154,7 @@ var AwsLinkAccountifier;
if (isRedirectPage) {
processRedirectPage();
}
if (isAwsSignin) {
if (isAwsSignIn) {
const state = AwsLinkAccountifier.getRedirectState();
if (state && state.shouldAutoLogout) {
AwsLinkAccountifier.setRedirectState(Object.assign(Object.assign({}, state), { shouldAutoLogout: false }));
Expand All @@ -166,9 +169,9 @@ var AwsLinkAccountifier;
AwsLinkAccountifier.extractUrlHint();
AwsLinkAccountifier.onDOMContentLoaded(processNotificationsAndRedirects);
}
AwsLinkAccountifier.initialiseMenu({
copyLink: isAwsConsole && !isAwsSignin,
switchRole: isAwsConsole && !isAwsSignin,
AwsLinkAccountifier.initializeMenu({
copyLink: isAwsConsole && !isAwsSignIn,
switchRole: isAwsConsole && !isAwsSignIn,
setAccountSwitchUrl: isAwsConsole || isRedirectPage,
useThisPageForRedirects: isRedirectPage
});
Expand All @@ -181,7 +184,7 @@ var AwsLinkAccountifier;
document.removeEventListener("DOMContentLoaded", processNotificationsAndRedirects);
const redirectState = AwsLinkAccountifier.getRedirectState();
if (redirectState) {
if (isAwsSignin) {
if (isAwsSignIn) {
AwsLinkAccountifier.injectAccountSelectionHint(redirectState);
}
else if (isAwsConsole) {
Expand Down Expand Up @@ -245,9 +248,9 @@ var AwsLinkAccountifier;
var AwsLinkAccountifier;
(function (AwsLinkAccountifier) {
//------------------------------------------------------------------------------------------------------------------
// Initialise the context menu
// Initialize the context menu
//------------------------------------------------------------------------------------------------------------------
function initialiseMenu(options) {
function initializeMenu(options) {
if (options.copyLink) {
GM_registerMenuCommand("Copy link (redirect)", () => copyLinkToClipboard(AwsLinkAccountifier.createRedirectLink), "c");
GM_registerMenuCommand("Copy link (direct)", () => copyLinkToClipboard(AwsLinkAccountifier.createDirectLink), "d");
Expand All @@ -262,7 +265,7 @@ var AwsLinkAccountifier;
AwsLinkAccountifier.onDOMContentLoaded(setRedirectUrl);
}
}
AwsLinkAccountifier.initialiseMenu = initialiseMenu;
AwsLinkAccountifier.initializeMenu = initializeMenu;
//------------------------------------------------------------------------------------------------------------------
// Copy link to clipboard
//------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -388,7 +391,8 @@ var AwsLinkAccountifier;
// Retrieve settings
//------------------------------------------------------------------------------------------------------------------
function getSettings() {
return migrateSettings(Object.assign(Object.assign({}, DEFAULT_SETTINGS), GM_getValue("settings", DEFAULT_SETTINGS)));
var _a;
return migrateSettings(Object.assign(Object.assign({}, DEFAULT_SETTINGS), ((_a = GM_getValue("settings", DEFAULT_SETTINGS)) !== null && _a !== void 0 ? _a : {})));
}
AwsLinkAccountifier.getSettings = getSettings;
//------------------------------------------------------------------------------------------------------------------
Expand All @@ -402,16 +406,15 @@ var AwsLinkAccountifier;
// Migrate old settings
//------------------------------------------------------------------------------------------------------------------
function migrateSettings(settings) {
const data = settings;
if (data && "object" === typeof data) {
if (data.redirectService) {
if (!data.redirectUrl) {
data.redirectUrl = data.redirectService;
}
delete data.redirectService;
}
var _a;
const redirectUrl = (_a = settings.redirectUrl) !== null && _a !== void 0 ? _a : settings.redirectService;
delete settings.redirectService;
if ("string" === typeof redirectUrl) {
return Object.assign(Object.assign({}, settings), { redirectUrl });
}
else {
return settings;
}
return settings;
}
})(AwsLinkAccountifier || (AwsLinkAccountifier = {}));
var AwsLinkAccountifier;
Expand Down Expand Up @@ -480,12 +483,12 @@ var AwsLinkAccountifier;
try {
const json = JSON.parse(decodeURIComponent(hint));
if (!json || "object" !== typeof json || "string" !== typeof ((_a = json === null || json === void 0 ? void 0 : json.account) === null || _a === void 0 ? void 0 : _a.id)) {
throw `Invalid URL hint: ${hint} (account/id is missing)`;
throw new Error(`account/id is missing`);
}
return json;
}
catch (exception) {
throw `Invalid URL hint: ${hint} (${exception})`;
throw new Error(`Invalid URL hint: ${hint} - (${exception})`);
}
}
//------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -553,19 +556,19 @@ var AwsLinkAccountifier;
// Set a cookie
//------------------------------------------------------------------------------------------------------------------
function setCookie(name, value, domain, path, ttlMs) {
var expires = new Date(new Date().getTime() + ttlMs);
const expires = new Date(new Date().getTime() + ttlMs);
document.cookie = `${name}=${encodeURIComponent(value)};expires=${expires};domain=${domain};path=${path}`;
}
AwsLinkAccountifier.setCookie = setCookie;
//------------------------------------------------------------------------------------------------------------------
// Sanitise HTML content
// Sanitize HTML content
//------------------------------------------------------------------------------------------------------------------
function sanitise(text) {
function sanitize(text) {
return text.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
AwsLinkAccountifier.sanitise = sanitise;
AwsLinkAccountifier.sanitize = sanitize;
//------------------------------------------------------------------------------------------------------------------
// Execute the given callback when the page has been loaded
//------------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit d2a90c2

Please sign in to comment.