- Update Docker and Caddy configuration - Add VPS setup and secrets management scripts - Add test suite - Update documentation - Clean up cache files
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
import os
|
|
import sys
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
def setup_secrets():
|
|
"""Set up secrets for the ETF Portal application."""
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
# Get the FMP API key from user
|
|
fmp_api_key = input("Enter your FMP API key: ").strip()
|
|
if not fmp_api_key:
|
|
logger.error("❌ FMP API key is required")
|
|
return False
|
|
|
|
# Create .streamlit directory if it doesn't exist
|
|
streamlit_dir = Path(".streamlit")
|
|
streamlit_dir.mkdir(exist_ok=True)
|
|
|
|
# Create secrets.toml
|
|
secrets_path = streamlit_dir / "secrets.toml"
|
|
with open(secrets_path, "w") as f:
|
|
f.write(f'# FMP API Configuration\n')
|
|
f.write(f'FMP_API_KEY = "{fmp_api_key}"\n\n')
|
|
f.write(f'# Cache Configuration\n')
|
|
f.write(f'CACHE_DURATION_HOURS = 24\n')
|
|
|
|
# Set proper permissions
|
|
secrets_path.chmod(0o600) # Only owner can read/write
|
|
|
|
logger.info(f"✅ Secrets file created at {secrets_path}")
|
|
logger.info("🔒 File permissions set to 600 (owner read/write only)")
|
|
|
|
# Create cache directories
|
|
cache_dirs = [
|
|
Path("cache/FMP_cache"),
|
|
Path("cache/yfinance_cache")
|
|
]
|
|
|
|
for cache_dir in cache_dirs:
|
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
cache_dir.chmod(0o755) # Owner can read/write/execute, others can read/execute
|
|
logger.info(f"✅ Cache directory created: {cache_dir}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"❌ Setup failed: {str(e)}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("🔧 ETF Portal Secrets Setup")
|
|
print("===========================")
|
|
print("This script will help you set up the secrets for the ETF Portal application.")
|
|
print("Make sure you have your FMP API key ready.")
|
|
print()
|
|
|
|
success = setup_secrets()
|
|
if success:
|
|
print("\n✅ Setup completed successfully!")
|
|
print("\nNext steps:")
|
|
print("1. Run the test script to verify the configuration:")
|
|
print(" python -m ETF_Portal.tests.test_api_config")
|
|
print("\n2. If you're deploying to a server, make sure to:")
|
|
print(" - Set the secrets in your Streamlit dashboard")
|
|
print(" - Create the cache directories with proper permissions")
|
|
else:
|
|
print("\n❌ Setup failed. Check the logs for details.")
|
|
sys.exit(1) |