Skip to content

Commit ea4577f

Browse files
committed
Define Config class
1 parent cabe864 commit ea4577f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/config.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import os
1+
import os, json
22
from dotenv import load_dotenv
3+
from urllib import parse
34
load_dotenv()
4-
5+
"""
56
class Development(object):
6-
"""
7-
Development environment configuration
8-
"""
97
DEBUG = True
108
TESTING = False
119
SECRET_KEY = os.environ.get("SECRET_KEY") or "you-will-never-guess"
@@ -14,9 +12,6 @@ class Development(object):
1412
OIDC_CLIENT_SECRETS = "manifests/oidc-secret.json"
1513
1614
class Production(object):
17-
"""
18-
Production environment configuration
19-
"""
2015
DEBUG = False
2116
TESTING = False
2217
SQLALCHEMY_DATABASE_URI = f"postgresql://{os.environ.get('POSTGRESQL_USER')}:{os.environ.get('POSTGRESQL_PASSWORD')}@svc-postgresql/library"
@@ -27,3 +22,14 @@ class Production(object):
2722
"development": Development,
2823
"production": Production,
2924
}
25+
"""
26+
class Config:
27+
DEBUG = False
28+
TESTING = False
29+
with open('/etc/pythonrestapi_config.json', 'r') as f:
30+
config = json.load(f)
31+
SECRET_KEY = config["SECRET_KEY"] or "you-will-never-guess"
32+
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{config['DB_HOST']}/library"
33+
POSTGRESQL_DATABASE_URI = f"postgresql://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{config['DB_HOST']}/library"
34+
JWT_SECRET_KEY = config["JWT_SECRET_KEY"]
35+
OIDC_CLIENT_SECRETS = config["OIDC_CLIENT_SECRETS"]

src/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ def create_app() -> Quart:
2727
# App initialization
2828
app = Quart(__name__, template_folder='view/templates', static_url_path='', static_folder='view/static')
2929
app.config.from_file("/etc/pythonrestapi_config.json", json.load)
30-
if "SQLALCHEMY_DATABASE_URI" not in app.config:
31-
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql+psycopg://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
32-
app.config["POSTGRESQL_DATABASE_URI"] = f"postgresql://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
30+
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql+psycopg://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
31+
app.config["POSTGRESQL_DATABASE_URI"] = f"postgresql://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
3332
app.register_blueprint(home_blueprint, url_prefix="/")
3433
app.register_blueprint(fibonacci_blueprint, url_prefix="/fibonacci")
3534
app.register_blueprint(auth_blueprint, url_prefix="/auth")

0 commit comments

Comments
 (0)