-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
65 lines (53 loc) · 1.91 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
import os
from logging.config import dictConfig
import connexion
from flask import request
from flask_sqlalchemy import SQLAlchemy
from env import FLASK_DEBUG
if FLASK_DEBUG:
dictConfig(
{
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s",
},
"simpleformatter": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
},
"handlers": {
"wsgi": {"class": "logging.StreamHandler", "formatter": "default"},
"custom_handler": {
"class": "logging.FileHandler",
"formatter": "simpleformatter",
"filename": "WARN.log",
"level": "WARN",
},
},
"root": {"level": "INFO", "handlers": ["wsgi", "custom_handler"]},
}
)
vuln_app = connexion.App(__name__, specification_dir='./openapi_specs')
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(vuln_app.root_path, 'database/database.db')
vuln_app.app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
vuln_app.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
if FLASK_DEBUG:
vuln_app.app.logger.info("Logging all request for FLASK_DEBUG!")
vuln_app.app.config['SECRET_KEY'] = 'random'
# start the db
db = SQLAlchemy(vuln_app.app)
vuln_app.add_api("openapi3.yml")
if FLASK_DEBUG:
@vuln_app.app.after_request
def log_after_request(response):
vuln_app.app.logger.info(
"path: %s | method: %s | headers: %s | body: %s | status: %s | size: %s",
request.path,
request.method,
str(request.headers),
str(request.data),
response.status,
response.content_length,
)
return response