Skip to content

Commit

Permalink
Merge pull request #11 from synkd/accept_additional_configuration
Browse files Browse the repository at this point in the history
Add support for external configuration
  • Loading branch information
synkd authored Aug 29, 2022
2 parents c06b552 + 2d44946 commit 62ff557
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 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 @@ -12,13 +13,14 @@

class Manifester:
def __init__(self, manifest_category, allocation_name=None, **kwargs):
if isinstance(manifest_category, dict):
self.manifest_data = DynaBox(manifest_category)
else:
self.manifest_data = settings.manifest_category.get(manifest_category)
self.allocation_name = allocation_name or "".join(
random.sample(string.ascii_letters, 10)
)
self.manifest_data = settings.manifest_category.get(manifest_category)
self.offline_token = kwargs.get(
"offline_token", self.manifest_data.get("offline_token", settings.offline_token)
)
self.offline_token = kwargs.get("offline_token", self.manifest_data.offline_token)
self.subscription_data = self.manifest_data.subscription_data
self.sat_version = kwargs.get("sat_version", self.manifest_data.sat_version)
self.token_request_data = {
Expand All @@ -29,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 @@ -39,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 @@ -57,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 @@ -76,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 @@ -93,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 @@ -115,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 @@ -136,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 @@ -153,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 @@ -266,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 @@ -284,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 62ff557

Please sign in to comment.