From 2d4494685618d3bcf6350c06370b31a5d4dfa9b4 Mon Sep 17 00:00:00 2001 From: synkd Date: Thu, 25 Aug 2022 11:58:35 -0400 Subject: [PATCH] Box manifest data, allow top-level URL setting This commit ensures that, when manifest_category is passed as a dict, it is wrapped in a DynaBox instance. This ensures consistency with the behavior when settings are read from manifester_settings.yaml and should allow DynaConf validation of manifest_category data passed from an external framework. This commit also ensures that, if the token request URL and allocations API endpoint URL are not present in manifest_category, they will be read from the top level of manifester_settings.yaml. --- manifester/manifester.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/manifester/manifester.py b/manifester/manifester.py index 941cac3..de0da7a 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -1,5 +1,6 @@ import random import string +from dynaconf.utils.boxing import DynaBox from pathlib import Path import requests @@ -13,7 +14,7 @@ class Manifester: def __init__(self, manifest_category, allocation_name=None, **kwargs): if isinstance(manifest_category, dict): - self.manifest_data = manifest_category + self.manifest_data = DynaBox(manifest_category) else: self.manifest_data = settings.manifest_category.get(manifest_category) self.allocation_name = allocation_name or "".join( @@ -30,6 +31,8 @@ def __init__(self, manifest_category, allocation_name=None, **kwargs): self.simple_content_access = kwargs.get( "simple_content_access", self.manifest_data.simple_content_access ) + self.token_request_url = self.manifest_data.get("url", {}).get("token_request", settings.url.token_request) + self.allocations_url = self.manifest_data.get("url", {}).get("allocations", settings.url.allocations) self._access_token = None self._subscription_pools = None @@ -40,7 +43,7 @@ def access_token(self): logger.debug("Generating access token") token_data = simple_retry( requests.post, - cmd_args=[f"{self.manifest_data.url.token_request}"], + cmd_args=[f"{self.token_request_url}"], cmd_kwargs=token_request_data, ).json() self._access_token = token_data["access_token"] @@ -58,7 +61,7 @@ def create_subscription_allocation(self): } self.allocation = simple_retry( requests.post, - cmd_args=[f"{self.manifest_data.url.allocations}"], + cmd_args=[f"{self.allocations_url}"], cmd_kwargs=allocation_data, ).json() self.allocation_uuid = self.allocation["body"]["uuid"] @@ -77,7 +80,7 @@ def delete_subscription_allocation(self): } response = simple_retry( requests.delete, - cmd_args=[f"{self.manifest_data.url.allocations}/{self.allocation_uuid}"], + cmd_args=[f"{self.allocations_url}/{self.allocation_uuid}"], cmd_kwargs=data, ) return response @@ -94,7 +97,7 @@ def subscription_pools(self): self._subscription_pools = simple_retry( requests.get, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/pools" + f"{self.allocations_url}/{self.allocation_uuid}/pools" ], cmd_kwargs=data, ).json() @@ -116,7 +119,7 @@ def subscription_pools(self): offset_pools = simple_retry( requests.get, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/pools" + f"{self.allocations_url}/{self.allocation_uuid}/pools" ], cmd_kwargs=data, ).json() @@ -137,7 +140,7 @@ def add_entitlements_to_allocation(self, pool_id, entitlement_quantity): add_entitlements = simple_retry( requests.post, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/entitlements" + f"{self.allocations_url}/{self.allocation_uuid}/entitlements" ], cmd_kwargs=data, ) @@ -154,7 +157,7 @@ def verify_allocation_entitlements(self, entitlement_quantity, subscription_name } self.entitlement_data = simple_retry( requests.get, - cmd_args=[f"{self.manifest_data.url.allocation}/{self.allocation_uuid}"], + cmd_args=[f"{self.allocations_url}/{self.allocation_uuid}"], cmd_kwargs=data, ).json() current_entitlement = [ @@ -267,7 +270,7 @@ def trigger_manifest_export(self): trigger_export_job = simple_retry( requests.get, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/export" + f"{self.allocations_url}/{self.allocation_uuid}/export" ], cmd_kwargs=data, ).json() @@ -275,7 +278,7 @@ def trigger_manifest_export(self): export_job = simple_retry( requests.get, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/exportJob/{export_job_id}" + f"{self.allocations_url}/{self.allocation_uuid}/exportJob/{export_job_id}" ], cmd_kwargs=data, ) @@ -285,7 +288,7 @@ def trigger_manifest_export(self): export_job = simple_retry( requests.get, cmd_args=[ - f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/exportJob/{export_job_id}" + f"{self.allocations_url}/{self.allocation_uuid}/exportJob/{export_job_id}" ], cmd_kwargs=data, )