-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use
confz
for env variable parsing (#119)
* fix: use `confz` for env variable parsing * ci: add missing env vars
- Loading branch information
1 parent
acabc0e
commit 7e6988a
Showing
18 changed files
with
116 additions
and
124 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,5 +1,5 @@ | ||
# Default configuration values. These are overwritten by docker-compose.yml environment variables | ||
VALENTINA_LOG_FILE = "/valentina/valentina.log" | ||
VALENTINA_LOG_LEVEL_AWS = "INFO" # Log level for AWS S3 client | ||
VALENTINA_LOG_LEVEL_AWS = "ERROR" # Log level for AWS S3 client | ||
VALENTINA_LOG_LEVEL_HTTP = "INFO" # Log level for discord HTTP, gateway, webhook, client events | ||
VALENTINA_LOG_LEVEL = "INFO" # Overall log level for the bot |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
"""Utility functions for Valentina.""" | ||
|
||
from .config import ValentinaConfig | ||
from .console import console | ||
from .helpers import random_num | ||
from .logging import InterceptHandler, instantiate_logger | ||
|
||
__all__ = ["Context", "InterceptHandler", "console", "instantiate_logger", "random_num"] | ||
__all__ = [ | ||
"Context", | ||
"InterceptHandler", | ||
"ValentinaConfig", | ||
"console", | ||
"instantiate_logger", | ||
"random_num", | ||
] |
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,15 +1,36 @@ | ||
"""Gather configuration from environment variables.""" | ||
|
||
import os | ||
from pathlib import Path | ||
from typing import ClassVar | ||
|
||
from dotenv import dotenv_values | ||
from confz import BaseConfig, ConfigSources, EnvSource | ||
|
||
DIR = Path(__file__).parents[3].absolute() | ||
CONFIG = { | ||
**dotenv_values(DIR / ".env"), # load shared variables | ||
**dotenv_values(DIR / ".env.secrets"), # load sensitive variables | ||
**os.environ, # override loaded values with environment variables | ||
} | ||
for k, v in CONFIG.items(): | ||
CONFIG[k] = v.replace('"', "").replace("'", "").replace(" ", "") | ||
|
||
|
||
#### NEW CONFIG #### | ||
class ValentinaConfig(BaseConfig): # type: ignore [misc] | ||
"""Valentina configuration.""" | ||
|
||
aws_access_key_id: str | None = None | ||
aws_secret_access_key: str | None = None | ||
discord_token: str | ||
github_repo: str | None = None | ||
github_token: str | None = None | ||
guilds: str | ||
log_file: str = "/valentina/valentina.log" | ||
log_level_aws: str = "INFO" | ||
log_level_http: str = "WARNING" | ||
log_level: str = "INFO" | ||
mongo_database_name: str = "valentina" | ||
mongo_uri: str = "mongodb://localhost:27017" | ||
owner_channels: str | ||
owner_ids: str | None = None | ||
s3_bucket_name: str | None = None | ||
test_mongodb_uri: str = "mongodb://localhost:27017" | ||
test_mongodb_db: str = "valentina-test-db" | ||
|
||
CONFIG_SOURCES: ClassVar[ConfigSources | None] = [ | ||
EnvSource(prefix="VALENTINA_", file=DIR / ".env", allow_all=True), | ||
EnvSource(prefix="VALENTINA_", file=DIR / ".env.secrets", allow_all=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
Oops, something went wrong.