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

5
.env.sample Normal file
View File

@@ -0,0 +1,5 @@
DB_NAME=@lcDbName@
DB_HOST=@lcDbHost@
API_URL=@lcApiUrl@
API_KEY=@lcApiKey@

41
build/build.xml Normal file
View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="LiveCarta MetaData project" default="full-build">
<target name="build"
depends="copy, replace, archive"
description="Performs static analysis, runs the tests, and generates project documentation"/>
<target name="replace"
unless="replace.done"
description="Replace placeholders in config files" >
<replace file="../.env" token="@lcDbName@" value="${lcDbName}"/>
<replace file="../.env" token="@lcDbHost@" value="${lcDbHost}"/>
<replace file="../.env" token="@lcApiUrl@" value="${lcApiUrl}"/>
<replace file="../.env" token="@lcApiKey@" value="${lcApiKey}"/>
<property name="replace.done" value="true"/>
</target>
<target name="copy"
unless="copy.done"
description="Replace placeholders in config files" >
<copy file="../.env.sample" tofile="../.env"/>
<property name="copy.done" value="true"/>
</target>
<target name="archive">
<tar compression="gzip" destfile="lc_meta.tar.gz" longfile="posix">
<tarfileset dir="${basedir}/..">
<include name="*/**" />
<exclude name="build/**" />
</tarfileset>
</tar>
</target>
</project>

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']
}
}

View File

@@ -7,10 +7,12 @@ from pydantic import BaseModel, Extra
from components.SenderComponent import SenderComponent
from configs.config import config
from configs.configs import CONFIGS
from models.MetaData import MetaData
from sources.source_types.AbstractSource import AbstractSource
class BaseSource(BaseModel):
source_name: str
source: dict
@@ -24,7 +26,7 @@ class BaseSource(BaseModel):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.senderComponent = SenderComponent(**config.get_main_app_creds())
self.senderComponent = SenderComponent(api_url=CONFIGS['application_credentials']['api_url'], api_key=CONFIGS['application_credentials']['api_key'])
def get_source_object(config):
class_name = config.type.capitalize() + "Source"