-
Notifications
You must be signed in to change notification settings - Fork 0
/
injector.py
78 lines (62 loc) · 2.48 KB
/
injector.py
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
from config.log_config import create_log
from config import config
from service.Handler.search.SearchOmniHandler import (SearchOmniHandler)
from service.Handler.search.QueryBuilder import (QueryBuilder, QueryVectorBuilder)
from service.Handler.message.redis_handler import Cache
from elasticsearch import Elasticsearch
from service.Handler.util.es_utils import ES_Utils
from dotenv import load_dotenv
import yaml
import json
import os
def read_config_yaml():
with open('./config.yaml', 'r') as f:
doc = yaml.load(f, Loader=yaml.FullLoader)
logger.info(json.dumps(doc, indent=2))
return doc
def get_headers():
''' Elasticsearch Header '''
return {'Content-type': 'application/json', 'Connection': 'close'}
load_dotenv()
# Initialize & Inject with only one instance
logger = create_log()
doc = read_config_yaml()
# print(doc)
# Read_Doc with arguments from Docker -e option
"""
hosts = os.getenv("ES_HOST", doc['app']['es']['omni_es_host'])
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:1234@{}:{}/postgres".format(doc['app']['mud']['host'],
doc['app']['mud']['port']
))
RABBITMQ_HOST = os.getenv('RABBIT_HOST', doc['app']['rabbitmq']['host'])
"""
global_settings = config.Settings(logger, doc)
# --
# RabbitMQ
DATABASE_URL = global_settings.get_DATABASE_URL()
RABBITMQ_HOST = global_settings.get_RABBITMQ_HOST()
# --
# --
# Redis
RedisHanlderInject = global_settings.get_REDIS_HOST()
Redis_Cache = Cache(logger, doc, RedisHanlderInject)
# --
es_client = Elasticsearch(hosts=global_settings.get_Hosts(),
headers=get_headers(),
verify_certs=False,
timeout=600
)
SearchOmniHandlerInject = SearchOmniHandler(es_client, logger, doc['app'])
QueryBuilderInject = QueryBuilder(es_client, logger, doc['app'])
QueryVectorBuilderInject = QueryVectorBuilder(es_client, logger, doc['app'])
metrics_service = ES_Utils(logger, doc, es_client)
# --
# Jinja2 template & filter call from html
# --
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="./template")
'''
https://abstractkitchen.com/blog/how-to-create-custom-jinja-filters-in-flask/
'''
from controller.Custome_jinja.filter import locale_code_to_name_filter
templates.env.filters['lc_name'] = locale_code_to_name_filter