Skip to content

Commit

Permalink
Use sample secrets as base for secrets (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg authored Dec 14, 2023
1 parent 90b3000 commit 65878ee
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ import {Secrets} from "../types/types";
* @returns A promise that resolves to the secrets object.
*/
const getSecrets = async (): Promise<Secrets> => {
const sampleSecrets = await fs.readJson(
new URL("../secrets.sample.json", import.meta.url),
);

// Remove Selenium hosts from sample secrets
sampleSecrets.selenium = {};

// In testing environments, real secrets shouldn't be used
if (process.env.NODE_ENV === "test") {
return await fs.readJson(
new URL("../secrets.sample.json", import.meta.url),
);
return sampleSecrets;
}

// If SECRETS_JSON present, try to parse and use it
if (process.env.SECRETS_JSON) {
try {
return JSON.parse(process.env.SECRETS_JSON);
return {...sampleSecrets, ...JSON.parse(process.env.SECRETS_JSON)};
} catch {
console.warn(
"SECRETS_JSON environment variable present but is not valid JSON; using secrets.json...",
Expand All @@ -36,7 +41,10 @@ const getSecrets = async (): Promise<Secrets> => {
}

// Use secrets.json
return await fs.readJson(new URL("../secrets.json", import.meta.url));
return {
...sampleSecrets,
...(await fs.readJson(new URL("../secrets.json", import.meta.url))),
};
};

export default getSecrets;

0 comments on commit 65878ee

Please sign in to comment.