Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 9161303

Browse files
author
danecreekphotography
authored
Fix issue with new secrets system (#395)
* Check for null secrets before attempting to replace them. * Make things work when no secrets are specified * Fix missing return statement * Make settings work when the alternate location is used instead * Fix unit tests
1 parent d1a11ba commit 9161303

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 5.5.1
4+
5+
- Resolve an issue where the system fails to start if no secrets file exists but the existing `settings.json` or `triggers.json` file uses
6+
mustache templates, or when the secrets method of loading the settings file isn't used. Resolves [issue 394](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/394).
7+
38
## 5.5.0
49

510
- Secrets can now be stored in a separate `secrets.json` file and inserted in `settings.json` and `triggers.json` via mustache templates. Resolves

src/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function parseFile(serviceName: string, fileType: string, filePath: string) {
2828
* @type T The type the settings should return as.
2929
*/
3030
function replaceSecrets<T>(settings: T, secrets: { a: string }) {
31+
// If no secrets were provided don't attempt to do a replacement
32+
if (!secrets) return settings;
33+
3134
return JSONC.parse(Mustache.render(JSON.stringify(settings), secrets));
3235
}
3336

@@ -40,7 +43,8 @@ function replaceSecrets<T>(settings: T, secrets: { a: string }) {
4043
export function readSettings<T>(serviceName: string, serviceFilePath: string, secretsFilePath = ""): T {
4144
const settings = parseFile(serviceName, "settings", serviceFilePath);
4245
if (!settings) {
43-
throw new Error(`[${serviceName}] Unable to load file ${serviceFilePath}.`);
46+
log.warn(serviceName, `Unable to load file ${serviceFilePath}.`);
47+
return null;
4448
}
4549
const secrets = parseFile(serviceName, "secrets", secretsFilePath);
4650
return replaceSecrets<T>(settings, secrets);

tests/helpers.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ describe("helpers", () => {
9090
expect(actualSettings).toEqual(expectedSettings);
9191
});
9292

93-
test("Verify throws if settings.json empty", () => {
93+
test("Verify logs with message if settings.json empty", () => {
9494
const expectedSettings = "";
9595
writeFileSync(settingsFilePath, expectedSettings);
9696

97-
expect(() => {
98-
helpers.readSettings(serviceName, settingsFilePath);
99-
}).toThrow(Error);
97+
helpers.readSettings(serviceName, settingsFilePath);
98+
99+
//eslint-disable-next-line no-console
100+
expect(console.log).toHaveBeenCalledWith(
101+
expect.stringContaining(`[${serviceName}] Unable to read the settings file: ENOENT: no such file or directory`),
102+
);
100103
});
101104

102-
test("Verify throws with message if settings.json empty", () => {
105+
test("Verify logs with message with message if settings.json empty", () => {
103106
const expectedSettings = "";
104107
writeFileSync(settingsFilePath, expectedSettings);
105108

0 commit comments

Comments
 (0)