Skip to content

Commit e583167

Browse files
authored
Merge pull request #295 from BSFishy/yaml_env
Support environment variables in config file
2 parents 1a4bd8f + 1076467 commit e583167

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Looking to **upgrade from V1 to V2**? Look [here](#upgrading-from-v1-to-v2)
1212
- [Running in docker](#running-in-docker)
1313
- [Docker-compose with config file (recommended)](#docker-docker-compose-together-with-configyaml)
1414
- [Docker-compose only](#docker-specifying-all-settings-in-docker-compose)
15+
- [Config file](#config-file)
1516
- [Upgrading from V1 to V2](#upgrading-from-v1-to-v2)
1617
- [Explanation of the settings](#explanation-of-the-settings)
1718
- [General](#general-settings)
@@ -288,6 +289,29 @@ services:
288289
# - $DOCKERDIR/appdata/decluttarr/logs:/app/logs # Uncomment to get logs in text file, too
289290
# - $DATADIR/media:/media # If you use detect_deletions, add the identical mount paths that you use in your sonarr/radarr instances. This may be different to this example!
290291
```
292+
293+
### Config file
294+
295+
Decluttarr V2 introduces a new configuration file that allows specifying
296+
configurations in YAML instead of through environment variables. It has the
297+
benefit of supporting multiple instances of the arrs and download clients. You
298+
can view [config_example.yaml](./config/config_example.yaml) for an example.
299+
300+
The config file supports environment variables through the `!ENV` tag. For
301+
example, if you don't want to specify API keys statically, you can pass them in
302+
through environment variables and set your configuration to something like:
303+
304+
```yaml
305+
instances:
306+
sonarr:
307+
- base_url: "http://sonarr.media"
308+
api_key: !ENV SONARR_API_KEY
309+
310+
radarr:
311+
- base_url: "http://radarr.media"
312+
api_key: !ENV RADARR_API_KEY
313+
```
314+
291315
## Upgrading from V1 to V2
292316
293317
Decluttarr v2 is a major update with a cleaner config format and powerful new features. Here's what changed and how to upgrade.

docker/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ black==24.8.0
99
pylint==3.3.3
1010
autoflake==2.3.1
1111
isort==5.13.2
12-
envyaml==1.10.211231
12+
pyyaml_env_tag==1.1
1313
demjson3==3.0.6
1414
ruff==0.11.11
15-
watchdog==6.0.0
15+
watchdog==6.0.0

src/settings/_user_config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22
from pathlib import Path
33
import yaml
4+
from yaml_env_tag import add_env_tag
45

56
from src.utils.log_setup import logger
67

8+
LOADER = add_env_tag(yaml.Loader)
9+
710
CONFIG_MAPPING = {
811
"general": [
912
"LOG_LEVEL",
@@ -82,7 +85,7 @@ def _load_from_env() -> dict:
8285
continue
8386

8487
try:
85-
parsed_value = yaml.safe_load(raw_value)
88+
parsed_value = yaml.load(raw_value, Loader=LOADER)
8689
parsed_value = _lowercase(parsed_value)
8790
except yaml.YAMLError as e:
8891
logger.error(
@@ -116,7 +119,7 @@ def _load_from_yaml_file(settings):
116119
config_path = settings.paths.config_file
117120
try:
118121
with Path(config_path).open(encoding="utf-8") as file:
119-
return yaml.safe_load(file) or {}
122+
return yaml.load(file, Loader=LOADER) or {}
120123
except yaml.YAMLError as e:
121124
logger.error("Error reading YAML file: %s", e)
122125
return {}

0 commit comments

Comments
 (0)