1+ "use strict" ;
2+ exports . id = 360 ;
3+ exports . ids = [ 360 ] ;
4+ exports . modules = {
5+
6+ /***/ 5360 :
7+ /***/ ( ( __unused_webpack_module , exports , __webpack_require__ ) => {
8+
9+
10+
11+ var sharedIniFileLoader = __webpack_require__ ( 4964 ) ;
12+ var propertyProvider = __webpack_require__ ( 1238 ) ;
13+ var child_process = __webpack_require__ ( 5317 ) ;
14+ var util = __webpack_require__ ( 9023 ) ;
15+ var client = __webpack_require__ ( 5152 ) ;
16+
17+ const getValidatedProcessCredentials = ( profileName , data , profiles ) => {
18+ if ( data . Version !== 1 ) {
19+ throw Error ( `Profile ${ profileName } credential_process did not return Version 1.` ) ;
20+ }
21+ if ( data . AccessKeyId === undefined || data . SecretAccessKey === undefined ) {
22+ throw Error ( `Profile ${ profileName } credential_process returned invalid credentials.` ) ;
23+ }
24+ if ( data . Expiration ) {
25+ const currentTime = new Date ( ) ;
26+ const expireTime = new Date ( data . Expiration ) ;
27+ if ( expireTime < currentTime ) {
28+ throw Error ( `Profile ${ profileName } credential_process returned expired credentials.` ) ;
29+ }
30+ }
31+ let accountId = data . AccountId ;
32+ if ( ! accountId && profiles ?. [ profileName ] ?. aws_account_id ) {
33+ accountId = profiles [ profileName ] . aws_account_id ;
34+ }
35+ const credentials = {
36+ accessKeyId : data . AccessKeyId ,
37+ secretAccessKey : data . SecretAccessKey ,
38+ ...( data . SessionToken && { sessionToken : data . SessionToken } ) ,
39+ ...( data . Expiration && { expiration : new Date ( data . Expiration ) } ) ,
40+ ...( data . CredentialScope && { credentialScope : data . CredentialScope } ) ,
41+ ...( accountId && { accountId } ) ,
42+ } ;
43+ client . setCredentialFeature ( credentials , "CREDENTIALS_PROCESS" , "w" ) ;
44+ return credentials ;
45+ } ;
46+
47+ const resolveProcessCredentials = async ( profileName , profiles , logger ) => {
48+ const profile = profiles [ profileName ] ;
49+ if ( profiles [ profileName ] ) {
50+ const credentialProcess = profile [ "credential_process" ] ;
51+ if ( credentialProcess !== undefined ) {
52+ const execPromise = util . promisify ( sharedIniFileLoader . externalDataInterceptor ?. getTokenRecord ?. ( ) . exec ?? child_process . exec ) ;
53+ try {
54+ const { stdout } = await execPromise ( credentialProcess ) ;
55+ let data ;
56+ try {
57+ data = JSON . parse ( stdout . trim ( ) ) ;
58+ }
59+ catch {
60+ throw Error ( `Profile ${ profileName } credential_process returned invalid JSON.` ) ;
61+ }
62+ return getValidatedProcessCredentials ( profileName , data , profiles ) ;
63+ }
64+ catch ( error ) {
65+ throw new propertyProvider . CredentialsProviderError ( error . message , { logger } ) ;
66+ }
67+ }
68+ else {
69+ throw new propertyProvider . CredentialsProviderError ( `Profile ${ profileName } did not contain credential_process.` , { logger } ) ;
70+ }
71+ }
72+ else {
73+ throw new propertyProvider . CredentialsProviderError ( `Profile ${ profileName } could not be found in shared credentials file.` , {
74+ logger,
75+ } ) ;
76+ }
77+ } ;
78+
79+ const fromProcess = ( init = { } ) => async ( { callerClientConfig } = { } ) => {
80+ init . logger ?. debug ( "@aws-sdk/credential-provider-process - fromProcess" ) ;
81+ const profiles = await sharedIniFileLoader . parseKnownFiles ( init ) ;
82+ return resolveProcessCredentials ( sharedIniFileLoader . getProfileName ( {
83+ profile : init . profile ?? callerClientConfig ?. profile ,
84+ } ) , profiles , init . logger ) ;
85+ } ;
86+
87+ exports . fromProcess = fromProcess ;
88+
89+
90+ /***/ } )
91+
92+ } ;
93+ ;
0 commit comments