-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.py
executable file
·148 lines (120 loc) · 5.45 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""This is where we defined the Config files, which are used for initiating the
application with specific settings such as logger configurations or different
database setups."""
from app.utils.logging import file_logger, client_logger
from decouple import config as env_conf
import logging
# To use this config, set up a local Postgres server on 127.0.0.1 port 5432, make a database
# called "data", and create a user named "postgres" with no password and all privileges.
class LocalPSQLConfig:
@property
def SQLALCHEMY_DATABASE_URI(self):
DB_USER = 'postgres'
DB_PASSWORD = ''
DB_HOST = '127.0.0.1'
DB_PORT = '5432'
DB_NAME = 'data'
return 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_RECORD_QUERIES = True
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
# by default, access tokens do not expire
JWT_ACCESS_TOKEN_EXPIRES = env_conf('JWT_ACCESS_TOKEN_EXPIRES', cast=int, default=False)
API_WEBHOOK_URL = env_conf('API_WEBHOOK_URL', cast=str, default='')
SLACK_API_TOKEN = env_conf('SLACK_API_TOKEN', cast=str, default='')
SLACK_CHANNEL = env_conf('SLACK_CHANNEL', cast=str, default='')
@staticmethod
def init_app(app):
# The default Flask logger level is set at ERROR, so if you want to see
# INFO level or DEBUG level logs, you need to lower the main loggers
# level first.
app.logger.setLevel(logging.DEBUG)
app.logger.handlers.clear()
app.logger.addHandler(file_logger)
app.logger.addHandler(client_logger)
class Production:
@property
def SQLALCHEMY_DATABASE_URI(self):
DB_USER = env_conf('DATABASE_USER')
DB_PASSWORD = env_conf('DATABASE_PASS')
DB_HOST = env_conf('DATABASE_HOST')
DB_PORT = env_conf('DATABASE_PORT')
DB_NAME = env_conf('DATABASE_NAME')
return 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_RECORD_QUERIES = True
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
# by default, access tokens do not expire
JWT_ACCESS_TOKEN_EXPIRES = env_conf('JWT_ACCESS_TOKEN_EXPIRES', cast=int, default=False)
API_WEBHOOK_URL = env_conf('API_WEBHOOK_URL', cast=str, default='')
SLACK_API_TOKEN = env_conf('SLACK_API_TOKEN', cast=str, default='')
SLACK_CHANNEL = env_conf('SLACK_CHANNEL', cast=str, default='')
@staticmethod
def init_app(app):
# The default Flask logger level is set at ERROR, so if you want to see
# INFO level or DEBUG level logs, you need to lower the main loggers
# level first.
app.logger.setLevel(logging.DEBUG)
app.logger.handlers.clear()
app.logger.addHandler(file_logger)
app.logger.addHandler(client_logger)
class Testing:
"""Configuration for running the test suite"""
TESTING = True
DEBUG = True
@property
def SQLALCHEMY_DATABASE_URI(self):
DB_USER = env_conf('DATABASE_USER')
DB_PASSWORD = env_conf('DATABASE_PASS')
DB_HOST = env_conf('DATABASE_HOST')
DB_PORT = env_conf('DATABASE_PORT')
DB_NAME = env_conf('DATABASE_NAME')
return 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_RECORD_QUERIES = True
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
# by default, access tokens do not expire
JWT_ACCESS_TOKEN_EXPIRES = env_conf('JWT_ACCESS_TOKEN_EXPIRES', cast=int, default=False)
API_WEBHOOK_URL = env_conf('API_WEBHOOK_URL', cast=str, default='')
SLACK_API_TOKEN = env_conf('SLACK_API_TOKEN', cast=str, default='')
SLACK_CHANNEL = env_conf('SLACK_CHANNEL', cast=str, default='')
@staticmethod
def init_app(app):
# The default Flask logger level is set at ERROR, so if you want to see
# INFO level or DEBUG level logs, you need to lower the main loggers
# level first.
app.logger.setLevel(logging.DEBUG)
app.logger.handlers.clear()
app.logger.addHandler(file_logger)
app.logger.addHandler(client_logger)
class Develop:
"""Development config geared towards docker."""
@property
def SQLALCHEMY_DATABASE_URI(self):
DB_USER = "deploy"
DB_PASSWORD = "docker"
DB_HOST = "db"
DB_PORT = "5432"
DB_NAME = "stories"
return 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_RECORD_QUERIES = True
API_WEBHOOK_URL = env_conf('API_WEBHOOK_URL', cast=str, default='')
SLACK_API_TOKEN = env_conf('SLACK_API_TOKEN', cast=str, default='')
SLACK_CHANNEL = env_conf('SLACK_CHANNEL', cast=str, default='')
# DEBUG = True
# API configurations
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
# by default, access tokens do not expire
JWT_ACCESS_TOKEN_EXPIRES = env_conf('JWT_ACCESS_TOKEN_EXPIRES', cast=int, default=False)
@staticmethod
def init_app(app):
"""Initiates application."""
app.logger.setLevel(logging.DEBUG)
app.logger.handlers.clear()
app.logger.addHandler(client_logger)
app.logger.addHandler(file_logger)