diff --git a/.vscode/settings.json b/.vscode/settings.json index db8165b..67a7606 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "yaml.customTags": ["!secret"] + "yaml.customTags": ["!secret", "!env"] } diff --git a/README.md b/README.md index c86437a..89aa375 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,14 @@ Possible ideas: - [x] Local recyclarr templates to include - [ ] Clone existing templates: Lets say you want the same template but with a different name? +## Configuration + +- `config.yml` + - Check the template file [template](./config.yml.template) or check the examples. + - You can provide values with the custom tags: + - `value: !secret secretKey`: Loads the value from the secrets file with the key `secretKey` + - `value: !env ENV_NAME`: Loads the value from the environment variable `ENV_NAME` + ## Custom formats This repository also provide additional custom formats what TrashGuide does not offer. diff --git a/src/config.ts b/src/config.ts index 2284ec7..6e0f77c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,6 +19,22 @@ const secretsTag = { }, }; +const envTag = { + identify: (value: any) => value instanceof String, + tag: "!env", + resolve(str: string) { + const envValue = process.env[str]; + + if (!envValue) { + const message = `Environment variables '${str}' is not set.`; + logger.error(message); + throw new Error(message); + } + + return envValue; + }, +}; + // TODO some schema validation. For now only check if something can be imported export const getConfig = (): YamlConfig => { if (config) { @@ -31,7 +47,7 @@ export const getConfig = (): YamlConfig => { } const file = readFileSync(CONFIG_LOCATION, "utf8"); - config = yaml.parse(file, { customTags: [secretsTag] }) as YamlConfig; + config = yaml.parse(file, { customTags: [secretsTag, envTag] }) as YamlConfig; return config; };