-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: read config options from environment variables
- Loading branch information
Showing
12 changed files
with
134 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
SERVICE_URL=http://localhost:8080 | ||
SERVICE_API_URL=https://localhost:8080/api | ||
SERVICE_NAME=Abrechnung | ||
DB_HOST=abrechnung_postgres | ||
DB_USER=abrechnung | ||
DB_NAME=abrechnung | ||
DB_PASSWORD=replaceme # e.g. pwgen -s 64 1 | ||
ABRECHNUNG_SERVICE__URL=http://localhost:8080 | ||
ABRECHNUNG_SERVICE__API_URL=https://localhost:8080/api | ||
ABRECHNUNG_SERVICE__NAME=Abrechnung | ||
ABRECHNUNG_DATABASE__HOST=abrechnung_postgres | ||
ABRECHNUNG_DATABASE__USER=abrechnung | ||
ABRECHNUNG_DATABASE__DBNAME=abrechnung | ||
ABRECHNUNG_DATABASE__PASSWORD=replaceme # e.g. pwgen -s 64 1 | ||
|
||
ABRECHNUNG_SECRET=replaceme # pwgen -s 64 1 | ||
ABRECHNUNG_PORT=8080 | ||
ABRECHNUNG_ID=default | ||
ABRECHNUNG_API__SECRET_KEY=replaceme # pwgen -s 64 1 | ||
ABRECHNUNG_API__PORT=8080 | ||
ABRECHNUNG_API__ID=default | ||
|
||
REGISTRATION_ENABLED=false | ||
REGISTRATION_VALID_EMAIL_DOMAINS=sft.lol,sft.mx | ||
REGISTRATION_ALLOW_GUEST_USERS=true | ||
ABRECHNUNG_REGISTRATION__ENABLED=false | ||
|
||
ABRECHNUNG_EMAIL=[email protected] | ||
SMTP_HOST=mail | ||
SMTP_PORT=1025 | ||
SMTP_MODE=smtp | ||
#SMTP_MODE=smtp-starttls # use this in production, remove line above | ||
SMTP_USER=username | ||
SMTP_PASSWORD=replaceme | ||
ABRECHNUNG_EMAIL__ADDRESS=[email protected] | ||
ABRECHNUNG_EMAIL__HOST=mail | ||
ABRECHNUNG_EMAIL__PORT=1025 | ||
ABRECHNUNG_EMAIL__MODE=smtp | ||
#ABRECHNUNG_EMAIL__MODE=smtp-starttls # use this in production, remove line above | ||
ABRECHNUNG_EMAIL__AUTH__USERNAME=username | ||
ABRECHNUNG_EMAIL__AUTH__PASSWORD=replaceme | ||
|
||
POSTGRES_USER=abrechnung | ||
POSTGRES_PASSWORD=replaceme # use the same as DB_PASSWORD | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,3 @@ services: | |
command: cron | ||
healthcheck: | ||
disable: true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
service: | ||
url: "https://localhost" | ||
api_url: "https://localhost/api" | ||
name: "Abrechnung" | ||
|
||
database: | ||
host: "0.0.0.0" | ||
user: "abrechnung" | ||
dbname: "abrechnung" | ||
|
||
api: | ||
host: "0.0.0.0" | ||
port: 8080 | ||
id: default | ||
|
||
registration: | ||
enabled: false | ||
|
||
email: | ||
host: "localhost" | ||
port: 587 | ||
mode: "smtp-starttls" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
from abrechnung.config import read_config | ||
|
||
docker_base_config = (Path(__file__).parent.parent / "docker" / "abrechnung.yaml").read_text() | ||
|
||
|
||
def test_config_load_from_env(): | ||
os.environ["ABRECHNUNG_SERVICE__NAME"] = "my abrechnung" | ||
os.environ["ABRECHNUNG_API__SECRET_KEY"] = "secret" | ||
os.environ["ABRECHNUNG_DATABASE__HOST"] = "localhost" | ||
os.environ["ABRECHNUNG_DATABASE__DBNAME"] = "abrechnung" | ||
os.environ["ABRECHNUNG_DATABASE__PASSWORD"] = "password" | ||
os.environ["ABRECHNUNG_DATABASE__USER"] = "abrechnung" | ||
os.environ["ABRECHNUNG_EMAIL__ADDRESS"] = "[email protected]" | ||
with tempfile.NamedTemporaryFile() as f: | ||
filename = Path(f.name) | ||
filename.write_text(docker_base_config, "utf-8") | ||
|
||
loaded_cfg = read_config(filename) | ||
|
||
assert loaded_cfg.service.name == "my abrechnung" | ||
assert loaded_cfg.api.secret_key == "secret" | ||
assert loaded_cfg.database.user == "abrechnung" | ||
assert loaded_cfg.database.host == "localhost" | ||
assert loaded_cfg.database.dbname == "abrechnung" | ||
assert loaded_cfg.database.password == "password" | ||
assert loaded_cfg.email.address == "[email protected]" |