Fix cnfig parsing
This commit is contained in:
parent
094803cc8d
commit
41e9de25c7
|
@ -1,7 +1,7 @@
|
|||
[relais]
|
||||
identitifant_sonde = 838266b2-fc3a-4430-95e8-f7f0d0fc9871
|
||||
api_login_url = 'https://merlin.savediffusion.fr/api/1.1/user/login'
|
||||
api_status_url = 'https://merlin.savediffusion.fr/api/1.1/status"
|
||||
api_user_login = 'admin'
|
||||
api_user_password = 'Watermark35'
|
||||
forward_api_address = 'https:/papi.silib.re/'
|
||||
api_login_url = https://merlin.savediffusion.fr/api/1.1/user/login
|
||||
api_status_url = https://merlin.savediffusion.fr/api/1.1/status
|
||||
api_user_login =admin
|
||||
api_user_password = Watermark35
|
||||
forward_api_address = https:/papi.silib.re/
|
||||
|
|
|
@ -6,23 +6,42 @@ import configparser
|
|||
import logging as logger
|
||||
|
||||
|
||||
def read_config(*, pattern="*"):
|
||||
def read_config(*, kind=None, pattern="*"):
|
||||
if kind is None:
|
||||
kind = "api"
|
||||
|
||||
paths = []
|
||||
|
||||
for relpath in glob.glob(f"confs/{pattern}.ini"):
|
||||
if "/api_client" in relpath:
|
||||
logger.info(f"Found api client {relpath} to add")
|
||||
paths.append(os.path.abspath(relpath))
|
||||
res = []
|
||||
for path in paths:
|
||||
# TODO: use case/switch
|
||||
if kind == "api":
|
||||
for path in paths:
|
||||
conf = configparser.ConfigParser()
|
||||
conf.read(path)
|
||||
probe_settings = dict(conf["probe"])
|
||||
emails = probe_settings["emails"]
|
||||
stripped = [x.strip() for x in emails.split()]
|
||||
probe_settings["emails"] = stripped
|
||||
probe_settings["debug_source_path"] = path
|
||||
res.append(probe_settings)
|
||||
|
||||
elif kind == "relais":
|
||||
assert len(paths) == 1 # for now only one path is allowed
|
||||
conf = configparser.ConfigParser()
|
||||
path = paths[0]
|
||||
conf.read(path)
|
||||
probe_settings = dict(conf["probe"])
|
||||
emails = probe_settings["emails"]
|
||||
stripped = [x.strip() for x in emails.split()]
|
||||
probe_settings["emails"] = stripped
|
||||
probe_settings["debug_source_path"] = path
|
||||
res.append(probe_settings)
|
||||
gg = dict(conf["relais"])
|
||||
for k, v in gg.items():
|
||||
gg[k] = v.strip()
|
||||
if "'" in v or '"' in v:
|
||||
raise ValueError(
|
||||
f"{k}:{v} from {path} containts forbidden char (escaping issue)"
|
||||
)
|
||||
res.append(gg)
|
||||
|
||||
return res
|
||||
|
||||
|
|
|
@ -23,7 +23,10 @@ def api_login(config):
|
|||
post_url = config["api_login_url"]
|
||||
login_r = session.post(
|
||||
post_url,
|
||||
json={"login": api_credentials.user, "password": api_credentials.password},
|
||||
json={
|
||||
"login": config["api_user_login"],
|
||||
"password": config["api_user_password"],
|
||||
},
|
||||
)
|
||||
logged.append(True)
|
||||
|
||||
|
@ -77,7 +80,7 @@ def main(
|
|||
pattern="relais_*"
|
||||
):
|
||||
loopcount = itertools.count().__next__
|
||||
config = read_config(pattern=pattern)
|
||||
config = read_config(kind="relais", pattern=pattern)
|
||||
assert len(config) == 1
|
||||
config = config[0]
|
||||
login(config)
|
||||
|
|
|
@ -6,7 +6,8 @@ class ConfigurationTestCase(TestCase):
|
|||
""" Check configuration parsing """
|
||||
|
||||
def test_get_config(self):
|
||||
configs = main.read_config(pattern="*test_sonde")
|
||||
|
||||
configs = main.read_config(pattern="api_client*test_sonde")
|
||||
assert len(configs) == 1
|
||||
config = configs[0]
|
||||
assert config["identifiant_sonde"] == "838266b2-fc3a-4430-95e8-f7f0d0fc9871"
|
||||
|
|
Loading…
Reference in New Issue