-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.py
92 lines (69 loc) · 3.46 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
import datetime
import os
import logging
import sys
import urllib.parse
PORT = os.getenv('PORT', 5000)
DEBUG = os.getenv('DEBUG', 'false').lower() in ('true', '1', 't')
DOWNLOAD_MISSING_VIDEOS = os.getenv('DOWNLOAD_MISSING_VIDEOS', 'false').lower() in ('true', '1', 't')
# Where to store uploaded/downloaded files
# DATA_DIRECTORY = os.getenv('DATA_DIRECTORY', '.')
if DEBUG:
logging.basicConfig(format='%(name)s\t%(asctime)-15s %(message)s', level=logging.DEBUG)
else:
logging.basicConfig(format='%(name)s\t%(asctime)-15s %(message)s', level=logging.INFO)
def print_sqlite_warning():
logging.warning('''DEV ONLY: Using SQLITE for persistent storage...
Please configure the following environment variables to enable persistent storage in production:
- USE_SQLITE=0
- POSTGRES_HOST=<postgres hostname>
- POSTGRES_PORT=<postgres port number>
- POSTGRES_USER=<postgres username>
- POSTGRES_PASS=<postgres password>
- POSTGRES_DB=<postgres database>
''')
def get_redacted_rmq_uri():
prefix = RABBITMQ_URI.split('@', 1)[0]
return RABBITMQ_URI.replace(prefix, 'amqp://********:********')
def get_redacted_db_uri():
return SQLALCHEMY_DATABASE_URI.replace(POSTGRES_USER, '********', 1).replace(POSTGRES_PASS, '********', 1)
# Database connection
basedir = os.path.abspath(os.path.dirname(__file__))
SQLITE_PATH = '%s/db.sqlite' % basedir
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + SQLITE_PATH
USE_SQLITE = os.getenv('USE_SQLITE', 'false').lower() in ('true', '1', 't')
POSTGRES_HOST = os.getenv('POSTGRES_HOST', 'localhost')
POSTGRES_PORT = os.getenv('POSTGRES_PORT', 5432)
POSTGRES_USER = os.getenv('POSTGRES_USER', '')
POSTGRES_PASS = os.getenv('POSTGRES_PASS', '')
POSTGRES_DB = os.getenv('POSTGRES_DB', 'ct2019db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
PROPAGATE_EXCEPTIONS = True
# AMQP Connection
#ADMIN_USER_ID = urllib.parse.quote(os.getenv('ADMIN_USER_ID', 'guest'), safe='') # default credentials
#ADMIN_PASSWORD = urllib.parse.quote(os.getenv('ADMIN_PASSWORD', 'guest'), safe='')
#RMQ_HOST = urllib.parse.quote(os.getenv('RABBITMQ_HOST', 'localhost'), safe='')
#RMQ_PORT = int(os.getenv('RABBITMQ_PORT', 5672)) # default port is 5672
#RMQ_PROTOCOL = os.getenv('RABBITMQ_PROTOCOL', 'amqp') # either amqp or amqps
#RMQ_VHOST = urllib.parse.quote(os.getenv('RABBITMQ_VHOST', '/'), safe='')
# Build up RABBITMQ from other vars or override directly
#RABBITMQ_URI = os.getenv('RABBITMQ_URI', f"amqp://{ADMIN_USER_ID}:{ADMIN_PASSWORD}@{RMQ_HOST}:{RMQ_PORT}/{RMQ_VHOST}")
RABBITMQ_URI = os.getenv('RABBITMQ_URI', "amqp://guest:guest@localhost:5672/%2f")
RABBITMQ_EXCHANGE = os.getenv('RABBITMQ_EXCHANGE', '')
# Listener only (emitter can publish to any queue)
RABBITMQ_QUEUENAME = os.getenv('RABBITMQ_QUEUENAME', '')
# JWT Auth
JWT_SECRET = os.getenv('JWT_SECRET', 'thisisnotverysecret')
JWT_ALGORITHM = os.getenv('JWT_ALGORITHM', 'HS256')
JWT_EXP_DELTA_MINS = os.getenv('JWT_EXP_DELTA_MINS', 300)
JWT_TIMEOUT = datetime.timedelta(minutes=JWT_EXP_DELTA_MINS)
#SWAGGER_URL = os.getenv('SWAGGER_URL', 'openapi/sample.yaml')
SWAGGER_URL = os.getenv('SWAGGER_URL', basedir + '/openapi/swagger.json')
if RABBITMQ_URI is None or RABBITMQ_URI == '':
logging.error("RABBITMQ_URI must be set")
sys.exit(1)
# NOTE: RABBITMQ_EXCHANGE is optional
if RABBITMQ_EXCHANGE is None or RABBITMQ_EXCHANGE == '':
logging.warning("Using RabbitMQ default exchange")
else:
logging.warning("Using RabbitMQ exchange: %s" % RABBITMQ_EXCHANGE)