From 7eaeeae36bc165881382523d0b218a8101ca1622 Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Thu, 2 May 2024 16:44:41 +0200 Subject: [PATCH] support endpoints alongside endpoint Signed-off-by: Matthias Gatto --- osc_sdk/sdk.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/osc_sdk/sdk.py b/osc_sdk/sdk.py index 43db46e..9e9695e 100755 --- a/osc_sdk/sdk.py +++ b/osc_sdk/sdk.py @@ -721,7 +721,7 @@ def patch_conf(conf: Configuration, endpoint: Optional[str] = None) -> Configura return conf -def get_conf(profile: str) -> Configuration: +def get_conf(profile: str, service: str) -> Configuration: # Check which conf_path is used. conf_path = next((path for path in CONF_PATHS if path.exists()), None) @@ -741,6 +741,29 @@ def get_conf(profile: str) -> Configuration: if not "https" in json_profile: json_profile["https"] = True + if "endpoints" in json_profile: + if service == "api" and "api" in json_profile["endpoints"]: + json_profile["endpoint"] = json_profile["endpoints"]["api"] + del json_profile["endpoints"] + elif ( + service == "directlink" + and "directlink" in json_profile["endpoints"] + ): + json_profile["endpoint"] = json_profile["endpoints"]["directlink"] + del json_profile["endpoints"] + elif service == "eim" and "eim" in json_profile["endpoints"]: + json_profile["endpoint"] = json_profile["endpoints"]["eim"] + del json_profile["endpoints"] + elif service == "fcu" and "fcu" in json_profile["endpoints"]: + json_profile["endpoint"] = json_profile["endpoints"]["fcu"] + del json_profile["endpoints"] + elif service == "lbu" and "lbu" in json_profile["endpoints"]: + json_profile["endpoint"] = json_profile["endpoints"]["lbu"] + del json_profile["endpoints"] + elif service == "okms" and "okms" in json_profile["endpoints"]: + json_profile["endpoint"] = json_profile["endpoints"]["okms"] + del json_profile["endpoints"] + if not "region_name" in json_profile: json_profile["region_name"] = json_profile["region"] del json_profile["region"] @@ -792,7 +815,7 @@ def api_connect( login, PASSWORD_ARG, authentication_method, - **patch_conf(get_conf(profile), endpoint), + **patch_conf(get_conf(profile, service), endpoint), ) handler.make_request(call, **kwargs)