Skip to content

Centralize configuration in a settings file #83

@kerudev

Description

@kerudev

The project has little room for configuration as most of it is hardcoded.

It'd be nice to have a settings file where the user can set their configurations, or set them as environment variables with the CLOUDISK_ prefix, then get them with a function.

Example:

# settings.py
EMAIL_FROM = "..."

# .env
CLOUDISK_EMAIL_FROM = "..."

The getter function:

def get_config(key: str, default: Any):
    if isinstance(key, str):
        raise Error("key must be a string")

    if key.upper() != key:
        raise Error("key must have all uppercase")

    if env := os.environ.get(f"CLOUDISK_{key}"):
        return env

    settings = __import__(config_module):
    var = getattr(settings, key, default)

    return var

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions