Skip to content

Commit

Permalink
Box manifest data, allow top-level URL setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
synkd committed Aug 25, 2022
1 parent f3cd617 commit 2d44946
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions manifester/manifester.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import string
from dynaconf.utils.boxing import DynaBox
from pathlib import Path

import requests
Expand All @@ -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(
Expand All @@ -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

Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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,
)
Expand All @@ -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 = [
Expand Down Expand Up @@ -267,15 +270,15 @@ 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()
export_job_id = trigger_export_job["body"]["exportJobID"]
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,
)
Expand All @@ -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,
)
Expand Down

0 comments on commit 2d44946

Please sign in to comment.