Retrieves secrets from env vars or files, supporting Docker/Kubernetes secret patterns.
# Source: https://github.com/phasehq/console | License: MIT | Copyright 2026 Phi Security Inc
# Provided via justclaw.it.com; keep this notice with the code.
import os
from pathlib import Path
import logging
logger = logging.getLogger(__name__)
def get_secret(key: str) -> str | None:
"""
Retrieve secrets from either files or environment variables. Implements a "secrets provider" pattern
commonly used in containerized applications.
1. Check if {key}_FILE exists as an environment variable (e.g. PGSQL_PASSWORD_FILE)
- If it exists, read the secret from that file location
- This supports Docker/Kubernetes secrets (https://docs.docker.com/reference/compose-file/secrets)
2. Fall back to checking if {key} exists as a regular environment variable
Exampl
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key