Skip to content

Commit

Permalink
change switch form to fix switching region (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilfin authored May 22, 2021
1 parent e963fa1 commit 4078842
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function appendAESR() {
const form = document.createElement('form');
form.id = 'AESR_form';
form.method = 'POST';
form.target = '_top';
form.innerHTML = '<input type="hidden" name="mfaNeeded" value="0"><input type="hidden" name="action" value="switchFromBasis"><input type="hidden" name="src" value="nav"><input type="hidden" name="csrf"><input type="hidden" name="roleName"><input type="hidden" name="account"><input type="hidden" name="color"><input type="hidden" name="redirect_uri"><input type="hidden" name="displayName">';
document.body.appendChild(form)

Expand Down
13 changes: 3 additions & 10 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function loadProfiles(profileSet, tabId, list, currentUrl, isGlobal, hidesAccoun
anchor.dataset.rolename = item.role_name;
anchor.dataset.account = item.aws_account_id;
anchor.dataset.color = color;
anchor.dataset.redirecturi = createRedirectURI(currentUrl, item.region, isGlobal);
anchor.dataset.redirecturi = createRedirectURI(currentUrl, item.region);
anchor.dataset.search = item.profile.toLowerCase() + ' ' + item.aws_account_id;

anchor.appendChild(headSquare);
Expand Down Expand Up @@ -211,22 +211,15 @@ function loadProfiles(profileSet, tabId, list, currentUrl, isGlobal, hidesAccoun
document.getElementById('roleFilter').focus()
}

function createRedirectURI(currentURL, destRegion, isGlobal) {
function createRedirectURI(currentURL, destRegion) {
if (!destRegion) return encodeURIComponent(currentURL.href);

let redirectUri = currentURL.href;
const md = currentURL.search.match(/region=([a-z\-1-9]+)/);
if (md) {
const currentRegion = md[1];
if (currentRegion !== destRegion) {
redirectUri = redirectUri.replace(new RegExp(currentRegion, 'g'), destRegion);
if (!isGlobal) {
if (currentRegion === 'us-east-1') {
redirectUri = redirectUri.replace('://', `://${destRegion}.`);
} else if (destRegion === 'us-east-1') {
redirectUri = redirectUri.replace(/:\/\/[^.]+\./, '://');
}
}
redirectUri = redirectUri.replace('region=' + currentRegion, 'region=' + destRegion);
}
}
return encodeURIComponent(redirectUri);
Expand Down

0 comments on commit 4078842

Please sign in to comment.