Skip to content

Commit

Permalink
move credentials into options
Browse files Browse the repository at this point in the history
  • Loading branch information
GGonryun committed Feb 29, 2024
1 parent 175d41f commit 13c78e5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/plugins/aws/ssm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,22 @@ const interceptSessionOutput = (
*
* Requires `aws ssm` to be installed on the client machine.
*/
const spawnSsmNode = async (
credentials: AwsCredentials,
options: {
command: string[];
attemptsRemaining?: number;
subcommand?: string[];
}
): Promise<number | null> =>
const spawnSsmNode = async (options: {
credentials: AwsCredentials;
command: string[];
attemptsRemaining?: number;
subcommand?: string[];
}): Promise<number | null> =>
new Promise((resolve, reject) => {
const parent = spawn("/usr/bin/env", options.command, {
env: {
...process.env,
...credentials,
...options.credentials,
},
stdio: ["inherit", "pipe", "pipe"],
});

const subprocesses = subcommandLauncher(credentials);
const subprocesses = subcommandLauncher(options.credentials);

const stream = interceptSessionOutput(parent, {
onSessionStart() {
Expand Down Expand Up @@ -312,7 +310,7 @@ const spawnSsmNode = async (
return;
}
// console.debug("Permissions not yet propagated in AWS; retrying");
spawnSsmNode(credentials, {
spawnSsmNode({
...options,
attemptsRemaining: attemptsRemaining - 1,
})
Expand Down Expand Up @@ -361,7 +359,7 @@ export const ssm = async (
if (!match) throw "Did not receive a properly formatted instance identifier";
const [, region, account, instance] = match;

const credential = await assumeRoleWithOktaSaml(authn, {
const credentials = await assumeRoleWithOktaSaml(authn, {
account,
role: request.generatedRoles[0]!.role,
});
Expand All @@ -373,7 +371,8 @@ export const ssm = async (
forwardPortAddress: args.L,
command: commandParameter(args),
};
await spawnSsmNode(credential, {
await spawnSsmNode({
credentials,
...createSsmCommands(ssmArgs),
});
};

0 comments on commit 13c78e5

Please sign in to comment.