1+ // @ts -check
2+
13// Copyright The Linux Foundation and each contributor to CommunityBridge.
24// SPDX-License-Identifier: MIT
35const AWS = require ( 'aws-sdk' ) ;
46
5- // @ts -check
6-
7-
87/**
98 * @param {string[] } variables
109 * @param {string } stage
1110 * @param {string } region
11+ * @param {string } profile
1212 * @returns {Promise<{ [key:string]: string}> }
1313 */
14- async function retrieveSSMValues ( variables , stage , region ) {
14+ async function retrieveSSMValues ( variables , stage , region , profile ) {
1515 const scopedVariables = variables . map ( ( param ) => `cla-${ param } -${ stage } ` ) ;
16- const result = await requestSSMParameters ( scopedVariables , stage , region ) ;
16+ const result = await requestSSMParameters ( scopedVariables , stage , region , profile ) ;
1717 const parameters = result . Parameters ;
1818 const error = result . $response . error ;
1919 if ( error !== null ) {
2020 throw new Error (
21- `Couldn't retrieve SSM parameters for stage ${ stage } in region ${ region } - error ${ error } `
21+ `Couldn't retrieve SSM parameters for stage ${ stage } in region ${ region } using profile ${ profile } - error ${ error } `
2222 ) ;
2323 }
2424 const scopedParams = createParameterMap ( parameters , stage ) ;
2525 const params = new Map ( ) ;
2626 Object . keys ( scopedParams ) . forEach ( ( key ) => {
27+ // console.log(`processing ${key}`);
2728 const param = scopedParams [ key ] ;
2829 key = key . replace ( 'cla-' , '' ) ;
2930 key = key . replace ( `-${ stage } ` , '' ) ;
@@ -33,7 +34,7 @@ async function retrieveSSMValues(variables, stage, region) {
3334 variables . forEach ( ( variable ) => {
3435 if ( params [ variable ] === undefined ) {
3536 throw new Error (
36- `Missing SSM parameter with name ${ variable } for stage ${ stage } in region ${ region } ` ,
37+ `Missing SSM parameter with name ${ variable } for stage ${ stage } in region ${ region } using profile ${ profile } ` ,
3738 ) ;
3839 }
3940 } ) ;
@@ -46,14 +47,20 @@ async function retrieveSSMValues(variables, stage, region) {
4647 * @param {string[] } variables
4748 * @param {string } stage
4849 * @param {string } region
50+ * @param {string } profile
4951 */
50- async function requestSSMParameters ( variables , stage , region ) {
52+ async function requestSSMParameters ( variables , stage , region , profile ) {
53+ console . log ( `Loading AWS credentials from profile: ${ profile } ` )
54+ AWS . config . credentials = new AWS . SharedIniFileCredentials ( { profile } ) ;
5155 const ssm = new AWS . SSM ( { region } ) ;
5256 const ps = {
5357 Names : variables ,
5458 WithDecryption : true
5559 } ;
60+ // console.log(AWS.config.credentials);
61+ // console.log(`fetching ssm parameters: ${variables}`);
5662 const response = await ssm . getParameters ( ps ) . promise ( ) ;
63+ // console.log(response);
5764 return response ;
5865}
5966
0 commit comments