Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor settings and reformat multiple files #8

Merged
merged 5 commits into from
Aug 1, 2022

Conversation

synkd
Copy link
Collaborator

@synkd synkd commented Jul 28, 2022

Previously, API URLs were hardcoded in the body of
manifester/manifester.py, and the offline token (which is used to
generate an access token, which is in turn used to authenticate API
calls) was a top-level setting. This commit makes the offline_token
setting a child setting of each manifest_category, and it moves the API
URLs to the settings file, also as children of each manifest_category.
This should enable greater flexibility by letting users associate
manifests with multiple RHSM accounts (potentially in multiple
environments, such as Red Hat's staging environment) in a single
settings file.

This commit also makes numerous formatting changes as a result of
running pre-commit.

Additionally, the offline_token validator in manifester/settings.py has
been commented out as it fails to validate with the offline_token
setting nested under the manifest categories.

Previously, API URLs were hardcoded in the body of
manifester/manifester.py, and the offline token (which is used to
generate an access token, which is in turn used to authenticate API
calls) was a top-level setting. This commit makes the offline_token
setting a child setting of each manifest_category, and it moves the API
URLs to the settings file, also as children of each manifest_category.
This should enable greater flexibility by letting users associate
manifests with multiple RHSM accounts (potentially in multiple
environments, such as Red Hat's staging environment) in a single
settings file.

This commit also makes numerous formatting changes as a result of
running pre-commit.

Additionally, the offline_token validator in manifester/settings.py has
been commented out as it fails to validate with the offline_token
setting nested under the manifest categories.
subscription_data:
# name should be an exact match of the subscription name as listed on the Customer Portal
- name: "Software Collections and Developer Toolset"
quantity: 1
- name: "Red Hat Ansible Automation Platform, Standard (100 Managed Nodes)"
quantity: 1
simple_content_access: "enabled"
url:
token_request: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token"
allocations: "https://api.access.redhat.com/management/v1/allocations"
Copy link
Member

@ogajduse ogajduse Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! People can simply generate manifest on stage using manifester!
Edit: a few minutes later, I read the PR description.

Copy link
Member

@ogajduse ogajduse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, I can not wait to see manifester integrated into robottelo!
It looks to me that you let black do the black formatting magic. Would it make sense now to run black on every pull request?

manifester/commands.py Show resolved Hide resolved
self.subscription_data = manifest_data.subscription_data
self.sat_version = kwargs.get("sat_version", manifest_data.sat_version)
self.allocation_name = allocation_name or "".join(
random.sample(string.ascii_letters, 10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a fauxfactory dependency for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now it is just a single call, but if more random data is needed later, that is a possibility. or the more performant

str(uuid4()).split("-")[-1]

Comment on lines 19 to 21
self.offline_token = kwargs.get(
"offline_token", self.manifest_data.offline_token
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to modify this so the offline token could be set at the top level or overridden at the manifest level. That way someone using the same token for each doesn't need to duplicate the setting for each manifest.

Suggested change
self.offline_token = kwargs.get(
"offline_token", self.manifest_data.offline_token
)
self.offline_token = kwargs.get(
"offline_token", self.manifest_data.get("offline_token", settings.offline_token)
)

self._subscription_pools=None
logger.debug(
f"Received response status {add_entitlements.status_code}."
f"Trying to find another pool."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"Trying to find another pool."
"Trying to find another pool."

)
break
else:
raise Exception(f"Something went wrong while adding entitlements. Received response status {add_entitlements.status_code}.")
raise Exception(
f"Something went wrong while adding entitlements. Received response status "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"Something went wrong while adding entitlements. Received response status "
"Something went wrong while adding entitlements. Received response status "

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": ""}).
@synkd synkd requested a review from JacobCallahan July 29, 2022 20:58
Copy link
Member

@JacobCallahan JacobCallahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

@synkd synkd merged commit e5e4a90 into SatelliteQE:master Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants