From ee571cebb2a9f3815e299edec8f702a0e64ce402 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 10 Jul 2025 12:00:49 +0200 Subject: [PATCH 1/8] Edited file 'python-lib/dku_utils.py' --- python-lib/dku_utils.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index 834b2af..bb5a6f7 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -98,15 +98,30 @@ def template_dict(dictionnary, **kwargs): return ret -def format_template(template, **kwargs): - """ Replace {{keys}} elements in template with the matching value in the kwargs dictionnary""" +def format_template(template, allow_list=False, **kwargs): + """ + Replace {{key}} in template with the value(s) in the kwargs dictionnary. + If allow_list is False, list inputs will be joined into a comma-separated string (for headers). + If allow_list is True, lists will be returned as lists (for query params). + """ + def replace_in(template): + formated = template + for key, value in kwargs.items(): + formated = formated.replace(f"{{{{{key}}}}}", str(value)) + return formated if template is None: return None - formated = template - for key in kwargs: - replacement = kwargs.get(key, "") - formated = formated.replace("{{{{{}}}}}".format(key), str(replacement)) - return formated + elif isinstance(template, list): + replaced_list = [replace_in(item) for item in template] + if allow_list: + return replaced_list + else: + # To handle headers + return ", ".join(replaced_list) + elif isinstance(template, str): + return replace_in(template) + else: + return template def is_string(data): From dd71546c42e4df6d0bf57aaf74e58faa51c1b7e1 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 10 Jul 2025 12:02:27 +0200 Subject: [PATCH 2/8] Edited file 'python-lib/dku_utils.py' --- python-lib/dku_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index bb5a6f7..2a75433 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -11,6 +11,12 @@ def get_dku_key_values(endpoint_query_string): return {key_value.get("from"): key_value.get("to") for key_value in endpoint_query_string if key_value.get("from")} +def get_dku_key_multivalues(endpoint_query_string): + result = defaultdict(list) + for kv in endpoint_query_string: + if kv.get('from') and kv.get('to'): + result[kv['from'].strip()].append(kv['to'].strip()) + return dict(result) def get_endpoint_parameters(configuration): endpoint_parameters = [ From 632d6baeda35491df27dba16fc5b30418666713a Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 10 Jul 2025 12:03:40 +0200 Subject: [PATCH 3/8] Edited file 'python-lib/dku_utils.py' From b7f2d48957d6a04c7aa2f92fe48001a1a22a8108 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 10 Jul 2025 12:07:17 +0200 Subject: [PATCH 4/8] Edited file 'python-lib/dku_utils.py' --- python-lib/dku_utils.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index 2a75433..0e86888 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -104,30 +104,16 @@ def template_dict(dictionnary, **kwargs): return ret -def format_template(template, allow_list=False, **kwargs): - """ - Replace {{key}} in template with the value(s) in the kwargs dictionnary. - If allow_list is False, list inputs will be joined into a comma-separated string (for headers). - If allow_list is True, lists will be returned as lists (for query params). - """ - def replace_in(template): - formated = template - for key, value in kwargs.items(): - formated = formated.replace(f"{{{{{key}}}}}", str(value)) - return formated +def format_template(template, **kwargs): + """ Replace {{keys}} elements in template with the matching value in the kwargs dictionnary""" if template is None: return None - elif isinstance(template, list): - replaced_list = [replace_in(item) for item in template] - if allow_list: - return replaced_list - else: - # To handle headers - return ", ".join(replaced_list) - elif isinstance(template, str): - return replace_in(template) - else: - return template + placeholders = re.findall(r'{{([a-zA-Z\-\_]*)}}', template) + formated = template + for placeholder in placeholders: + replacement = kwargs.get(placeholder, "") + formated = formated.replace("{{{{{}}}}}".format(placeholder), str(replacement)) + return formated def is_string(data): From d6340a8969a2171e1af653ee1bda3c3fe931af3c Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 10 Jul 2025 12:08:12 +0200 Subject: [PATCH 5/8] Edited file 'python-lib/dku_utils.py' --- python-lib/dku_utils.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index 0e86888..09beee9 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -11,12 +11,6 @@ def get_dku_key_values(endpoint_query_string): return {key_value.get("from"): key_value.get("to") for key_value in endpoint_query_string if key_value.get("from")} -def get_dku_key_multivalues(endpoint_query_string): - result = defaultdict(list) - for kv in endpoint_query_string: - if kv.get('from') and kv.get('to'): - result[kv['from'].strip()].append(kv['to'].strip()) - return dict(result) def get_endpoint_parameters(configuration): endpoint_parameters = [ From e2871a533ea8d7c63e0f5193b0e90594cf450ce9 Mon Sep 17 00:00:00 2001 From: JaneBellaiche Date: Thu, 10 Jul 2025 13:41:25 +0200 Subject: [PATCH 6/8] support query with multivalued keys --- python-lib/dku_utils.py | 38 ++++++++++++++++++++++++++--------- python-lib/rest_api_client.py | 6 +++--- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index 09beee9..b11991a 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -1,6 +1,7 @@ import json import copy import math +from collections import defaultdict from jsonpath_ng.ext import parse from safe_logger import SafeLogger @@ -9,7 +10,12 @@ def get_dku_key_values(endpoint_query_string): - return {key_value.get("from"): key_value.get("to") for key_value in endpoint_query_string if key_value.get("from")} + result = defaultdict(list) + for kv in endpoint_query_string: + if kv.get('from') and kv.get('to'): + result[kv['from'].strip()].append(kv['to'].strip()) + return dict(result) + def get_endpoint_parameters(configuration): @@ -98,16 +104,30 @@ def template_dict(dictionnary, **kwargs): return ret -def format_template(template, **kwargs): - """ Replace {{keys}} elements in template with the matching value in the kwargs dictionnary""" +def format_template(template, allow_list=False, **kwargs): + """ + Replace {{key}} in template with the value(s) in the kwargs dictionnary. + If allow_list is False, list inputs will be joined into a comma-separated string (for headers). + If allow_list is True, lists will be returned as lists (for query params). + """ + def replace_in(template): + formated = template + for key, value in kwargs.items(): + formated = formated.replace(f"{{{{{key}}}}}", str(value)) + return formated if template is None: return None - placeholders = re.findall(r'{{([a-zA-Z\-\_]*)}}', template) - formated = template - for placeholder in placeholders: - replacement = kwargs.get(placeholder, "") - formated = formated.replace("{{{{{}}}}}".format(placeholder), str(replacement)) - return formated + elif isinstance(template, list): + replaced_list = [replace_in(item) for item in template] + if allow_list: + return replaced_list + else: + # To handle headers + return ", ".join(replaced_list) + elif isinstance(template, str): + return replace_in(template) + else: + return template def is_string(data): diff --git a/python-lib/rest_api_client.py b/python-lib/rest_api_client.py index 0b467ce..246345b 100644 --- a/python-lib/rest_api_client.py +++ b/python-lib/rest_api_client.py @@ -46,7 +46,7 @@ def __init__(self, credential, secure_credentials, endpoint, custom_key_values={ endpoint_headers = endpoint.get("endpoint_headers", "") self.endpoint_headers = self.get_params(endpoint_headers, self.presets_variables) - self.params = self.get_params(self.endpoint_query_string, self.presets_variables) + self.params = self.get_params(self.endpoint_query_string, self.presets_variables, True) self.extraction_key = endpoint.get("extraction_key", None) @@ -195,11 +195,11 @@ def set_metadata(self, metadata_name, value): self.metadata["dku_{}".format(metadata_name)] = value @staticmethod - def get_params(endpoint_query_string, keywords): + def get_params(endpoint_query_string, keywords, allow_list=False): templated_query_string = get_dku_key_values(endpoint_query_string) ret = {} for key in templated_query_string: - ret.update({key: format_template(templated_query_string.get(key, ""), **keywords) or ""}) + ret.update({key: format_template(templated_query_string.get(key, ""),allow_list=allow_list, **keywords) or ""}) return ret def has_more_data(self): From eb5811f0794e12a22915802b5dafa93cc9d213e8 Mon Sep 17 00:00:00 2001 From: Jane Bellaiche <77485161+JaneBellaiche@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:01:53 +0200 Subject: [PATCH 7/8] formatting --- python-lib/dku_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python-lib/dku_utils.py b/python-lib/dku_utils.py index b11991a..eb170c4 100644 --- a/python-lib/dku_utils.py +++ b/python-lib/dku_utils.py @@ -17,7 +17,6 @@ def get_dku_key_values(endpoint_query_string): return dict(result) - def get_endpoint_parameters(configuration): endpoint_parameters = [ "endpoint_url", From a634bbbe55d5e4abcb6a002fb00ab46ae0b9f348 Mon Sep 17 00:00:00 2001 From: Jane Bellaiche <77485161+JaneBellaiche@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:02:52 +0200 Subject: [PATCH 8/8] more formatting --- python-lib/rest_api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-lib/rest_api_client.py b/python-lib/rest_api_client.py index 246345b..efaa2eb 100644 --- a/python-lib/rest_api_client.py +++ b/python-lib/rest_api_client.py @@ -199,7 +199,7 @@ def get_params(endpoint_query_string, keywords, allow_list=False): templated_query_string = get_dku_key_values(endpoint_query_string) ret = {} for key in templated_query_string: - ret.update({key: format_template(templated_query_string.get(key, ""),allow_list=allow_list, **keywords) or ""}) + ret.update({key: format_template(templated_query_string.get(key, ""), allow_list=allow_list, **keywords) or ""}) return ret def has_more_data(self):