Skip to content

Commit

Permalink
Display confirmation code (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Sep 18, 2023
1 parent f8bac06 commit c105f34
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 35 deletions.
17 changes: 15 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import util from 'util';
import { exec } from 'child_process';
import { exec, spawn } from 'child_process';

import yargs from 'yargs';

Expand Down Expand Up @@ -85,12 +85,25 @@ interface SSOLoginContext {

const runSsoLogin = async (context: SSOLoginContext): Promise<void> => {
log.info('No valid SSO cache file found, running login...');
await execPromise('aws sso login', {
const child = spawn('aws', ['sso', 'login'], {
env: {
...process.env,
AWS_PROFILE: context.awsProfile || 'default',
},
stdio: 'inherit',
});

await new Promise<void>((res, rej) => {
child.on('close', (code: number, signal: string) => {
/* istanbul ignore else */
if (code === 0) {
res();
} else {
rej(`Command failed with code ${code}, signal: ${signal}`);
}
});
});

context.haveRunSsoLogin = true;

log.info('Login completed, trying again to retrieve credentials from SSO cache');
Expand Down
Loading

0 comments on commit c105f34

Please sign in to comment.