Skip to content

Commit b165859

Browse files
Merge master into feature/q-dev-execution
2 parents 35cec21 + 3f16d7d commit b165859

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

packages/core/src/awsService/accessanalyzer/vue/iamPolicyChecks.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ export class IamPolicyChecksWebview extends VueWebview {
179179
documentType,
180180
inputPolicyType: policyType ? policyType : 'None',
181181
})
182-
this.client.config.credentials = new SharedIniFileCredentials() // We need to detect changes in the user's credentials
182+
this.client.config.credentials = new SharedIniFileCredentials({
183+
profile: `${getProfileName()}`,
184+
}) // We need to detect changes in the user's credentials
183185
this.client.validatePolicy(
184186
{
185187
policyDocument: IamPolicyChecksWebview.editedDocument,
@@ -277,6 +279,8 @@ export class IamPolicyChecksWebview extends VueWebview {
277279
`${this.region}`,
278280
'--config',
279281
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
282+
'--profile',
283+
`${getProfileName()}`,
280284
]
281285
await this.executeValidatePolicyCommand({
282286
command,
@@ -297,7 +301,15 @@ export class IamPolicyChecksWebview extends VueWebview {
297301
case 'CloudFormation': {
298302
if (isCloudFormationTemplate(document)) {
299303
const command = 'cfn-policy-validator'
300-
const args = ['validate', '--template-path', `${document}`, '--region', `${this.region}`]
304+
const args = [
305+
'validate',
306+
'--template-path',
307+
`${document}`,
308+
'--region',
309+
`${this.region}`,
310+
'--profile',
311+
`${getProfileName()}`,
312+
]
301313
if (cfnParameterPath !== '') {
302314
args.push('--template-configuration-file', `${cfnParameterPath}`)
303315
}
@@ -357,6 +369,8 @@ export class IamPolicyChecksWebview extends VueWebview {
357369
`${tempFilePath}`,
358370
'--reference-policy-type',
359371
`${policyType}`,
372+
'--profile',
373+
`${getProfileName()}`,
360374
]
361375
await this.executeCustomPolicyChecksCommand({
362376
command,
@@ -388,6 +402,8 @@ export class IamPolicyChecksWebview extends VueWebview {
388402
`${tempFilePath}`,
389403
'--reference-policy-type',
390404
`${policyType}`,
405+
'--profile',
406+
`${getProfileName()}`,
391407
]
392408
if (cfnParameterPath !== '') {
393409
args.push('--template-configuration-file', `${cfnParameterPath}`)
@@ -448,6 +464,8 @@ export class IamPolicyChecksWebview extends VueWebview {
448464
`${this.region}`,
449465
'--config',
450466
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
467+
'--profile',
468+
`${getProfileName()}`,
451469
]
452470
if (actions !== '') {
453471
args.push('--actions', `${actions}`)
@@ -480,6 +498,8 @@ export class IamPolicyChecksWebview extends VueWebview {
480498
`${document}`,
481499
'--region',
482500
`${this.region}`,
501+
'--profile',
502+
`${getProfileName()}`,
483503
]
484504
if (actions !== '') {
485505
args.push('--actions', `${actions}`)
@@ -525,6 +545,8 @@ export class IamPolicyChecksWebview extends VueWebview {
525545
`${this.region}`,
526546
'--config',
527547
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
548+
'--profile',
549+
`${getProfileName()}`,
528550
]
529551
await this.executeCustomPolicyChecksCommand({
530552
command,
@@ -551,6 +573,8 @@ export class IamPolicyChecksWebview extends VueWebview {
551573
`${document}`,
552574
'--region',
553575
`${this.region}`,
576+
'--profile',
577+
`${getProfileName()}`,
554578
]
555579
if (cfnParameterPath !== '') {
556580
args.push('--template-configuration-file', `${cfnParameterPath}`)
@@ -925,6 +949,11 @@ export function isJsonPolicyLanguage(document: string) {
925949
return policyLanguageFileTypes.some((t) => document.endsWith(t))
926950
}
927951

952+
export function getProfileName(): string | undefined {
953+
// We neeed to split the name on 'profile:' to extract the correct profile name
954+
return globals.awsContext.getCredentialProfileName()?.split('profile:')[1]
955+
}
956+
928957
export class PolicyChecksError extends ToolkitError {
929958
constructor(message: string, code: PolicyChecksErrorCode) {
930959
super(message, { code })

packages/core/src/test/awsService/accessanalyzer/iamPolicyChecks.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ describe('validatePolicy', function () {
155155
'us-east-1',
156156
'--config',
157157
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
158+
'--profile',
159+
'undefined',
158160
],
159161
cfnParameterPathExists: false,
160162
documentType,
@@ -180,6 +182,8 @@ describe('validatePolicy', function () {
180182
IamPolicyChecksWebview.editedDocumentFileName,
181183
'--region',
182184
'us-east-1',
185+
'--profile',
186+
'undefined',
183187
'--template-configuration-file',
184188
cfnParameterPath,
185189
],
@@ -449,6 +453,8 @@ describe('customChecks', function () {
449453
'us-east-1',
450454
'--config',
451455
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
456+
'--profile',
457+
'undefined',
452458
'--actions',
453459
'action1action2',
454460
'--resources',
@@ -486,6 +492,8 @@ describe('customChecks', function () {
486492
document,
487493
'--region',
488494
'us-east-1',
495+
'--profile',
496+
'undefined',
489497
'--actions',
490498
'action1action2',
491499
'--resources',
@@ -548,6 +556,8 @@ describe('customChecks', function () {
548556
'us-east-1',
549557
'--config',
550558
`${globals.context.asAbsolutePath(defaultTerraformConfigPath)}`,
559+
'--profile',
560+
'undefined',
551561
],
552562
cfnParameterPathExists: !!cfnParameterPath,
553563
documentType,
@@ -579,6 +589,8 @@ describe('customChecks', function () {
579589
document,
580590
'--region',
581591
'us-east-1',
592+
'--profile',
593+
'undefined',
582594
'--template-configuration-file',
583595
cfnParameterPath,
584596
],
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Policy Checks selected profile is always default"
4+
}

0 commit comments

Comments
 (0)