@@ -30,11 +30,8 @@ const {Storage} = require('@google-cloud/storage');
3030 */
3131class CustomAwsSupplier {
3232 constructor ( ) {
33- // Will be cached upon first resolution.
3433 this . region = null ;
3534
36- // Initialize the AWS credential provider.
37- // The AWS SDK handles memoization (caching) and proactive refreshing internally.
3835 this . awsCredentialsProvider = fromNodeProviderChain ( ) ;
3936 }
4037
@@ -65,7 +62,6 @@ class CustomAwsSupplier {
6562 * Retrieves AWS security credentials using the AWS SDK's default provider chain.
6663 */
6764 async getAwsSecurityCredentials ( _context ) {
68- // Call the initialized provider. It will return cached creds or refresh if needed.
6965 const awsCredentials = await this . awsCredentialsProvider ( ) ;
7066
7167 if ( ! awsCredentials . accessKeyId || ! awsCredentials . secretAccessKey ) {
@@ -75,7 +71,6 @@ class CustomAwsSupplier {
7571 ) ;
7672 }
7773
78- // Map the AWS SDK format to the google-auth-library format.
7974 return {
8075 accessKeyId : awsCredentials . accessKeyId ,
8176 secretAccessKey : awsCredentials . secretAccessKey ,
@@ -131,40 +126,25 @@ function loadConfigFromFile() {
131126
132127 try {
133128 const secrets = JSON . parse ( fs . readFileSync ( secretsPath , 'utf8' ) ) ;
134-
135129 if ( ! secrets ) {
136130 return ;
137131 }
138132
139- // AWS SDK for Node.js looks for environment variables with specific names.
140- if ( secrets . aws_access_key_id ) {
141- process . env . AWS_ACCESS_KEY_ID = secrets . aws_access_key_id ;
142- }
143- if ( secrets . aws_secret_access_key ) {
144- process . env . AWS_SECRET_ACCESS_KEY = secrets . aws_secret_access_key ;
145- }
146- if ( secrets . aws_region ) {
147- process . env . AWS_REGION = secrets . aws_region ;
148- }
149-
150- // Set custom GCP variables so they can be retrieved from process.env.
151- if ( secrets . gcp_workload_audience ) {
152- process . env . GCP_WORKLOAD_AUDIENCE = secrets . gcp_workload_audience ;
153- }
154- if ( secrets . gcs_bucket_name ) {
155- process . env . GCS_BUCKET_NAME = secrets . gcs_bucket_name ;
156- }
157- if ( secrets . gcp_service_account_impersonation_url ) {
158- process . env . GCP_SERVICE_ACCOUNT_IMPERSONATION_URL =
159- secrets . gcp_service_account_impersonation_url ;
160- }
133+ const configMapping = {
134+ aws_access_key_id : 'AWS_ACCESS_KEY_ID' ,
135+ aws_secret_access_key : 'AWS_SECRET_ACCESS_KEY' ,
136+ aws_region : 'AWS_REGION' ,
137+ gcp_workload_audience : 'GCP_WORKLOAD_AUDIENCE' ,
138+ gcs_bucket_name : 'GCS_BUCKET_NAME' ,
139+ gcp_service_account_impersonation_url :
140+ 'GCP_SERVICE_ACCOUNT_IMPERSONATION_URL' ,
141+ } ;
161142 } catch ( error ) {
162143 console . error ( `Error reading secrets file: ${ error . message } ` ) ;
163144 }
164145}
165146
166147async function main ( ) {
167- // Reads the secrets.json if running locally.
168148 loadConfigFromFile ( ) ;
169149
170150 const gcpAudience = process . env . GCP_WORKLOAD_AUDIENCE ;
0 commit comments