From 629e195498ad20b939bc289814b6e935c80d8859 Mon Sep 17 00:00:00 2001 From: ljacobsson Date: Wed, 19 Jul 2023 22:43:29 +0200 Subject: [PATCH] auth fallback from sso --- package.json | 2 +- src/commands/local/lib/cleanup.js | 9 +++++++-- src/commands/local/lib/connect.js | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 24ff005..9e64e62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "samp-cli", - "version": "1.0.12", + "version": "1.0.13", "description": "CLI tool for extended productivity with AWS Serverless Application Model (SAM)", "main": "index.js", "scripts": { diff --git a/src/commands/local/lib/cleanup.js b/src/commands/local/lib/cleanup.js index bde7a9a..5aa1fdb 100644 --- a/src/commands/local/lib/cleanup.js +++ b/src/commands/local/lib/cleanup.js @@ -27,9 +27,14 @@ if (!conf.envConfig) process.exit(0); const stackName = conf.envConfig.stack_name; const region = conf.envConfig.region; const profile = conf.envConfig.profile; +let credentials; +try { + credentials = await fromSSO({ profile, region })(); +} catch (e) { +} -const cfnClient = new CloudFormationClient({ region, credentials: fromSSO({ profile }) }); -const lambdaClient = new LambdaClient({ region, credentials: fromSSO({ profile }) }); +const cfnClient = new CloudFormationClient({ region, credentials }); +const lambdaClient = new LambdaClient({ region, credentials }); const templateResponse = await cfnClient.send(new GetTemplateCommand({ StackName: stackName, TemplateStage: "Processed" })); const stack = await cfnClient.send(new ListStackResourcesCommand({ StackName: stackName })); diff --git a/src/commands/local/lib/connect.js b/src/commands/local/lib/connect.js index e4db71e..00c9d96 100644 --- a/src/commands/local/lib/connect.js +++ b/src/commands/local/lib/connect.js @@ -32,9 +32,16 @@ if (fs.existsSync(`samconfig.toml`)) { } } console.log(`Using profile: ${envConfig.profile || 'default'}`); -const stsClient = new STSClient({ region: envConfig.region, credentials: fromSSO({ profile: envConfig.profile || 'default' }) }); + +let credentials; +try { + credentials = await fromSSO({ profile: envConfig.profile || 'default' })(); +} catch (e) { +} + +const stsClient = new STSClient({ region: envConfig.region, credentials }); const accountId = (await stsClient.send(new GetCallerIdentityCommand({}))).Account; -const iotClient = new IoTClient({ region: envConfig.region, credentials: fromSSO({ profile: envConfig.profile || 'default' }) }); +const iotClient = new IoTClient({ region: envConfig.region, credentials }); const timer = new Date().getTime(); let certData, endpoint, stack, functions, template; const policyName = "lambda-debug-policy"; @@ -128,9 +135,7 @@ if (!fs.existsSync(".lambda-debug")) { certData.ca = fs.readFileSync(path.join(__dirname, 'AmazonRootCA1.pem')).toString(); // Download this from Amazon's website const cfnClient = new CloudFormationClient({ region: envConfig.region, - credentials: fromSSO({ - profile: envConfig.profile || 'default' - }) + credentials: credentials }); console.log(`Loading necessary resources...`); @@ -154,9 +159,7 @@ if (!fs.existsSync(".lambda-debug")) { // replace function code with stub-local.js const lambdaClient = new LambdaClient({ region: envConfig.region, - credentials: fromSSO({ - profile: envConfig.profile || 'default', - }) + credentials }); if (!fs.existsSync(zipFilePath)) { console.log(`Creating Lambda artifact zip`);