Skip to content

Commit

Permalink
escaping secrets and formatting Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelStancik committed May 24, 2021
1 parent ba9d4d6 commit a7a8992
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 17 deletions.
40 changes: 33 additions & 7 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
45 changes: 37 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}


Expand Down

0 comments on commit a7a8992

Please sign in to comment.