Skip to content

Commit

Permalink
Merge pull request #229 from tilfinltd/feature/action-subdomain
Browse files Browse the repository at this point in the history
Sign-in endpoint in current region
  • Loading branch information
tilfin authored Jan 10, 2022
2 parents 53e57d1 + 06f27c6 commit 09e2fa5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h1>Settings</h1>
<ul>
<li><label for="hidesAccountIdCheckBox"><input type="checkbox" id="hidesAccountIdCheckBox">Hide account id</label></li>
<li><label for="showOnlyMatchingRolesCheckBox"><input type="checkbox" id="showOnlyMatchingRolesCheckBox">Show only matching roles</label></li>
<li><label for="signinEndpointInHereCheckBox"><input type="checkbox" id="signinEndpointInHereCheckBox">Sign-in endpoint in current region</label> (Experimental, Supporters only) </li>
<li><s><label for="autoAssumeLastRoleCheckBox"><input type="checkbox" id="autoAssumeLastRoleCheckBox">Automatically assume last assumed role</label> (Experimental) </s> (temporarily disabled) </li>
<li>
Configuration storage:
Expand Down Expand Up @@ -244,6 +245,7 @@ <h3>Settings</h3>
<ul>
<li><b>Hide account id</b> hides the account_id for each profile.</li>
<li><b>Show only matching roles</b> filters to only show profiles with roles that match your role in your master account.</li>
<li><b>Sign-in endpoint in current region (Experimental, Supporters only)</b> instead of <i>signin.aws.amazon.com</i> when you browse a non-global page in AWS Management Console. For those working geographically far from Virginia, the switch role may be a little faster.</li>
<li><b>Automatically assume last assumed role (Experimental)</b> automatically assumes last assumed role on the next sign-in if did not back to the base account and signed out.</li>
<li><b>Configuration storage</b> specifies which storage to save to. 'Sync' can automatically share it between browsers with your account but cannot store many profiles.
'Local' is the exact opposite of 'Sync.'</li>
Expand Down
6 changes: 5 additions & 1 deletion src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ if (document.body) {
}
} else if (action === 'switch') {
const metaASE = document.querySelector('meta#awsc-signin-endpoint');
const actionHost = metaASE ? metaASE.getAttribute('content') : 'signin.aws.amazon.com';
let actionHost = metaASE ? metaASE.getAttribute('content') : 'signin.aws.amazon.com';
const { actionSubdomain } = data;
if (actionSubdomain && actionHost === 'signin.aws.amazon.com') {
actionHost = actionSubdomain + '.' + actionHost;
}
const form = document.getElementById('AESR_form');
form.setAttribute('action', `https://${actionHost}/switchrole`);
form.account.value = data.account;
Expand Down
9 changes: 9 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ window.onload = function() {
syncStorageRepo.set({ [key]: this.checked });
}
}
const signinEndpointInHereCheckBox = elById('signinEndpointInHereCheckBox');
if (localStorage.getItem('hasGoldenKey')) {
signinEndpointInHereCheckBox.onchange = function() {
syncStorageRepo.set({ signinEndpointInHere: this.checked });
}
} else {
signinEndpointInHereCheckBox.disabled = true;
}
booleanSettings.push('signinEndpointInHere')

elById('configSenderIdText').onchange = function() {
syncStorageRepo.set({ configSenderId: this.value });
Expand Down
11 changes: 7 additions & 4 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,30 @@ function main() {

function loadFormList(curURL, userInfo, tabId) {
const storageRepo = new SyncStorageRepository(chrome || browser)
storageRepo.get(['hidesAccountId', 'showOnlyMatchingRoles', 'configStorageArea'])
storageRepo.get(['hidesAccountId', 'showOnlyMatchingRoles', 'configStorageArea', 'signinEndpointInHere'])
.then(data => {
const hidesAccountId = data.hidesAccountId || false;
const showOnlyMatchingRoles = data.showOnlyMatchingRoles || false;
const configStorageArea = data.configStorageArea || 'sync';
const signinEndpointInHere = data.signinEndpointInHere || false;

new StorageRepository(chrome || browser, configStorageArea).get(['profiles', 'profiles_1', 'profiles_2', 'profiles_3', 'profiles_4'])
.then(data => {
if (data.profiles) {
const dps = new DataProfilesSplitter();
const profiles = dps.profilesFromDataSet(data);
const profileSet = createProfileSet(profiles, userInfo, { showOnlyMatchingRoles });
renderRoleList(profileSet.destProfiles, tabId, curURL, { hidesAccountId });
renderRoleList(profileSet.destProfiles, tabId, curURL, { hidesAccountId, signinEndpointInHere });
setupRoleFilter();
}
})
});
}

function renderRoleList(profiles, tabId, curURL, options) {
const { url, region } = getCurrentUrlandRegion(curURL)
const { url, region, notGlobal } = getCurrentUrlandRegion(curURL)
const listItemOnSelect = function(data) {
if (options.signinEndpointInHere && notGlobal) data.actionSubdomain = region;
sendSwitchRole(tabId, data);
}
const list = document.getElementById('roleList');
Expand Down Expand Up @@ -178,5 +180,6 @@ function getCurrentUrlandRegion(aURL) {
let region = '';
const md = aURL.search.match(/region=([a-z\-1-9]+)/);
if (md) region = md[1];
return { url, region }
const notGlobal = /^[a-z]{2}\-[a-z]+\-[1-9]\.console\.aws/.test(aURL.host);
return { url, region, notGlobal }
}

0 comments on commit 09e2fa5

Please sign in to comment.