Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ function doSwitch(data, cb) {

const form = document.getElementById('AESR_form');
form.setAttribute('action', formActionUrl);

// Handle switch-back to base account
if (data.isswitchback === 'true') {
form.action.value = 'switchToBasis';
form.redirect_uri.value = data.redirecturi;
cb({ prism: session.prismModeEnabled, switchBack: true });
form.submit();
return false;
}

form.account.value = data.account;
form.color.value = data.color;
form.roleName.value = data.rolename;
Expand Down
3 changes: 3 additions & 0 deletions src/js/lib/create_role_list_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function createRoleListItem(document, item, url, region, { hidesAccountId
anchor.dataset.color = item.color || 'aaaaaa';
anchor.dataset.redirecturi = createRedirectUri(url, region, item.region);
anchor.dataset.search = item.name.toLowerCase() + ' ' + item.aws_account_id;
if (item.isSwitchBack) {
anchor.dataset.isswitchback = 'true';
}

anchor.appendChild(headSquare);
anchor.appendChild(document.createTextNode(item.name));
Expand Down
5 changes: 5 additions & 0 deletions src/js/lib/current_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export class CurrentContext {
return extractLoginRole(loginDisplayNameUser.split("/", 2)[0]);
})();
this.filterByTargetRole = showOnlyMatchingRoles ? (roleDisplayNameUser || this.loginRole) : null;

// Track if we're in a delegated role and what the source account is
this.isInDelegatedRole = !!(roleDisplayNameAccount || (prism && roleDisplayNameUser));
this.sourceAccount = this.isInDelegatedRole ? brushAccountId(loginDisplayNameAccount) : null;
this.sourceRole = this.isInDelegatedRole ? extractLoginRole(loginDisplayNameUser.split("/", 2)[0]) : null;
}
}

Expand Down
34 changes: 31 additions & 3 deletions src/js/lib/target_profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function findTargetProfiles(ctx) {
}

async function retrieveTargetProfilesFromDB(ctx) {
const { baseAccount, loginRole, filterByTargetRole } = ctx;
const { baseAccount, loginRole, filterByTargetRole, isInDelegatedRole, sourceAccount, sourceRole } = ctx;
const dbManager = new DBManager('aesr');
await dbManager.open();

Expand All @@ -32,6 +32,20 @@ async function retrieveTargetProfilesFromDB(ctx) {
}
results.push(...targets)
}

// If we're in a delegated role, add the base account as a switchable target
if (isInDelegatedRole && sourceAccount) {
const baseProfile = complexSrcItems.find(it => matchSourceProfile(it, sourceAccount, sourceRole));
if (baseProfile) {
const switchBackProfile = {
...baseProfile,
isSwitchBack: true,
profile: `← ${baseProfile.name}`,
};
// Add it at the beginning for easy access
results.unshift(switchBackProfile);
}
}
}, 'readonly');

await dbManager.close();
Expand All @@ -58,8 +72,8 @@ function convertComplexTarget(item, baseProfile) {
}

async function retrieveTargetProfilesFromLztext(ctx) {
const { baseAccount, loginRole, filterByTargetRole } = ctx;
const { baseAccount, loginRole, filterByTargetRole, isInDelegatedRole, sourceAccount, sourceRole } = ctx;

const localRepo = StorageProvider.getLocalRepository();
const cfgText = await loadConfigIni(localRepo);
if (!cfgText) return [];
Expand All @@ -77,6 +91,20 @@ async function retrieveTargetProfilesFromLztext(ctx) {
results.push(...targets)
}

// If we're in a delegated role, add the base account as a switchable target
if (isInDelegatedRole && sourceAccount) {
const baseProfile = profileSet.complexes.find(it => matchSourceProfile(it, sourceAccount, sourceRole));
if (baseProfile) {
const switchBackProfile = {
...baseProfile,
isSwitchBack: true,
profile: `← ${baseProfile.name}`,
};
// Add it at the beginning for easy access
results.unshift(switchBackProfile);
}
}

return results;
}

Expand Down