Skip to content

Commit

Permalink
Merge pull request #697 from UKHSA-Internal/improvements_to_deploymen…
Browse files Browse the repository at this point in the history
…t_scripts

Add env vars filtering to 'patchUrls.js'
  • Loading branch information
jaro-m authored Oct 11, 2023
2 parents 0576fe1 + f8bcddb commit 8ac6f3d
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions scripts/patchUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ const getFiles = (directory) => {
}; // getFiles


/**
* The function filters environment variables and returns only the important ones.
*
* @returns {object}
*/
const filterEnvVars = () => {
const vars = process.env;
const valid_keys = [
"BASE_URL",
"MAIN_CDN",
"DOWNLOADS_CDN",
"API_ENDPOINT",
"USER_API_ENDPOINT",
"APPINSIGHTS_INSTRUMENTATIONKEY"
]
const filteredVars = {}

Object.keys(vars).forEach(key => {
// Check if it can be one of the vars to use.
valid_keys.forEach(valid_key => {
if(vars.hasOwnProperty(key) && key.includes(valid_key)) {
filteredVars[key] = vars[key]
}
})
})

return filteredVars
}


/**
* Replaces placeholders formatted as `%key%` with environment
* variables defined using the same key.
Expand All @@ -94,18 +124,17 @@ const main = async () => {
files = getFiles(directory),
Replacements = {
...extractEnvVars(),
...process.env
...filterEnvVars()
};

console.log("+++ extractEnvVars():", extractEnvVars())
console.log("+++ process.env:", process.env)
console.log("+++ Number of files =", files.length)
console.log("vars:", Replacements)
console.log("vars number:", Object.keys(Replacements).length)

let counter = 0;

for ( const file of files ) {
counter += 1;
console.log(counter, " - ", file)
console.log(counter, " - processing file:", file)

const tmpFile = `${ file }.tmp`;

Expand Down

0 comments on commit 8ac6f3d

Please sign in to comment.