-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
153 lines (124 loc) · 5.27 KB
/
config.py
File metadata and controls
153 lines (124 loc) · 5.27 KB
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
# -*- coding: utf-8 -*-
import json
import logging
import os
from datetime import timedelta
from urllib.parse import quote_plus
from application.common import logger, constants
class DefaultConfig:
######################################################################
# Configurable Settings
# These must still be present here but user may change later
######################################################################
# App name and secret
APP_DOMAIN = "agentsofthesystem.com"
APP_NAME = "TheArchitect"
APP_WEBSITE = f"www.{APP_DOMAIN}"
APP_PRETTY_NAME = "Agents of the System"
DEPLOYMENT_TYPE = "docker_compose" # also supports kubernetes
# Top-level App Controls
APP_ENABLE_PAYMENTS = False
APP_ENABLE_EMAIL = False
APP_ENABLE_BETA = False
# AWS Settings
AWS_REGION = "us-east-1"
AWS_ACCESS_KEY_ID = None
AWS_SECRET_ACCESS_KEY = None
# Email Settings
DEFAULT_MAIL_SENDER = f"architect@{APP_DOMAIN}"
# Celery Settings
CELERY_BROKER = "redis://redis-service:6379"
CELERY_BACKEND = "redis://redis-service:6379"
CELERY_BACKED_BY = "REDIS"
CELERY_SQS_PREDEFINED_QUEUE = None
# Log/Verbosity Settings
OPERATOR_CLIENT_VERBOSE = False
# Monitor Settings
MONITOR_TEST_MODE = False
######################################################################
# Non - Re-Configurable Settings
######################################################################
# Flask specific configs
DEBUG = False
ENV = "production"
TESTING = False
FLASK_RUN_HOST = "0.0.0.0"
FLASK_RUN_PORT = "3000"
SECRET_KEY = "CHANGE_ME"
WTF_CSRF_ENABLED = True
PERMANENT_SESSION_LIFETIME = timedelta(hours=constants.DEFAULT_SESSION_HOURS)
IS_SEEDED = False
LOG_LEVEL = logging.DEBUG
# SQL Database Settings
SQL_DATABASE_USER = "admin"
SQL_DATABASE_PASS = "REPLACEME"
# SQL_DATABASE_SERVER = "mariadb-service"
SQL_DATABASE_SERVER = "localhost"
SQL_DATABASE_PORT = "3306"
SQL_DATABASE_NAME = "app"
SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{SQL_DATABASE_USER}:{SQL_DATABASE_PASS}@{SQL_DATABASE_SERVER}:{SQL_DATABASE_PORT}/{SQL_DATABASE_NAME}" # noqa: E501
SQL_DEPLOY_SECRET = None
# Stripe Payment configs
# This is a test key. Okay to expose.
STRIPE_PUBLISHABLE_KEY = "pk_test1"
STRIPE_SECRET_KEY = "pk_test2"
STRIPE_PRICE_ID_1 = "price_id1"
STRIPE_WEBHOOK_SECRET = "whsec_abc123"
# Google login Configuration
GOOGLE_SIGNUP_ENABLED = False
GOOGLE_CLIENT_ID = "REPLACEME"
GOOGLE_CLIENT_SECRET = "REPLACEME"
GOOGLE_DISCOVERY_URL = "https://accounts.google.com/.well-known/openid-configuration"
OAUTHLIB_INSECURE_TRANSPORT = "" # Set to '1' to disable HTTPS requirement for testing.
# Admin Stuff
ADMIN_USER = "Global Admin"
ADMIN_PASSWORD = "password" # Default password
DEFAULT_ADMIN_EMAIL = f"admin@{APP_DOMAIN}"
FLASK_ADMIN_SWATCH = "cosmo" # See https://bootswatch.com/3/ for swatches
def __init__(self, deploy_type):
configuration_options = [el.value for el in constants._DeployTypes]
if deploy_type not in configuration_options:
logger.info(
f"Configuration: {deploy_type} is not a valid configuration type, "
f"which are: {configuration_options}"
)
raise RuntimeError
self.DEPLOYMENT_TYPE = deploy_type
@classmethod
def get(cls, attribute, default_value=None):
if hasattr(cls, attribute):
return getattr(cls, attribute)
else:
return default_value
@classmethod
def obtain_environment_variables(cls):
for var in cls.__dict__.keys():
if var[:1] != "_" and var != "obtain_environment_variables":
if var in os.environ:
value = os.environ[var].lower()
if value == "true" or value == "True" or value == "TRUE":
setattr(cls, var, True)
elif value == "false" or value == "False" or value == "FALSE":
setattr(cls, var, False)
else:
setattr(cls, var, os.environ[var])
cls.update_derived_variables()
@classmethod
def __str__(cls):
print_str = ""
for var in cls.__dict__.keys():
if var[:1] != "_" and var != "obtain_environment_variables":
print_str += f"VAR: {var} set to: {getattr(cls,var)}\n"
return print_str
@classmethod
def update_derived_variables(cls):
"""Update Computed Configuration Variables."""
if cls.SQL_DEPLOY_SECRET:
logger.info("Configuration Alert!: Overriding DB URI with deploy secret!")
unpack_string = json.loads(cls.SQL_DEPLOY_SECRET)
cls.SQL_DATABASE_USER = unpack_string["username"]
cls.SQL_DATABASE_PASS = unpack_string["password"]
# Update the password string to escape special characters.
password_string_final = quote_plus(cls.SQL_DATABASE_PASS)
cls.SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{cls.SQL_DATABASE_USER}:{password_string_final}@{cls.SQL_DATABASE_SERVER}:{cls.SQL_DATABASE_PORT}/{cls.SQL_DATABASE_NAME}" # noqa: E501
cls.DEFAULT_MAIL_SENDER = f"architect@{cls.APP_DOMAIN}"