diff --git a/lib/index.js b/lib/index.js index 6eb510f..0e474b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,12 +41,13 @@ const preparation = (proposedEnvironment, proposedType) => __awaiter(void 0, voi throw new Error("Environment parameter set incorrectly, choose one of [TEST | STAGE | PROD]."); } if (!typeVariant.includes(proposedType)) { - throw new Error("Type parameter set incorrectly, choose one of [frontend | backend | both]."); + throw new Error("Type parameter set incorrectly, choose one of [frontend | backend."); } const prefix = proposedEnvironment; const type = proposedType; let arrJson = []; - let tfvars = []; + let tfvars_frontend = []; + let tfvars_backend = []; const azureParameters = yield manager.listAll(prefix, type); console.log(`Setting ENV params for environment: ${prefix} and type: ${type}:`); azureParameters.map(secretObject => { @@ -62,16 +63,41 @@ const preparation = (proposedEnvironment, proposedType) => __awaiter(void 0, voi }); const terraformParameters = yield manager.listAll(prefix); terraformParameters.map(secretObject => { - if (secretObject.enabled && secretObject.environment === prefix) { + if (secretObject.enabled && secretObject.environment === prefix && secretObject.tags.type !== undefined) { core.setSecret(secretObject.value); - tfvars.push(` ${secretObject.name} = ${secretObject.value}`); + secretObject.value = (secretObject.value).replace(/\\/g, "\\\\"); + if (secretObject.tags.type === 'frontend') + tfvars_frontend.push(` "${secretObject.name}"="${secretObject.value}"\ + `); + if (secretObject.tags.type === 'backend') + tfvars_backend.push(` "${secretObject.name}"="${secretObject.value}"\ + `); } }); core.setOutput("json", JSON.stringify(arrJson, null)); - core.setOutput("terraform", prepareTfVars(tfvars)); + core.setOutput("terraform", prepareTfVars(tfvars_frontend, tfvars_backend)); }); -const prepareTfVars = (tfvars) => { - return `web_app_settings = {${tfvars}}`; +const prepareTfVars = (frontend, backend) => { + frontend.toString = function () { + return this.join(`\ + `); + }; + backend.toString = function () { + return this.join(` + `); + }; + let return_object = `web_app_settings = {\ + `; + return_object = return_object.concat(`\ + frontend = {\ + ${frontend}\ + }, `); + return_object = return_object.concat(`\ + backend = {\ + ${backend} \ + } \ + }`); + return return_object; }; const e = core.getInput('ENVIRONMENT') || process.env.ENVIRONMENT; const t = core.getInput('TYPE') || process.env.TYPE; diff --git a/lib/index.js.map b/lib/index.js.map index bd2bdf6..906e259 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAClF,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC;AAE7C,kEAAoD;AAEpD,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,MAAM,WAAW,GAAG,CAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAE,CAAC;AAChD,MAAM,WAAW,GAAG,CAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAE,CAAC;AAGtD,MAAM,WAAW,GAAG,CAAO,mBAA2B,EAAE,YAAoB,EAAG,EAAE;IAE/E,oDAAoD;IAEpD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;QAC9C,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;KAChG;IACD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;KAC/F;IACD,MAAM,MAAM,GAAW,mBAAmB,CAAC;IAC3C,MAAM,IAAI,GAAW,YAAY,CAAC;IAClC,IAAI,OAAO,GAAS,EAAE,CAAC;IACvB,IAAI,MAAM,GAAa,EAAE,CAAC;IAE1B,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,uCAAuC,MAAM,cAAc,IAAI,GAA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AAa,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;AACnE,MAAM,CAAC,GAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;AAErD,WAAW,CAAC,CAAC,EAAC,CAAC,CAAC;KACf,KAAK,CAAE,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAE,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 590389b..4a39e0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "enhanced-env-azure-vault-action", - "version": "1.1.1", + "version": "1.1.2", "description": "This action gets secrets from Azure Vault as ENV parameters for specific environment and type.", "main": "index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 908232d..f9cded6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,12 +19,13 @@ const preparation = async (proposedEnvironment: string, proposedType: string ) = throw new Error("Environment parameter set incorrectly, choose one of [TEST | STAGE | PROD]."); } if (!typeVariant.includes(proposedType)) { - throw new Error("Type parameter set incorrectly, choose one of [frontend | backend | both]."); + throw new Error("Type parameter set incorrectly, choose one of [frontend | backend."); } const prefix: string = proposedEnvironment; const type: string = proposedType; let arrJson: {}[] = []; - let tfvars: string[] = []; + let tfvars_frontend: string[] = []; + let tfvars_backend: string[] = []; const azureParameters = await manager.listAll(prefix, type); @@ -49,21 +50,49 @@ const preparation = async (proposedEnvironment: string, proposedType: string ) = const terraformParameters = await manager.listAll(prefix); terraformParameters.map( secretObject => { - if (secretObject.enabled && secretObject.environment === prefix) { + if (secretObject.enabled && secretObject.environment === prefix && secretObject.tags.type !== undefined) { + core.setSecret(secretObject.value); - tfvars.push(` ${secretObject.name} = ${secretObject.value}`); + secretObject.value = (secretObject.value).replace(/\\/g, "\\\\"); + + if (secretObject.tags.type === 'frontend') tfvars_frontend.push(` "${secretObject.name}"="${secretObject.value}"\ + `); + if (secretObject.tags.type === 'backend') tfvars_backend.push(` "${secretObject.name}"="${secretObject.value}"\ + `); + } }) core.setOutput("json", JSON.stringify(arrJson, null)); - - core.setOutput("terraform", prepareTfVars(tfvars)); + core.setOutput("terraform", prepareTfVars(tfvars_frontend,tfvars_backend)); }; -const prepareTfVars = (tfvars: string[]) => { - return `web_app_settings = {${tfvars}}` +const prepareTfVars = (frontend: string[], backend: string[]) => { + + frontend.toString = function() { + return this.join(`\ + `); + }; + + backend.toString = function() { + return this.join(` + `); + }; + + let return_object = `web_app_settings = {\ + `; + return_object = return_object.concat(`\ + frontend = {\ + ${frontend}\ + }, `); + return_object = return_object.concat(`\ + backend = {\ + ${backend} \ + } \ + }`); + return return_object; }