Skip to content

Add environment variable support to config.py with fallback defaults#2

Closed
Itsmmdoha with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-513a1230-e39f-47a5-b6e9-2e183b9f48ed
Closed

Add environment variable support to config.py with fallback defaults#2
Itsmmdoha with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-513a1230-e39f-47a5-b6e9-2e183b9f48ed

Conversation

Copilot AI commented Jul 3, 2025

Copy link
Copy Markdown

Summary

This PR converts hardcoded configuration values in config.py to environment variable-based configuration while maintaining full backward compatibility. Users can now override configuration values using environment variables for secure production deployments.

Changes Made

  • Updated config.py to use os.environ.get() for all configuration values
  • Added clear documentation comments specifying environment variable names
  • Maintained the same variable names and structure for backward compatibility
  • Provided all original hardcoded values as fallback defaults

Environment Variables Added

Variable Default Value Description
FRONTEND_HOST http://localhost:3000 Frontend application host URL
DATABASE_URL postgresql+psycopg://user:password@localhost:5432/binx PostgreSQL connection string
ENDPOINT b456c973fcfed7f5383ebbef9b82b425.r2.cloudflarestorage.com S3-compatible storage endpoint
ACCESS_KEY f962a8292930c0620a7a8166fe62f6cf S3 access key
SECRET_KEY cd2c90643a4f69992e4172eab295a707ea2e4d9c9b30a8283f32dea28faa4dbe S3 secret key
BUCKET_NAME binx S3 bucket name
JWT_SECRET_KEY your-secret-key JWT signing secret key

Usage Examples

Development (no changes needed)

# Uses built-in defaults - existing workflow unchanged
uvicorn app:app --reload

Production deployment

export FRONTEND_HOST="https://your-domain.com"
export DATABASE_URL="postgresql+psycopg://prod_user:secure_pass@db.example.com:5432/binx_prod"
export JWT_SECRET_KEY="your-very-secure-jwt-secret"
# ... set other production values
uvicorn app:app --host 0.0.0.0 --port 8000

Docker deployment

ENV FRONTEND_HOST=https://your-domain.com
ENV DATABASE_URL=postgresql+psycopg://user:pass@db:5432/binx
ENV JWT_SECRET_KEY=your-jwt-secret
# ... other environment variables

Benefits

  • Security: Sensitive values like keys can be kept out of source code
  • Flexibility: Easy configuration for different deployment environments
  • Backward Compatibility: Existing deployments continue to work unchanged
  • DevOps Friendly: Standard environment variable pattern for configuration

Testing

  • ✅ All modules import configuration values correctly
  • ✅ Environment variables override defaults when set
  • ✅ Fallback to defaults when environment variables are not set
  • ✅ Backward compatibility maintained for existing imports
  • ✅ Authentication and S3 functionality verified with new configuration

This change enables secure production deployments while maintaining the simplicity of the current development workflow.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Itsmmdoha Itsmmdoha closed this Jul 3, 2025
@Itsmmdoha Itsmmdoha deleted the copilot/fix-513a1230-e39f-47a5-b6e9-2e183b9f48ed branch July 3, 2025 11:35
Copilot AI changed the title [WIP] Refactor config.py to use environment variables with default fallbacks Add environment variable support to config.py with fallback defaults Jul 3, 2025
Copilot AI requested a review from Itsmmdoha July 3, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants