@@ -7,6 +7,8 @@ import CloudGraph, {
77import { loadFilesSync } from '@graphql-tools/load-files'
88import { mergeTypeDefs } from '@graphql-tools/merge'
99import AWS , { Config } from 'aws-sdk'
10+ import { loadSharedConfigFiles } from '@aws-sdk/shared-ini-file-loader'
11+ import { fromIni } from '@aws-sdk/credential-providers'
1012import chalk from 'chalk'
1113import { DocumentNode } from 'graphql'
1214import STS from 'aws-sdk/clients/sts'
@@ -78,7 +80,7 @@ export default class Provider extends CloudGraph.Client {
7880 const result : { [ key : string ] : any } = { ...providerSettings }
7981 let profiles
8082 try {
81- profiles = this . getProfilesFromSharedConfig ( )
83+ profiles = await this . getProfilesFromSharedConfig ( )
8284 } catch ( error : any ) {
8385 this . logger . warn ( 'No AWS profiles found' )
8486 }
@@ -304,19 +306,21 @@ export default class Provider extends CloudGraph.Client {
304306 switch ( true ) {
305307 case role && role !== '' : {
306308 let sts = new AWS . STS ( )
307- await new Promise < void > ( resolve => {
309+ await new Promise < void > ( async resolve => {
308310 if ( profile && profile !== 'default' ) {
309- const creds = this . getSharedIniFileCredentials ( profile )
311+ let creds : AWS . Credentials
312+ const credsFunction = fromIni ( {
313+ profile
314+ } )
310315 if ( creds ) {
311- sts = new AWS . STS ( { credentials : creds } )
316+ sts = new AWS . STS ( { credentials : await credsFunction ( ) } )
312317 }
313318 }
314319 const options = {
315320 RoleSessionName : 'CloudGraph' ,
316321 RoleArn : role ,
317322 ...( externalId && { ExternalId : externalId } ) ,
318323 }
319-
320324 sts . assumeRole ( options , ( err , data ) => {
321325 if ( err ) {
322326 this . logger . error (
@@ -478,18 +482,22 @@ export default class Provider extends CloudGraph.Client {
478482 return credentials
479483 }
480484
481- private getProfilesFromSharedConfig ( ) : string [ ] {
482- let profiles
485+ private async getProfilesFromSharedConfig ( ) : Promise < string [ ] > {
486+ let profiles = [ ]
483487 try {
484- profiles = Object . keys (
485- AWS [ 'util' ] . getProfilesFromSharedConfig ( AWS [ 'util' ] . iniLoader )
486- )
488+ const filesObject = await loadSharedConfigFiles ( )
489+ const files = Object . keys ( filesObject )
490+ for ( const file of files ) {
491+ const fileProfiles = Object . keys ( filesObject [ file ] )
492+ if ( fileProfiles && fileProfiles . length > 0 ) {
493+ profiles . push ( ...fileProfiles )
494+ }
495+ }
487496 } catch ( error : any ) {
488497 this . logger . warn ( 'Unable to read AWS shared credential file' )
489498 this . logger . debug ( error )
490499 }
491-
492- return profiles || [ ]
500+ return profiles
493501 }
494502
495503 private mergeRawData (
@@ -689,7 +697,7 @@ export default class Provider extends CloudGraph.Client {
689697 const { profile, roleArn : role } = account
690698 // verify that profile exists in the shared credential file
691699 if ( profile ) {
692- const profiles = this . getProfilesFromSharedConfig ( )
700+ const profiles = await this . getProfilesFromSharedConfig ( )
693701 if ( ! profiles . includes ( profile ) ) {
694702 this . logger . warn (
695703 `Profile: ${ profile } not found in shared credentials file. Skipping...`
0 commit comments