From ab948ac6849b1258501d72c7d64aacbe8e59c305 Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Thu, 1 Feb 2024 17:19:26 +0300 Subject: [PATCH] Modify the build_payload function, check for more use cases under update and create --- importer/main.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/importer/main.py b/importer/main.py index ec4d6554..4f73f2ab 100644 --- a/importer/main.py +++ b/importer/main.py @@ -467,17 +467,27 @@ def build_payload(resource_type, resources, resource_payload_file): for resource in resources: try: - if resource[2] == "update": - # use the provided id - unique_uuid = resource[4] - identifier_uuid = resource[4] if resource[5] == "" else resource[5] - else: - # generate a new uuid - unique_uuid = str(uuid.uuid4()) - identifier_uuid = unique_uuid + if resource[2] == "create": + if len(resource[4].strip()) > 0: + # use the provided id + unique_uuid = resource[4].strip() + identifier_uuid = resource[4] if resource[5] == "" else resource[5] + else: + # generate a new uuid + unique_uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, resource[0])) + identifier_uuid = unique_uuid + elif resource[2] == "update": + if len(resource[4].strip()) > 0: + # use the provided id + unique_uuid = resource[4].strip() + identifier_uuid = resource[4] if resource[5] == "" else resource[5] + else: + # generate a new uuid + unique_uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, resource[0])) + identifier_uuid = unique_uuid except IndexError: # default if method is not provided - unique_uuid = str(uuid.uuid4()) + unique_uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, resource[0])) identifier_uuid = unique_uuid # ps = payload_string