@@ -179,7 +179,9 @@ export class IamPolicyChecksWebview extends VueWebview {
179
179
documentType,
180
180
inputPolicyType : policyType ? policyType : 'None' ,
181
181
} )
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
183
185
this . client . validatePolicy (
184
186
{
185
187
policyDocument : IamPolicyChecksWebview . editedDocument ,
@@ -277,6 +279,8 @@ export class IamPolicyChecksWebview extends VueWebview {
277
279
`${ this . region } ` ,
278
280
'--config' ,
279
281
`${ globals . context . asAbsolutePath ( defaultTerraformConfigPath ) } ` ,
282
+ '--profile' ,
283
+ `${ getProfileName ( ) } ` ,
280
284
]
281
285
await this . executeValidatePolicyCommand ( {
282
286
command,
@@ -297,7 +301,15 @@ export class IamPolicyChecksWebview extends VueWebview {
297
301
case 'CloudFormation' : {
298
302
if ( isCloudFormationTemplate ( document ) ) {
299
303
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
+ ]
301
313
if ( cfnParameterPath !== '' ) {
302
314
args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
303
315
}
@@ -357,6 +369,8 @@ export class IamPolicyChecksWebview extends VueWebview {
357
369
`${ tempFilePath } ` ,
358
370
'--reference-policy-type' ,
359
371
`${ policyType } ` ,
372
+ '--profile' ,
373
+ `${ getProfileName ( ) } ` ,
360
374
]
361
375
await this . executeCustomPolicyChecksCommand ( {
362
376
command,
@@ -388,6 +402,8 @@ export class IamPolicyChecksWebview extends VueWebview {
388
402
`${ tempFilePath } ` ,
389
403
'--reference-policy-type' ,
390
404
`${ policyType } ` ,
405
+ '--profile' ,
406
+ `${ getProfileName ( ) } ` ,
391
407
]
392
408
if ( cfnParameterPath !== '' ) {
393
409
args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
@@ -448,6 +464,8 @@ export class IamPolicyChecksWebview extends VueWebview {
448
464
`${ this . region } ` ,
449
465
'--config' ,
450
466
`${ globals . context . asAbsolutePath ( defaultTerraformConfigPath ) } ` ,
467
+ '--profile' ,
468
+ `${ getProfileName ( ) } ` ,
451
469
]
452
470
if ( actions !== '' ) {
453
471
args . push ( '--actions' , `${ actions } ` )
@@ -480,6 +498,8 @@ export class IamPolicyChecksWebview extends VueWebview {
480
498
`${ document } ` ,
481
499
'--region' ,
482
500
`${ this . region } ` ,
501
+ '--profile' ,
502
+ `${ getProfileName ( ) } ` ,
483
503
]
484
504
if ( actions !== '' ) {
485
505
args . push ( '--actions' , `${ actions } ` )
@@ -525,6 +545,8 @@ export class IamPolicyChecksWebview extends VueWebview {
525
545
`${ this . region } ` ,
526
546
'--config' ,
527
547
`${ globals . context . asAbsolutePath ( defaultTerraformConfigPath ) } ` ,
548
+ '--profile' ,
549
+ `${ getProfileName ( ) } ` ,
528
550
]
529
551
await this . executeCustomPolicyChecksCommand ( {
530
552
command,
@@ -551,6 +573,8 @@ export class IamPolicyChecksWebview extends VueWebview {
551
573
`${ document } ` ,
552
574
'--region' ,
553
575
`${ this . region } ` ,
576
+ '--profile' ,
577
+ `${ getProfileName ( ) } ` ,
554
578
]
555
579
if ( cfnParameterPath !== '' ) {
556
580
args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
@@ -925,6 +949,11 @@ export function isJsonPolicyLanguage(document: string) {
925
949
return policyLanguageFileTypes . some ( ( t ) => document . endsWith ( t ) )
926
950
}
927
951
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
+
928
957
export class PolicyChecksError extends ToolkitError {
929
958
constructor ( message : string , code : PolicyChecksErrorCode ) {
930
959
super ( message , { code } )
0 commit comments