-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
139 lines (103 loc) · 4.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
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
from os import environ
from os.path import join, dirname
# Third party imports
from flask_compress import Compress
class Config:
"""
Common configurations
"""
# private variable used by Flask to secure/encrypt session cookies
SECRET_KEY = environ['SECRET_KEY']
# get the root url and concantenate it with the client secrets file
OIDC_CLIENT_SECRETS = join(dirname(__file__), "client_secrets.json")
# test out login and registration in development without using SSL
OIDC_COOKIE_SECURE = False
# URL to handle user login
OIDC_CALLBACK_ROUTE = "/oidc/callback"
# what user data to request on log in
OIDC_SCOPES = ["openid", "email", "profile"]
OIDC_ID_TOKEN_COOKIE_NAME = "oidc_token"
TESTING = False
DEBUG = False
CSRF_ENABLED = True # protect against CSRF attacks
SQLALCHEMY_TRACK_MODIFICATIONS = False
# Gzip compression allows to reduce the size of the response by 70-90%
# Flask-Compress compresses the application’s response with gzip
COMPRESS_MIMETYPES = ['text/html', 'text/css', 'text/xml',
'application/json', 'application/javascript']
COMPRESS_LEVEL = 6
COMPRESS_MIN_SIZE = 500
CACHE_TYPE = 'simple' # compare with memcached, redis, filesystem, etc.
# 'datastore' does not require any additional configuration.
DATA_BACKEND = 'datastore' # alternatively 'cloudsql' or 'mongodb'
# Google Cloud Project ID
PROJECT_ID = environ['PROJECT_ID']
# CloudSQL & SQLAlchemy configuration
CLOUDSQL_USER = environ['CLOUDSQL_USER']
CLOUDSQL_PASSWORD = environ['CLOUDSQL_PASSWORD']
CLOUDSQL_DATABASE = environ['CLOUDSQL_DATABASE']
DB_HOST_IP = environ['DB_HOST_IP']
DB_HOST_PORT = environ['DB_HOST_PORT']
# The CloudSQL proxy is used locally to connect to the cloudsql instance.
# To start the proxy, use:
#
# $ cloud_sql_proxy -instances=your-connection-name=tcp:3306
#
# Port 3306 is the standard MySQL port. If you need to use a different port,
# change the 3306 to a different port number.
# Alternatively, use a local MySQL instance for testing.
LOCAL_SQLALCHEMY_DATABASE_URI = (
'postgresql://{}:{}@127.0.0.1:5432/{}').format(CLOUDSQL_USER, CLOUDSQL_PASSWORD, CLOUDSQL_DATABASE)
# When running on App Engine, a unix socket is used to connect to the cloudsql instance.
LIVE_SQLALCHEMY_DATABASE_URI = ('postgresql://{}:{}@{}:{}/{}').format(
CLOUDSQL_USER, CLOUDSQL_PASSWORD, DB_HOST_IP, DB_HOST_PORT, CLOUDSQL_DATABASE)
SQLALCHEMY_DATABASE_URI = LIVE_SQLALCHEMY_DATABASE_URI if environ.get(
'FLASK_ENV') == 'production' else LOCAL_SQLALCHEMY_DATABASE_URI
# Mongo configuration
# If using mongolab, the connection URI is available from the mongolab control
# panel. If self-hosting on compute engine, replace the values below.
# MONGO_URI = 'mongodb://user:password@host:27017/database'
# Google Cloud Storage and upload settings.
# You can adjust the max content length and allow extensions settings to allow
# larger or more varied file types if desired.
CLOUD_STORAGE_BUCKET = environ['CLOUD_STORAGE_BUCKET']
MAX_CONTENT_LENGTH = 8 * 1024 * 1024
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
# OAuth2 configuration.
# This can be generated from the Google Developers Console at
# https://console.developers.google.com/project/_/apiui/credential.
#
# * http://localhost:8080/oauth2callback
# * https://flask-okta-1.appspot.com/oauth2callback.
#
# If you receive a invalid redirect URI error review you settings to ensure
# that the current URI is allowed.
# GOOGLE_OAUTH2_CLIENT_ID = \
# 'your-client-id'
# GOOGLE_OAUTH2_CLIENT_SECRET = 'your-client-secret'
class ProductionConfig(Config):
"""
Production configurations
"""
DEBUG = False
TESTING = False
class DevelopmentConfig(Config):
"""
Development configurations
"""
DEBUG = True
SQLALCHEMY_ECHO = True
class TestingConfig(Config):
"""
Testing configurations
"""
TESTING = True
app_config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig
}
def configure_app(app):
"""Multiple app configurations"""
# Configure Compressing
Compress(app)