Skip to content

Commit 5395b03

Browse files
add set rest engine config
Signed-off-by: Lanuti_emanuele <[email protected]>
1 parent fc7a243 commit 5395b03

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

suzieq/shared/utils.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from logging.handlers import RotatingFileHandler
1616
from os import getenv
1717
from time import time
18-
from typing import Any, Dict, List, Optional, Union
18+
from typing import Any, Dict, List, Optional, Union, Tuple
1919

2020
import pandas as pd
2121
import psutil
@@ -1229,3 +1229,28 @@ def log_suzieq_info(name: str, c_logger: logging.Logger = None,
12291229
'higher with 4 cores and 16 GB RAM')
12301230
if prev_level > logging.INFO:
12311231
c_logger.setLevel(prev_level)
1232+
1233+
def set_rest_engine(cfg:Dict[str, Any]) -> Tuple:
1234+
"""Unpack the rest configuration from the cfg object. It is used to switch
1235+
to rest engine with the right config params
1236+
1237+
Args:
1238+
cfg (dict): the configuration object.
1239+
1240+
Returns:
1241+
tuple:
1242+
rest_server_ip
1243+
rest_server_port
1244+
rest_transport
1245+
rest_api_key
1246+
"""
1247+
restcfg = cfg.get('rest', {})
1248+
rest_server_ip = restcfg.get('address', '127.0.0.1')
1249+
rest_server_port = restcfg.get('port', '80')
1250+
if restcfg.get('no-https', False):
1251+
rest_transport = 'http'
1252+
else:
1253+
rest_transport = 'https'
1254+
rest_api_key = restcfg.get('API_KEY', '')
1255+
1256+
return rest_server_ip, rest_server_port, rest_transport, rest_api_key

0 commit comments

Comments
 (0)