Skip to content

Commit a3580ea

Browse files
committed
Implement API key authentication, rate limiting, and admin management features
- Added security middleware to validate API keys for protected endpoints. - Implemented tier-based access control for API keys (basic, premium, master). - Introduced rate limiting for global data access based on client tier. - Created admin routes for API key management (CRUD operations). - Enhanced logging and error handling for security-related operations. - Updated requirements to include Flask-Limiter and python-dotenv. - Added Docker support with a multi-stage Dockerfile and docker-compose configuration. - Created comprehensive environment configuration in .env.example. - Developed a test suite for security features including API key validation and rate limiting. - Updated documentation to reflect new security and deployment features.
1 parent dc2dbce commit a3580ea

13 files changed

Lines changed: 1436 additions & 33 deletions

.dockerignore

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Docker ignore patterns
2+
3+
# Environment files
4+
.env
5+
.env.local
6+
.env.*.local
7+
8+
# Python
9+
__pycache__/
10+
*.py[cod]
11+
*$py.class
12+
*.so
13+
.Python
14+
env/
15+
venv/
16+
ENV/
17+
env.bak/
18+
venv.bak/
19+
.venv/
20+
21+
# Testing
22+
.pytest_cache/
23+
.coverage
24+
htmlcov/
25+
.tox/
26+
.nox/
27+
28+
# IDE
29+
.vscode/
30+
.idea/
31+
*.swp
32+
*.swo
33+
*~
34+
35+
# OS
36+
.DS_Store
37+
.DS_Store?
38+
._*
39+
.Spotlight-V100
40+
.Trashes
41+
ehthumbs.db
42+
Thumbs.db
43+
44+
# Git
45+
.git/
46+
.gitignore
47+
48+
# Docker
49+
Dockerfile*
50+
docker-compose*
51+
.dockerignore
52+
53+
# Documentation drafts
54+
*.draft.md
55+
56+
# Logs (but keep logs directory)
57+
logs/*.log
58+
logs/*.txt
59+
60+
# Temporary files
61+
*.tmp
62+
*.temp
63+
64+
# Archive and backup files
65+
archive/
66+
backup/
67+
*.bak
68+
69+
# Large data files (keep structure but not actual files)
70+
data/*.csv
71+
data/*.json
72+
data/*.xlsx
73+
output/*.csv
74+
output/*.json
75+
output/*.xlsx
76+
77+
# But keep example/reference files
78+
!reference/
79+
!data/README.md

.env.example

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Environment Configuration for Permit API
2+
# Copy this file to .env and update with your values
3+
4+
# Flask Configuration
5+
FLASK_ENV=development
6+
FLASK_DEBUG=1
7+
FLASK_APP=api.api_server:app
8+
9+
# Security - API Keys
10+
# Format: "key1:client_name1:tier1,key2:client_name2:tier2"
11+
# Tiers: basic (30 req/min), premium (100 req/min)
12+
API_KEYS=your_api_key_here:YourClient:basic,premium_key_here:PremiumClient:premium
13+
14+
# Master API Key (highest privileges)
15+
MASTER_API_KEY=your_secure_master_key_here
16+
17+
# Data Sources Configuration
18+
# EDGAR Excel Path (optional - defaults to reference/EDGAR_emiss_on_UCDB_2024.xlsx)
19+
EDGAR_XLSX_PATH=/app/reference/EDGAR_emiss_on_UCDB_2024.xlsx
20+
21+
# ISO Data Sources (optional)
22+
ISO_CSV_URL=https://example.com/iso14001_certificates.csv
23+
ISO_XLSX_PATH=/app/reference/list_iso.xlsx
24+
25+
# EEA API Configuration (uses default EEA Downloads API)
26+
EEA_BASE_URL=https://eeadmz1-downloads-api-appservice.azurewebsites.net
27+
28+
# Rate Limiting
29+
RATELIMIT_STORAGE_URL=memory://
30+
31+
# Logging Configuration
32+
LOG_LEVEL=INFO
33+
LOG_FILE=/app/logs/permit_api.log
34+
35+
# Database Configuration (if using PostgreSQL for API keys)
36+
# DATABASE_URL=postgresql://username:password@localhost:5432/permit_api
37+
38+
# Redis Configuration (if using Redis for caching)
39+
# REDIS_URL=redis://localhost:6379/0
40+
41+
# Security Headers
42+
SECURITY_HEADERS_ENABLED=true
43+
44+
# CORS Configuration
45+
CORS_ORIGINS=*
46+
CORS_METHODS=GET,POST,PUT,DELETE,OPTIONS
47+
CORS_HEADERS=Content-Type,Authorization,X-API-Key
48+
49+
# Development/Testing
50+
TESTING=false
51+
SAMPLE_DATA_ENABLED=true
52+
53+
# Production Settings (uncomment for production)
54+
# FLASK_ENV=production
55+
# FLASK_DEBUG=0
56+
# LOG_LEVEL=WARNING
57+
# SAMPLE_DATA_ENABLED=false

0 commit comments

Comments
 (0)