Skip to content

Settings

Settings from environment variables.

Settings

Bases: BaseSettings

Environment variables.

Source code in teledetection/sdk/settings.py
class Settings(BaseSettings):
    """Environment variables."""

    tld_ttl_margin: NonNegativeInt = 1800
    tld_url_duration: NonNegativeInt = 0
    tld_config_dir: str = ""
    tld_access_key: str = ""
    tld_secret_key: str = ""
    tld_request_timeout: int = 30
    tld_retry_total: PositiveInt = 10
    tld_retry_backoff_factor: PositiveFloat = 0.8
    tld_disable_auth: bool = False
    tld_signing_endpoint: str = DEFAULT_SIGNING_ENDPOINT

    @field_validator("tld_signing_endpoint", mode="after")
    @classmethod
    def val_endpoint_after(cls, val):
        """Post initialization."""
        if not val.lower().startswith(("http://", "https://")):
            raise ValueError(f"{val} must start with http[s]://")
        if not val.endswith("/"):
            val += "/"
        return val

val_endpoint_after(val) classmethod

Post initialization.

Source code in teledetection/sdk/settings.py
@field_validator("tld_signing_endpoint", mode="after")
@classmethod
def val_endpoint_after(cls, val):
    """Post initialization."""
    if not val.lower().startswith(("http://", "https://")):
        raise ValueError(f"{val} must start with http[s]://")
    if not val.endswith("/"):
        val += "/"
    return val

get_config_path()

Get path to config directory (usually in ~/.config/).

Source code in teledetection/sdk/settings.py
def get_config_path() -> str | None:
    """Get path to config directory (usually in ~/.config/)."""
    log.debug("Get config path")
    cfg_path = ENV.tld_config_dir or appdirs.user_config_dir(appname=APP_NAME)
    if not os.path.exists(cfg_path):
        try:
            os.makedirs(cfg_path)
            log.debug("Config dir created in %s", cfg_path)
        except PermissionError:
            log.warning("Unable to use config dir %s", cfg_path)  # pragma: no cover
            cfg_path = None  # pragma: no cover
    else:
        log.debug("Using existing config dir %s", cfg_path)
    return cfg_path