Spaces:
Running
Running
File size: 951 Bytes
bab156e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
|