-
Notifications
You must be signed in to change notification settings - Fork 5
/
settings.sample.py
228 lines (173 loc) · 5.69 KB
/
settings.sample.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 30 18:06:12 2020
@author: Hrishikesh Terdalkar
"""
###############################################################################
import os
from configuration import Configuration
###############################################################################
DEBUG = False
APP_NAME = "MyFlaskWebApp"
APP_TITLE = "MyHeader"
APP_YEAR = "2020"
APP_AUTHOR = "Hrishikesh Terdalkar"
APP_DIR = os.path.dirname(os.path.realpath(__file__))
LOG_FILE = os.path.join(APP_DIR, "flask.log")
# DB_DIR is used for specifying directory containing SQLite3 database
DB_DIR = "db"
DATA_DIR = "data"
# --------------------------------------------------------------------------- #
APPLICATION_CONFIG = {}
# --------------------------------------------------------------------------- #
# Security
# Generate a nice key using secrets.token_urlsafe()
SECRET_KEY = os.environ.get("SECRET_KEY", "Secret Key for Flask Webapp")
# Bcrypt is set as default SECURITY_PASSWORD_HASH, which requires a salt
# Generate a good salt using: secrets.SystemRandom().getrandbits(128)
SECURITY_PASSWORD_SALT = os.environ.get(
"SECURITY_PASSWORD_SALT", "301721846670564486948773381866193921949"
)
# --------------------------------------------------------------------------- #
# First User
ADMIN_USER = os.environ.get("ADMIN_USER", "admin")
ADMIN_PASS = os.environ.get("ADMIN_PASS", "admin")
ADMIN_MAIL = os.environ.get("ADMIN_MAIL", "admin@127.0.0.1")
# --------------------------------------------------------------------------- #
# PythonAnywhere
PA_DOMAIN = os.environ.get("PA_DOMAIN", "")
PA_USERNAME = os.environ.get("PA_USERNAME", "")
PA_TOKEN = os.environ.get("PA_TOKEN", "")
# --------------------------------------------------------------------------- #
# SMTP Config
SMTP_ENABLED = False
SMTP_SENDER_NAME = os.environ.get("SMTP_SENDER_NAME", "")
SMTP_SERVER = os.environ.get("SMTP_SERVER", "")
SMTP_USER = os.environ.get("SMTP_USER", "")
SMTP_PASS = os.environ.get("SMTP_PASS", "")
SMTP_PORT = os.environ.get("SMTP_PORT", "587")
SMTP_USE_SSL = os.environ.get("SMTP_USE_SSL", "0")
SMTP_USE_TLS = os.environ.get("SMTP_USE_TLS", "1")
# --------------------------------------------------------------------------- #
# MongoDB Config
MONGO_HOST = os.environ.get("MONGO_HOST", "")
MONGO_USER = os.environ.get("MONGO_USER", "")
MONGO_PASS = os.environ.get("MONGO_PASS", "")
MONGO_DATABASE = os.environ.get("MONGO_DATABASE", "")
MONGO_OPTIONS = os.environ.get("MONGO_OPTIONS", "")
# --------------------------------------------------------------------------- #
# MySQL Config
MYSQL_USER = os.environ.get("MYSQL_USER", "")
MYSQL_PASS = os.environ.get("MYSQL_PASS", "")
MYSQL_HOST = os.environ.get("MYSQL_HOST", "")
MYSQL_DATABASE = os.environ.get("MYSQL_DATABASE", "")
# --------------------------------------------------------------------------- #
# SQLite Config
SQLITE_DATABASE = os.environ.get("SQLITE_DATABASE", "test.db")
# --------------------------------------------------------------------------- #
USE_MONGO = False
USE_MYSQL = False
USE_SQLITE = True
# --------------------------------------------------------------------------- #
# Role Definitions
ROLES = [
{
"name": "guest",
"level": 1,
"description": "Guest",
"permissions": []
},
{
"name": "member",
"level": 5,
"description": "Member",
"permissions": ["view_ucp"]
},
{
"name": "admin",
"level": 100,
"description": "Administrator",
"permissions": ["view_acp", "add_admin"]
},
{
"name": "owner",
"level": 1000,
"description": "Owner",
"permissions": ["view_acp", "remove_admin"]
},
]
###############################################################################
# DO NOT EDIT
app = Configuration()
app.name = APP_NAME
app.title = APP_TITLE
app.author = APP_AUTHOR
app.year = APP_YEAR
app.debug = DEBUG
# Config
app.config = APPLICATION_CONFIG
# Paths
app.dir = APP_DIR
app.db_dir = os.path.join(APP_DIR, DB_DIR)
app.data_dir = os.path.join(APP_DIR, DATA_DIR)
app.log_file = LOG_FILE
# Security
app.secret_key = SECRET_KEY
app.security_password_salt = SECURITY_PASSWORD_SALT
# Users
app.admin = {
"username": ADMIN_USER,
"email": ADMIN_MAIL,
"password": ADMIN_PASS
}
app.role_definitions = ROLES
# PythonAnywhere
# https://help.pythonanywhere.com/pages/API
app.pa_enabled = bool(PA_DOMAIN and PA_USERNAME and PA_TOKEN)
app.pa_api_actions = {
"info": f"/webapps/{PA_DOMAIN}/",
"reload": f"/webapps/{PA_DOMAIN}/reload/",
}
app.pa_api_url = f"https://www.pythonanywhere.com/api/v0/user/{PA_USERNAME}/"
app.pa_headers = {
"Authorization": f"Token {PA_TOKEN}"
}
# MongoDB
if USE_MONGO:
app.mongo = {
"host": (f"mongodb+srv://{MONGO_USER}:{MONGO_PASS}@{MONGO_HOST}/"
f"{MONGO_DATABASE}?retryWrites=true&w=majority"),
"connect": False,
"connectTimeoutMS": 30000,
"socketTimeoutMS": None,
"socketKeepAlive": True,
"maxPoolsize": 1
}
# SMTP
app.smtp_enabled = SMTP_ENABLED
app.smtp = {
"name": SMTP_SENDER_NAME,
"server": SMTP_SERVER,
"username": SMTP_USER,
"password": SMTP_PASS,
"port": int(SMTP_PORT),
"use_ssl": bool(int(SMTP_USE_SSL)),
"use_tls": bool(int(SMTP_USE_TLS))
}
# MySQL
if USE_MYSQL:
app.sqla = {
"database_uri": (
f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASS}"
f"@{MYSQL_HOST}/{MYSQL_DATABASE}"
)
}
# SQLite
if USE_SQLITE:
app.sqla = {
"database_uri": (
f"sqlite:///{os.path.join(app.db_dir, SQLITE_DATABASE)}"
)
}
###############################################################################