forked from LiveCarta/LiveCartaMeta
add build settings
This commit is contained in:
5
.env.sample
Normal file
5
.env.sample
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DB_NAME=@lcDbName@
|
||||||
|
DB_HOST=@lcDbHost@
|
||||||
|
|
||||||
|
API_URL=@lcApiUrl@
|
||||||
|
API_KEY=@lcApiKey@
|
||||||
41
build/build.xml
Normal file
41
build/build.xml
Normal 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>
|
||||||
|
|
||||||
@@ -4,24 +4,19 @@ import requests
|
|||||||
from dynaconf import Dynaconf, Validator
|
from dynaconf import Dynaconf, Validator
|
||||||
from mongoengine import connect
|
from mongoengine import connect
|
||||||
|
|
||||||
|
from configs.configs import CONFIGS
|
||||||
|
|
||||||
|
|
||||||
class AppConfig:
|
class AppConfig:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = Dynaconf(settings_files=[
|
self.config = Dynaconf(settings_files=[
|
||||||
"/app/configs/main.json",
|
"/app/configs/main.json",
|
||||||
"/app/configs/application_credentials.json",
|
|
||||||
"/app/configs/db.json",
|
|
||||||
"/app/configs/sources.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(
|
connect(
|
||||||
db=creds.database,
|
db=CONFIGS['db']['name'],
|
||||||
host="mongodb://{host}:27017/{database}".format(host=creds.host, database=creds.database)
|
host="mongodb://{host}:27017/{database}".format(host=CONFIGS['db']['host'], database=CONFIGS['db']['name'])
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_bulk_insert_limit(self):
|
def get_bulk_insert_limit(self):
|
||||||
@@ -30,12 +25,6 @@ class AppConfig:
|
|||||||
else:
|
else:
|
||||||
return self.config.bulk_limit
|
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):
|
def get_source_by_name(self, name: str):
|
||||||
if name not in self.config.sources:
|
if name not in self.config.sources:
|
||||||
raise ValueError(f'"{name}" source not exists!')
|
raise ValueError(f'"{name}" source not exists!')
|
||||||
@@ -45,12 +34,11 @@ class AppConfig:
|
|||||||
return self.config.sources.keys()
|
return self.config.sources.keys()
|
||||||
|
|
||||||
def update_sources(self):
|
def update_sources(self):
|
||||||
creds = self.get_main_app_creds()
|
|
||||||
headers = {
|
headers = {
|
||||||
'Content-type': 'application/json',
|
'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:
|
if r.status_code != 200:
|
||||||
raise Exception('Bad app response')
|
raise Exception('Bad app response')
|
||||||
|
|
||||||
|
|||||||
12
configs/configs.py
Normal file
12
configs/configs.py
Normal 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']
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,12 @@ from pydantic import BaseModel, Extra
|
|||||||
|
|
||||||
from components.SenderComponent import SenderComponent
|
from components.SenderComponent import SenderComponent
|
||||||
from configs.config import config
|
from configs.config import config
|
||||||
|
from configs.configs import CONFIGS
|
||||||
from models.MetaData import MetaData
|
from models.MetaData import MetaData
|
||||||
from sources.source_types.AbstractSource import AbstractSource
|
from sources.source_types.AbstractSource import AbstractSource
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseSource(BaseModel):
|
class BaseSource(BaseModel):
|
||||||
source_name: str
|
source_name: str
|
||||||
source: dict
|
source: dict
|
||||||
@@ -24,7 +26,7 @@ class BaseSource(BaseModel):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**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):
|
def get_source_object(config):
|
||||||
class_name = config.type.capitalize() + "Source"
|
class_name = config.type.capitalize() + "Source"
|
||||||
|
|||||||
Reference in New Issue
Block a user