add build settings

This commit is contained in:
Egor Svitin
2023-01-30 10:45:26 +03:00
parent aaf98fc65e
commit e50cc762cf
5 changed files with 67 additions and 19 deletions

View File

@@ -4,24 +4,19 @@ import requests
from dynaconf import Dynaconf, Validator
from mongoengine import connect
from configs.configs import CONFIGS
class AppConfig:
def __init__(self):
self.config = Dynaconf(settings_files=[
"/app/configs/main.json",
"/app/configs/application_credentials.json",
"/app/configs/db.json",
"/app/configs/sources.json"
])
self.config.validators.register(
Validator('db', 'db.host', 'db.database', must_exist=True),
)
self.config.validators.validate()
creds = self.get_db_config()
connect(
db=creds.database,
host="mongodb://{host}:27017/{database}".format(host=creds.host, database=creds.database)
db=CONFIGS['db']['name'],
host="mongodb://{host}:27017/{database}".format(host=CONFIGS['db']['host'], database=CONFIGS['db']['name'])
)
def get_bulk_insert_limit(self):
@@ -30,12 +25,6 @@ class AppConfig:
else:
return self.config.bulk_limit
def get_db_config(self):
return self.config.db
def get_main_app_creds(self):
return self.config.application_credentials
def get_source_by_name(self, name: str):
if name not in self.config.sources:
raise ValueError(f'"{name}" source not exists!')
@@ -45,12 +34,11 @@ class AppConfig:
return self.config.sources.keys()
def update_sources(self):
creds = self.get_main_app_creds()
headers = {
'Content-type': 'application/json',
'Authorization': 'Bearer {key}'.format(key=creds.api_key)
'Authorization': 'Bearer {key}'.format(key=CONFIGS['application_credentials']['api_key'])
}
r = requests.get(creds.api_url + "sources", headers=headers)
r = requests.get(CONFIGS['application_credentials']['api_url'] + "sources", headers=headers)
if r.status_code != 200:
raise Exception('Bad app response')

12
configs/configs.py Normal file
View File

@@ -0,0 +1,12 @@
import os
CONFIGS = {
'db' : {
'name' : os.environ['DB_NAME'],
'host' : os.environ['DB_HOST']
},
'application_credentials' : {
'api_url' : os.environ['API_URL'],
'api_key' : os.environ['API_KEY']
}
}