-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
88 lines (57 loc) · 2.29 KB
/
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
#!/usr/bin/env python3
# Imports
import os
from dotenv import load_dotenv
import pymysql
from datetime import timedelta
# Load environment variables from the .env file
load_dotenv()
# Define the absolute path for the upload folder
UPLOAD_FOLDER = "static/img"
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif"}
def allowed_file(filename):
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
# Base class configuration for database
class Config:
"""
Base Configuration class
"""
SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{os.getenv('DATABASE_USERNAME')}:{os.getenv('DATABASE_PASSWORD')}@{os.getenv('DATABASE_HOST')}/{os.getenv('DATABASE')}"
# SQLALCHEMY_DATABASE_URI = f"postgresql://{os.getenv('DATABASE_USERNAME')}:{os.getenv('DATABASE_PASSWORD')}@{os.getenv('DATABASE_HOST')}/{os.getenv('DATABASE')}"
# Disable track modifictions to avoid warning
SQLALCHEMY_TRACK_MODIFICATIONS = False
# ssl_mode="VERIFY_IDENTITY",
# ssl={ "ca": "" }
# Define SSL options in engine options
SQLALCHEMY_ENGINE_OPTIONS = {"connect_args": {"ssl": {"rejectUnauthorized": True}}}
# Flask-Caching configuration
CACHE_TYPE = "simple"
CACHE_DEFAULT_TIMEOUT = 300
# JWT Configuration
JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'your_default_secret_key')
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=2)
class DevelopmentConfig(Config):
"""Development configuration class"""
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
class TestingConfig(Config):
"""Testing configuration class"""
TESTING = True
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
DEBUG = True
class ProductionConfig(Config):
"""Production configuration class"""
DEBUG = False
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
# SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
# Mapping config names to their respective classes
config_map = {
"development": DevelopmentConfig,
"testing": TestingConfig,
"production": ProductionConfig,
}
# Set the active configuration based on an environment variable
active_env = os.getenv("FLASK_ENV", "testing")
config = config_map[active_env]