Skip to content

Commit

Permalink
Modify settings and requests to support proxies
Browse files Browse the repository at this point in the history
Access to the internal Red Hat staging environment is mediated through a
proxy server. To support compatibility with this environment, this
commit adds a `proxies` setting to each manifest_category and adds a
`proxies` argument to each request in manifester.py. To access the
production RHSM API without a proxy, the value of the dictionary in the
`proxies` setting can be left as an empty string (i.e. `proxies:
{"https": ""}).
  • Loading branch information
synkd committed Jul 29, 2022
1 parent f50b1f5 commit 6cef8c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions manifester/manifester.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def access_token(self):
def create_subscription_allocation(self):
allocation_data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
"params": {
"name": f"{self.allocation_name}",
"version": f"{self.sat_version}",
Expand All @@ -72,6 +73,7 @@ def subscription_pools(self):
_offset = 0
data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
"params": {"offset": _offset},
}
self._subscription_pools = simple_retry(
Expand All @@ -93,6 +95,7 @@ def subscription_pools(self):
)
data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
"params": {"offset": _offset},
}
offset_pools = simple_retry(
Expand All @@ -113,6 +116,7 @@ def subscription_pools(self):
def add_entitlements_to_allocation(self, pool_id, entitlement_quantity):
data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
"params": {"pool": f"{pool_id}", "quantity": f"{entitlement_quantity}"},
}
add_entitlements = simple_retry(
Expand All @@ -130,6 +134,7 @@ def verify_allocation_entitlements(self, entitlement_quantity, subscription_name
)
data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
"params": {"include": "entitlements"},
}
self.entitlement_data = simple_retry(
Expand Down Expand Up @@ -234,7 +239,10 @@ def process_subscription_pools(self, subscription_pools, subscription_data):
)

def trigger_manifest_export(self):
headers = {"headers": {"Authorization": f"Bearer {self.access_token}"}}
data = {
"headers": {"Authorization": f"Bearer {self.access_token}"},
"proxies": self.manifest_data.proxies,
}
# Should this use the XDG Base Directory Specification?
local_file = Path(f"manifests/{self.allocation_name}_manifest.zip")
local_file.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -246,15 +254,15 @@ def trigger_manifest_export(self):
cmd_args=[
f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/export"
],
cmd_kwargs=headers,
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}"
],
cmd_kwargs=headers,
cmd_kwargs=data,
)
request_count = 1
limit_exceeded = False
Expand All @@ -264,7 +272,7 @@ def trigger_manifest_export(self):
cmd_args=[
f"{self.manifest_data.url.allocations}/{self.allocation_uuid}/exportJob/{export_job_id}"
],
cmd_kwargs=headers,
cmd_kwargs=data,
)
logger.debug(
f"Attempting to export manifest. Attempt number: {request_count}"
Expand All @@ -284,7 +292,7 @@ def trigger_manifest_export(self):
manifest = simple_retry(
requests.get,
cmd_args=[f"{export_href}"],
cmd_kwargs=headers,
cmd_kwargs=data,
)
logger.info(
f"Writing manifest for subscription allocation {self.allocation_name} to location "
Expand Down
2 changes: 2 additions & 0 deletions manifester_settings.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ manifest_category:
url:
token_request: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token"
allocations: "https://api.access.redhat.com/management/v1/allocations"
proxies: {"https": ""}
robottelo_automation:
offline_token: ""
sat_version: "sat-6.10"
Expand All @@ -30,3 +31,4 @@ manifest_category:
url:
token_request: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token"
allocations: "https://api.access.redhat.com/management/v1/allocations"
proxies: {"https": ""}

0 comments on commit 6cef8c7

Please sign in to comment.