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(RHINENG-5484): refactor operating_system filter #2141

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FabriciaDinizRH
Copy link
Contributor

Overview

This PR is being created to address RHINENG-5484.
I tried a few different ways, I think I got a good one but I'm not sure how to write the actual filter

PR Checklist

  • Keep PR title short, ideally under 72 characters
  • Descriptive comments provided in complex code blocks
  • Include raw query examples in the PR description, if adding/modifying SQL query
  • Tests: validate optimal/expected output
  • Tests: validate exceptions and failure scenarios
  • Tests: edge cases
  • Recovers or fails gracefully during potential resource outages (e.g. DB, Kafka)
  • Uses type hinting, if convenient
  • Documentation, if this PR changes the way other services interact with host inventory
  • Links to related PRs

Secure Coding Practices Documentation Reference

You can find documentation on this checklist here.

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

@FabriciaDinizRH
Copy link
Contributor Author

I added some commits I was not supposed to, I'm fixing it

Comment on lines +119 to 120
for os_name in filter_param.keys(): # this doesn't account for "os_name" instead of os names
if os_name not in (os_names := _get_valid_os_names()):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend checking for the key "name" between these 2 lines and doing the custom logic there:

Suggested change
for os_name in filter_param.keys(): # this doesn't account for "os_name" instead of os names
if os_name not in (os_names := _get_valid_os_names()):
for os_name in filter_param.keys():
if os_name == "name":
# Return an OsComparison object that implies all hosts with a matching OS name.
# Maybe if OsComparison.comparator is "eq" or "neq" and the major version is None?
elif os_name not in (os_names := _get_valid_os_names()):

@@ -158,6 +169,7 @@ def build_operating_system_filter(filter_param: dict) -> tuple:
os_filter_list.append(os_field.astext.operate(comparator, None))

elif comparison.comparator == "eq":
print("~~~~~~~~~~~~~~~~~~~``", os_field["name"].astext == comparison.name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Around here is where you'd convert the OsComparison to an actual DB operation. If we went with the logic I posted above, this next section could be something like this:

Suggested change
print("~~~~~~~~~~~~~~~~~~~``", os_field["name"].astext == comparison.name)
os_filters = [
os_field["name"].astext == comparison.name,
]
if comparison.major is not None:
os_filters.append(os_field["major"].astext.cast(Integer) == comparison.major)
if comparison.minor:
os_filters.append(os_field["minor"].astext.cast(Integer) == comparison.minor)
os_filter_list.append(and_(*os_filters))

Of course, you'll need to handle "neq" as well :)

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.

2 participants