@@ -12,7 +12,6 @@ import { VueWebview, VueWebviewPanel } from '../../../webviews/main'
1212import { ExtContext } from '../../../shared/extensions'
1313import { telemetry } from '../../../shared/telemetry/telemetry'
1414import { AccessAnalyzer , SharedIniFileCredentials } from 'aws-sdk'
15- import { execFileSync } from 'child_process'
1615import { ToolkitError } from '../../../shared/errors'
1716import { makeTemporaryToolkitFolder , tryRemoveFolder } from '../../../shared/filesystemUtilities'
1817import { globals } from '../../../shared'
@@ -28,6 +27,7 @@ import {
2827} from './constants'
2928import { DefaultS3Client , parseS3Uri } from '../../../shared/clients/s3Client'
3029import { ExpiredTokenException } from '@aws-sdk/client-sso-oidc'
30+ import { ChildProcess } from '../../../shared/utilities/processUtils'
3131
3232const defaultTerraformConfigPath = 'resources/policychecks-tf-default.yaml'
3333// Diagnostics for Custom checks are shared
@@ -277,7 +277,7 @@ export class IamPolicyChecksWebview extends VueWebview {
277277 '--config' ,
278278 `${ globals . context . asAbsolutePath ( defaultTerraformConfigPath ) } ` ,
279279 ]
280- this . executeValidatePolicyCommand ( {
280+ await this . executeValidatePolicyCommand ( {
281281 command,
282282 args,
283283 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -300,7 +300,7 @@ export class IamPolicyChecksWebview extends VueWebview {
300300 if ( cfnParameterPath !== '' ) {
301301 args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
302302 }
303- this . executeValidatePolicyCommand ( {
303+ await this . executeValidatePolicyCommand ( {
304304 command,
305305 args,
306306 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -357,7 +357,7 @@ export class IamPolicyChecksWebview extends VueWebview {
357357 '--reference-policy-type' ,
358358 `${ policyType } ` ,
359359 ]
360- this . executeCustomPolicyChecksCommand ( {
360+ await this . executeCustomPolicyChecksCommand ( {
361361 command,
362362 args,
363363 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -391,7 +391,7 @@ export class IamPolicyChecksWebview extends VueWebview {
391391 if ( cfnParameterPath !== '' ) {
392392 args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
393393 }
394- this . executeCustomPolicyChecksCommand ( {
394+ await this . executeCustomPolicyChecksCommand ( {
395395 command,
396396 args,
397397 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -454,7 +454,7 @@ export class IamPolicyChecksWebview extends VueWebview {
454454 if ( resources !== '' ) {
455455 args . push ( '--resources' , `${ resources } ` )
456456 }
457- this . executeCustomPolicyChecksCommand ( {
457+ await this . executeCustomPolicyChecksCommand ( {
458458 command,
459459 args,
460460 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -489,7 +489,7 @@ export class IamPolicyChecksWebview extends VueWebview {
489489 if ( cfnParameterPath !== '' ) {
490490 args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
491491 }
492- this . executeCustomPolicyChecksCommand ( {
492+ await this . executeCustomPolicyChecksCommand ( {
493493 command,
494494 args,
495495 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -525,7 +525,7 @@ export class IamPolicyChecksWebview extends VueWebview {
525525 '--config' ,
526526 `${ globals . context . asAbsolutePath ( defaultTerraformConfigPath ) } ` ,
527527 ]
528- this . executeCustomPolicyChecksCommand ( {
528+ await this . executeCustomPolicyChecksCommand ( {
529529 command,
530530 args,
531531 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -554,7 +554,7 @@ export class IamPolicyChecksWebview extends VueWebview {
554554 if ( cfnParameterPath !== '' ) {
555555 args . push ( '--template-configuration-file' , `${ cfnParameterPath } ` )
556556 }
557- this . executeCustomPolicyChecksCommand ( {
557+ await this . executeCustomPolicyChecksCommand ( {
558558 command,
559559 args,
560560 cfnParameterPathExists : ! ! cfnParameterPath ,
@@ -573,16 +573,16 @@ export class IamPolicyChecksWebview extends VueWebview {
573573 }
574574 }
575575
576- public executeValidatePolicyCommand ( opts : PolicyCommandOpts & { policyType ?: PolicyChecksPolicyType } ) {
577- telemetry . accessanalyzer_iamPolicyChecksValidatePolicy . run ( ( span ) => {
576+ public async executeValidatePolicyCommand ( opts : PolicyCommandOpts & { policyType ?: PolicyChecksPolicyType } ) {
577+ await telemetry . accessanalyzer_iamPolicyChecksValidatePolicy . run ( async ( span ) => {
578578 try {
579579 span . record ( {
580580 cfnParameterFileUsed : opts . cfnParameterPathExists ,
581581 documentType : opts . documentType ,
582582 inputPolicyType : opts . policyType ?? 'None' ,
583583 } )
584- const resp = execFileSync ( opts . command , opts . args )
585- const findingsCount = this . handleValidatePolicyCliResponse ( resp . toString ( ) )
584+ const result = await ChildProcess . run ( opts . command , opts . args , { collect : true } )
585+ const findingsCount = this . handleValidatePolicyCliResponse ( result . stdout )
586586 span . record ( {
587587 findingsCount : findingsCount ,
588588 } )
@@ -633,10 +633,10 @@ export class IamPolicyChecksWebview extends VueWebview {
633633 return findingsCount
634634 }
635635
636- public executeCustomPolicyChecksCommand (
636+ public async executeCustomPolicyChecksCommand (
637637 opts : PolicyCommandOpts & { checkType : PolicyChecksCheckType ; referencePolicyType ?: PolicyChecksPolicyType }
638638 ) {
639- telemetry . accessanalyzer_iamPolicyChecksCustomChecks . run ( ( span ) => {
639+ await telemetry . accessanalyzer_iamPolicyChecksCustomChecks . run ( async ( span ) => {
640640 try {
641641 span . record ( {
642642 cfnParameterFileUsed : opts . cfnParameterPathExists ,
@@ -645,8 +645,8 @@ export class IamPolicyChecksWebview extends VueWebview {
645645 inputPolicyType : 'None' , // Note: This will change once JSON policy language is enabled for Custom policy checks
646646 referencePolicyType : opts . referencePolicyType ?? 'None' ,
647647 } )
648- const resp = execFileSync ( opts . command , opts . args )
649- const findingsCount = this . handleCustomPolicyChecksCliResponse ( resp . toString ( ) )
648+ const resp = await ChildProcess . run ( opts . command , opts . args )
649+ const findingsCount = this . handleCustomPolicyChecksCliResponse ( resp . stdout )
650650 span . record ( {
651651 findingsCount : findingsCount ,
652652 } )
@@ -790,7 +790,7 @@ export async function renderIamPolicyChecks(context: ExtContext): Promise<VueWeb
790790 checkAccessNotGrantedResourcesTextArea,
791791 customChecksFileErrorMessage,
792792 cfnParameterPath : cfnParameterPath ? cfnParameterPath : '' ,
793- pythonToolsInstalled : arePythonToolsInstalled ( ) ,
793+ pythonToolsInstalled : await arePythonToolsInstalled ( ) ,
794794 } ,
795795 client ,
796796 context . regionProvider . defaultRegionId
@@ -828,20 +828,20 @@ export async function _readCustomChecksFile(input: string): Promise<string> {
828828}
829829
830830// Check if Cfn and Tf tools are installed
831- export function arePythonToolsInstalled ( ) : boolean {
831+ export async function arePythonToolsInstalled ( ) : Promise < boolean > {
832832 const logger : Logger = getLogger ( )
833833 let cfnToolInstalled = true
834834 let tfToolInstalled = true
835835 try {
836- execFileSync ( 'tf-policy-validator' )
836+ await ChildProcess . run ( 'tf-policy-validator' )
837837 } catch ( err : any ) {
838838 if ( isProcessNotFoundErr ( err . message ) ) {
839839 tfToolInstalled = false
840840 logger . error ( 'Terraform Policy Validator is not found' )
841841 }
842842 }
843843 try {
844- execFileSync ( 'cfn-policy-validator' )
844+ await ChildProcess . run ( 'cfn-policy-validator' )
845845 } catch ( err : any ) {
846846 if ( isProcessNotFoundErr ( err . message ) ) {
847847 cfnToolInstalled = false
0 commit comments