UNPKG

@artilleryio/platform-fargate

Version:
1 lines 1.46 kB
"use strict";const util=require("../util"),awsUtil=require("../aws-util"),ALLOWED_CONFIG_PARAMETERS=require("../constants")["ALLOWED_CONFIG_PARAMETERS"],setDefaultAWSCredentials=require("../utils/aws-set-default-credentials");async function set(options){var name=options.name,value=options.value;if(options.region||(console.log(util.formatError(new Error("A region must be specified, e.g. us-east-1"))),process.exit(1)),-1===util.supportedRegions.indexOf(options.region)&&(console.log(`Unsupported region (${options.region}) provided. Please specify one of: ${util.supportedRegions.join(", ")} `),process.exit(1)),name&&value||(console.log(util.formatError(new Error("Both name and value must be provided"))),process.exit(1)),"BACKEND_DATABASE_CONFIG"===name)try{JSON.parse(value)}catch(parseErr){console.error("The value of BACKEND_DATABASE_CONFIG is expected to be a valid JSON object"),process.exit(1)}await setDefaultAWSCredentials();name=name.toUpperCase();ALLOWED_CONFIG_PARAMETERS.indexOf(name)<0&&(console.log(util.formatError(new Error("Parameter name must be one of: "+ALLOWED_CONFIG_PARAMETERS.join(", ")))),process.exit(1));try{var type="NPM_TOKEN"===name?"SecureString":"String";await awsUtil.putParameter("/artilleryio/"+name,value,type,options.region),console.log(`Parameter ${name} in ${options.region} has been updated`,"SecureString"==type?"(encrypted)":"")}catch(err){console.log(util.formatError(err)),process.exit(1)}}module.exports={set:set};