-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
113 lines (88 loc) · 2.71 KB
/
Copy pathconfig.py
File metadata and controls
113 lines (88 loc) · 2.71 KB
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
import os
from functools import lru_cache
from pydantic import BaseSettings
from flask import Flask
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_ENV = os.environ.get("APP_ENV", "development")
class BaseConfig(BaseSettings):
"""Base configuration."""
ENV: str = "base"
APP_NAME: str = "Simple Flask App"
SECRET_KEY: str
SQLALCHEMY_TRACK_MODIFICATIONS: bool = False
WTF_CSRF_ENABLED: bool = False
# Mail config
MAIL_SERVER: str = ""
MAIL_PORT: int = 465
MAIL_USE_TLS: bool = False
MAIL_USE_SSL: bool = True
MAIL_USERNAME: str = ""
MAIL_PASSWORD: str = ""
MAIL_DEFAULT_SENDER: str = ""
# Pagination
DEFAULT_PAGE_SIZE: int
PAGE_LINKS_NUMBER: int
# AWS
AWS_BUCKET_NAME: str
AWS_ACCESS_KEY: str
AWS_SECRET_ACCESS_KEY: str
AWS_DOMAIN: str
# GOOGLE
GOOGLE_SERVICE_ACCOUNT_PATH: str = ""
# Count of questions
QUESTIONS_COUNT = 25
@staticmethod
def configure(app: Flask):
# Implement this method to do further configuration on your app.
pass
class Config:
# `.env` takes priority over `project.env`
env_file = "project.env", ".env"
class DevelopmentConfig(BaseConfig):
"""Development configuration."""
DEBUG: bool = True
ALCHEMICAL_DATABASE_URL: str = "sqlite:///" + os.path.join(
BASE_DIR, "database-dev.sqlite3"
)
class Config:
fields = {
"ALCHEMICAL_DATABASE_URL": {
"env": "DEVEL_DATABASE_URL",
}
}
class TestingConfig(BaseConfig):
"""Testing configuration."""
TESTING: bool = True
PRESERVE_CONTEXT_ON_EXCEPTION: bool = False
ALCHEMICAL_DATABASE_URL: str = "sqlite:///" + os.path.join(
BASE_DIR, "database-test.sqlite3"
)
class Config:
fields = {
"ALCHEMICAL_DATABASE_URL": {
"env": "TEST_DATABASE_URL",
}
}
class ProductionConfig(BaseConfig):
"""Production configuration."""
# using URI instead of URL just for production
ALCHEMICAL_DATABASE_URL: str = os.environ.get(
"DATABASE_URI", "sqlite:///" + os.path.join(BASE_DIR, "database.sqlite3")
)
WTF_CSRF_ENABLED = True
class Config:
fields = {
"ALCHEMICAL_DATABASE_URL": {
"env": "DATABASE_URI",
}
}
@lru_cache
def config(name=APP_ENV) -> DevelopmentConfig | TestingConfig | ProductionConfig:
CONF_MAP = dict(
development=DevelopmentConfig(), # type: ignore
testing=TestingConfig(), # type: ignore
production=ProductionConfig(), # type: ignore
)
configuration = CONF_MAP[name]
configuration.ENV = name
return configuration # type: ignore