Spaces:
Running
Running
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 | |
""" | |
# Read the TOML file | |
with open(config_path, 'r') as f: | |
config = toml.load(f) | |
# Replace placeholders with environment variables | |
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] # Remove ${ and } | |
credentials[key] = os.environ.get(env_var) | |
if credentials[key] is None: | |
raise ValueError(f"Environment variable {env_var} is not set") | |
return credentials | |