-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp_config.py
122 lines (101 loc) · 4.09 KB
/
app_config.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
This file houses the total backend application configuration. It's setup such that you can load multiple
configurations based on the environment files' names. For example, having a file called '.env.dev' will
load the development config and a file called '.env.prod' will load the production config.
You may add more configuration types as you see fit. Scroll down to see examples of how each configuration
type is implemented.
"""
import datetime
import os
"""
README: If you want to add a new configuration environment, add an entry to 'ALLOWED_MODES'
"""
ALLOWED_MODES = ['local', 'dev', 'staging', 'prod']
MODE = os.getenv('MODE')
if MODE not in ALLOWED_MODES:
raise Exception(f'Invalid operating mode: "{MODE}"')
ENV_FILE = f'.env.{MODE}'
from dotenv import load_dotenv
load_dotenv(dotenv_path=ENV_FILE)
class BaseConfig(object):
"""
Base configuration object to load the application.
NOTE: You should only be changing this if you're adding new variables that affects *all* environments.
"""
# Flask settings
SECRET_KEY = os.getenv('SECRET_KEY')
FLASK_SECRET = os.getenv('SECRET_KEY')
JSON_ADD_STATUS = False
CORS_HEADERS = '*' # TODO: [Security] - Tweak headers "specifically"
UPLOAD_FOLDER = 'uploads'
ALLOWED_IMG_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # Max upload size if 16 MB
# Email token settings
CONFIRM_EMAIL_SALT = os.getenv('CONFIRM_EMAIL_SALT')
RESET_PASSWORD_SALT = os.getenv('RESET_PASSWORD_SALT')
CONFIRM_EMAIL_EXPIRY = datetime.timedelta(weeks=1)
RESET_PASSWORD_EXPIRY = datetime.timedelta(minutes=30)
# JWT settings
JWT_SECRET_KEY = os.getenv('SECRET_KEY')
JWT_BLACKLIST_ENABLED = True
JWT_BLACKLIST_TOKEN_CHECKS = ['access', 'refresh']
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(minutes=30)
JWT_REFRESH_TOKEN_EXPIRES = datetime.timedelta(days=15)
# Mail SMTP server settings
MAIL_SERVER = os.getenv('MAIL_SERVER')
MAIL_PORT = int(os.getenv('MAIL_PORT'))
MAIL_USE_SSL = os.getenv('MAIL_USE_SSL') == 'true'
MAIL_USE_TLS = os.getenv('MAIL_USE_TLS') == 'true'
MAIL_USERNAME = os.getenv('MAIL_USERNAME')
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD')
MAIL_DEFAULT_SENDER = f'"sproul.club" <{os.getenv("MAIL_SENDER")}>'
# AWS S3 settings
S3_REGION = os.getenv('S3_REGION')
S3_BUCKET = os.getenv('S3_BUCKET')
S3_ACCESS_KEY = os.getenv('S3_KEY')
S3_SECRET_KEY = os.getenv('S3_SECRET')
# Google OAuth key and secret
GOOGLE_OAUTH_CLIENT_ID = os.getenv('GOOGLE_OAUTH_CLIENT_ID')
GOOGLE_OAUTH_CLIENT_SECRET = os.getenv('GOOGLE_OAUTH_CLIENT_SECRET')
"""
README: If you want to add a new configuration environment, add a new class like the examples below.
"""
class LocalConfig(BaseConfig):
DEBUG = True
MODE = 'local'
DATABASE_NAME = 'develop-db'
FRONTEND_BASE_URL = 'http://localhost:3000'
BACKEND_BASE_URL = 'http://localhost:5000'
class DevelopmentConfig(BaseConfig):
DEBUG = True
MODE = 'dev'
DATABASE_NAME = 'develop-db'
FRONTEND_BASE_URL = 'http://localhost:3000'
BACKEND_BASE_URL = 'https://sc-backend-dev.herokuapp.com'
class StagingConfig(BaseConfig):
DEBUG = False
MODE = 'staging'
DATABASE_NAME = 'staging-db'
FRONTEND_BASE_URL = 'http://localhost:3000'
BACKEND_BASE_URL = 'https://sc-backend-staging.herokuapp.com'
class ProductionConfig(BaseConfig):
DEBUG = False
MODE = 'prod'
DATABASE_NAME = 'production-db'
FRONTEND_BASE_URL = 'https://www.sproul.club'
BACKEND_BASE_URL = 'https://sc-backend-prod.herokuapp.com'
# Set the respective configuration class to load based on 'MODE'
"""
README: If you want to add a new configuration environment, add a new if statement clause to ensure that
CurrentConfig will have the right configuration variables loaded.
"""
if MODE == 'local':
CurrentConfig = LocalConfig
elif MODE == 'dev':
CurrentConfig = DevelopmentConfig
elif MODE == 'staging':
CurrentConfig = StagingConfig
elif MODE == 'prod':
CurrentConfig = ProductionConfig
else:
raise Exception(f'Invalid operating mode: "{MODE}"')