Skip to content

hyperion.ports.secrets

hyperion.ports.secrets

Port: secrets manager abstraction.

Abstract :class:SecretsManager base and the :data:SECRET_PATTERN used by translate_env_vars. Concrete adapters (DummySecretsManager, AWSSecretsManager, EnvSecretsManager) live in hyperion.adapters.secrets.*; _create_new delegates backend selection to :mod:hyperion.composition (the single composition root).

SecretsManager

Bases: ABC

translate_env_vars staticmethod

translate_env_vars()

Loop through all env variables and replace secrets with their values.

Only variables with value pattern of !#secret:#secret_name will be replaced.

Source code in hyperion/ports/secrets.py
@staticmethod
def translate_env_vars() -> None:
    """Loop through all env variables and replace secrets with their values.

    Only variables with value pattern of `!#secret:#secret_name` will be replaced.
    """
    for key, value in os.environ.items():
        if (match := SECRET_PATTERN.match(value)) is not None:
            secret_name = match.group("secret_name")
            logger.info("Replacing secret in environment variable.", key=key, secret_name=secret_name)
            os.environ[key] = SecretsManager.from_config().get_secret(secret_name)

get_secret abstractmethod

get_secret(secret_name)

Get the secret with the given name.

Source code in hyperion/ports/secrets.py
@abc.abstractmethod
def get_secret(self, secret_name: str) -> str:
    """Get the secret with the given name."""