-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
executable file
·35 lines (28 loc) · 1.28 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
#!/usr/bin/env python3
"""Configuration module"""
from os import getenv
from dotenv import load_dotenv
from urllib.parse import quote
# Load environment variables from .env file
load_dotenv()
# MongoDB configuration
MONGODB_ADMIN = quote(getenv("MONGODB_ADMIN"), safe="")
MONGODB_ADMIN_PASSWORD = quote(getenv("MONGODB_ADMIN_PASSWORD"), safe="")
MONGODB_USER = quote(getenv("MONGODB_USER"), safe="")
MONGODB_PASSWORD = quote(getenv("MONGODB_PASSWORD"), safe="")
MONGODB_HOST = getenv("MONGODB_HOST")
MONGODB_PORT = getenv("MONGODB_PORT")
MONGODB_DATABASE = getenv("MONGODB_DATABASE")
# Get collections from environment variable and split them
DB_COLLECTIONS = getenv("DB_COLLECTIONS", "").split(",")
DB_COLLECTIONS = [collection.strip() for collection in DB_COLLECTIONS]
# URL encode the username and password
encoded_user = quote(MONGODB_USER, safe="")
encoded_password = quote(MONGODB_PASSWORD, safe="")
# Create database URI
MONGODB_URI = f"mongodb://{MONGODB_USER}:{MONGODB_PASSWORD}@{MONGODB_HOST}:{MONGODB_PORT}/{MONGODB_DATABASE}?authSource={MONGODB_DATABASE}"
# Flask configuration
SECRET_KEY = getenv("SECRET_KEY", "\x93J\xa7\xd2e\x0co\xfb\x07"\x9cg\xd6\xd43s")
# Get Flask host IP and port number
WORKLOG_HOST = getenv("WORKLOG_HOST", "0.0.0.0")
WORKLOG_PORT = getenv("WORKLOG_PORT", "5000")