Skip to content

Commit

Permalink
auth fallback from sso
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Jul 19, 2023
1 parent eb42f21 commit 629e195
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 7 additions & 2 deletions src/commands/local/lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));

Expand Down
19 changes: 11 additions & 8 deletions src/commands/local/lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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...`);
Expand All @@ -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`);
Expand Down

0 comments on commit 629e195

Please sign in to comment.