@@ -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+
928957export class PolicyChecksError extends ToolkitError {
929958 constructor ( message : string , code : PolicyChecksErrorCode ) {
930959 super ( message , { code } )
0 commit comments