Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --list-available-roles to print the list of roles available to assume and exit #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const credentialsManager = new CredentialsManager(logger, argv.awsRegion, argv['
await trash(paths.data);
}

if (!argv.headful) {
if (!argv.headful && !argv.listAvailableRoles) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without adding this, the output looks something like this:

❯ node index.js --idp-id=redacted --sp-id=redacted --aws-region us-west-2 --list-available-roles
⠋ Logging inarn:aws:iam::1234567890:role/StagingAccount-AdministratorAccess
arn:aws:iam::1234567890:role/StagingAccount-FullReadOnlyAccess
arn:aws:iam::1234567890:role/StagingAccount-ReadOnlyAccess
arn:aws:iam::1234567891:role/ProductionAccount-AdministratorAccess
arn:aws:iam::1234567891:role/ProductionAccount-FullReadOnlyAccess
arn:aws:iam::1234567891:role/ProductionAccount-ReadOnlyAccess

I have to filter out stderr to get the output to look good

❯ node index.js --idp-id=redacted --sp-id=redacted --aws-region us-west-2 --list-available-roles 2>/dev/null
arn:aws:iam::1234567890:role/StagingAccount-AdministratorAccess
arn:aws:iam::1234567890:role/StagingAccount-FullReadOnlyAccess
arn:aws:iam::1234567890:role/StagingAccount-ReadOnlyAccess
arn:aws:iam::1234567891:role/ProductionAccount-AdministratorAccess
arn:aws:iam::1234567891:role/ProductionAccount-FullReadOnlyAccess
arn:aws:iam::1234567891:role/ProductionAccount-ReadOnlyAccess

Looking for recommendation on what's the best way to address this.

logger.start('Logging in');
}

Expand Down Expand Up @@ -146,6 +146,20 @@ const credentialsManager = new CredentialsManager(logger, argv.awsRegion, argv['
try {
let { availableRoles, roleToAssume, samlAssertion } = await credentialsManager.prepareRoleWithSAML(route.request().postDataJSON(), argv.awsRoleArn);

if (argv.listAvailableRoles) {
if (argv.output === 'json') {
process.stdout.write(JSON.stringify(availableRoles));
} else {
for (let role of availableRoles) {
process.stdout.write(role.roleArn+"\n");
}
}

logger.stop();
await context.close();
return;
}

if (!roleToAssume && availableRoles.length > 1) {
logger.stop();

Expand Down
5 changes: 5 additions & 0 deletions parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export function generateCliParameters(paths) {
required: true,
awsConfigKey: 'gsts.idp_id'
},
'list-available-roles': {
description: 'List available roles and exit',
type: 'boolean',
default: false,
},
'no-credentials-cache': {
description: 'Disable default behaviour of storing credentials in --cache-dir',
type: 'boolean'
Expand Down