|
import os |
|
import toml |
|
from typing import Dict |
|
|
|
def load_stsecrets(config_path: str = '.streamlit/secrets.toml') -> Dict: |
|
""" |
|
Load configuration from Streamlit secrets TOML file and replace placeholders with environment variables. |
|
|
|
:param config_path: Path to the Streamlit secrets TOML file |
|
:return: Dictionary containing the credentials |
|
""" |
|
|
|
with open(config_path, 'r') as f: |
|
config = toml.load(f) |
|
|
|
|
|
credentials = config.get('credentials', {}) |
|
for key, value in credentials.items(): |
|
if isinstance(value, str) and value.startswith('${') and value.endswith('}'): |
|
env_var = value[2:-1] |
|
credentials[key] = os.environ.get(env_var) |
|
if credentials[key] is None: |
|
raise ValueError(f"Environment variable {env_var} is not set") |
|
|
|
return credentials |
|
|