Skip to content
Snippets Groups Projects
Commit ecfce64a authored by Robert Rosca's avatar Robert Rosca
Browse files

Use Dynaconf for webservice configuration

Implemented with minimal changes
parent a88ac05b
No related branches found
No related tags found
1 merge request!531Feat/dynaconf
from dynaconf import Dynaconf
webservice = Dynaconf(
envvar_prefix="DYNACONF",
settings_files=["webservice.yaml", ".webservice.secrets.yaml"],
environments=False,
)
serve_overview = Dynaconf(
envvar_prefix="DYNACONF",
settings_files=["serve_overview.yaml", ".serve_overview.secrets.yaml"],
environments=False,
)
# `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`.
# `settings_files` = Load this files in the order.
......@@ -15,7 +15,6 @@ metadata-client:
user-secret:
user-email:
metadata-web-app-url: 'https://in.xfel.eu/metadata'
metadata-web-app-url: 'https://in.xfel.eu/metadata'
token-url: 'https://in.xfel.eu/metadata/oauth/token'
refresh-url: 'https://in.xfel.eu/metadata/oauth/token'
auth-url: 'https://in.xfel.eu/metadata/oauth/authorize'
......
"""Print Kafka events sent by the webservice.
"""
import json
import os.path as osp
import yaml
from kafka import KafkaConsumer
conf_file = osp.join(osp.dirname(__file__), 'webservice.yaml')
with open(conf_file, "r") as f:
config = yaml.safe_load(f)
from .config import webservice as config
topic = config['kafka']['topic']
brokers = config['kafka']['brokers']
......
......@@ -6,12 +6,12 @@ from collections import OrderedDict
from datetime import datetime, timezone
from http.server import BaseHTTPRequestHandler, HTTPServer
from subprocess import check_output
from uuid import uuid4
import yaml
from jinja2 import Template
from xfel_calibrate.settings import free_nodes_cmd, preempt_nodes_cmd, reservation
from .config import serve_overview as config
class LimitedSizeDict(OrderedDict):
......@@ -30,7 +30,6 @@ class LimitedSizeDict(OrderedDict):
self.popitem(last=False)
config = None
pdf_queue = LimitedSizeDict(size_limit=50)
......@@ -345,10 +344,6 @@ class RequestHandler(BaseHTTPRequestHandler):
def run(configfile, port=8008):
print('reading config file')
with open(configfile, "r") as cf:
global config
config = yaml.load(cf.read(), Loader=yaml.FullLoader)
with open(config["web-service"]["cal-config"], "r") as cf:
global cal_config
cal_config = yaml.load(cf.read(), Loader=yaml.FullLoader)
......
......@@ -4,6 +4,8 @@ import os.path as osp
import yaml
from metadata_client.metadata_client import MetadataClient
from .config import webservice as config
parser = argparse.ArgumentParser(
description='Update run status at MDC for a given run id.')
parser.add_argument('--conf-file', type=str, help='Path to webservice config',
......@@ -20,9 +22,6 @@ rid = args['rid']
flg = args['flg']
msg = args['msg']
with open(conf_file, "r") as f:
config = yaml.load(f.read(), Loader=yaml.FullLoader)
mdconf = config['metadata-client']
client_conn = MetadataClient(client_id=mdconf['user-id'],
client_secret=mdconf['user-secret'],
......
......@@ -30,6 +30,8 @@ from kafka import KafkaProducer
from kafka.errors import KafkaError
from metadata_client.metadata_client import MetadataClient
from .config import webservice as config
try:
from .messages import MDC, Errors, Success
except ImportError:
......@@ -1136,9 +1138,6 @@ def main(argv: Optional[List[str]] = None):
log_level = args.log_level
mode = args.mode
with open(config_file, "r") as f:
config = yaml.safe_load(f.read())
fmt = '%(asctime)s - %(name)s - %(levelname)s - [%(filename)s:%(lineno)d] %(message)s'
logging.basicConfig(
filename=log_file,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment