Skip to content

Commit

Permalink
WIP: add several helpers to connector for query
Browse files Browse the repository at this point in the history
WIP usage of implemented ErrataConnector::filter and other helpers
- get_releases_for_product
- get_open_advisories_for_release
- get_open_advisories_for_release_filter

Note: errata endpoint releases and products have to be special
handled to include extra [] and multiple entries if you want them

Related: red-hat-storage#132
  • Loading branch information
yazug committed Apr 27, 2020
1 parent 0c35a5e commit 3a2bbad
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions errata_tool/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,46 @@ def get_filter(self, endpoint, filter_arg, **kwargs):
return {'data': self.get_paginated_data(url)}

return self._get(url)

def get_releases_for_product(self, product_name_or_id, return_ids_only=True):
"""search for and return list of releases by name or id of product"""
args = {'is_active': 'true', 'enabled': 'true'}

try:
args['id'] = int(product_name_or_id)
except ValueError:
args['name'] = product_name_or_id

data = self.filter('/api/v1/releases', 'filter', **args)
if return_ids_only:
return [i['id'] for i in data['data']]

return data

def get_open_advisories_for_release(self, release_id):
data = self._get('/errata/errata_for_release/' +
'{0}.json'.format(release_id))

ADVISORY_STATES = ('NEW_FILES', 'QE', 'REL_PREP', 'PUSH_READY')
advisory_ids = set()

for advisory_result in data:
if advisory_result['status'] in ADVISORY_STATES:
advisory_ids.add(advisory_result['id'])
return list(advisory_ids)

def get_open_advisories_for_release_filter(self, release_id,
return_ids_only=True):
"""Return list of open advisories for a release either id's or json"""

data = self.filter(
'/errata', 'errata_filter[filter_params]',
show_type_RHBA=1, show_type_RHEA=1, show_type_RHSA=1,
show_state_NEW_FILES=1, show_state_QE=1, show_state_REL_PREP=1,
show_state_PUSH_READY=1, open_closed_option='exclude',
release=release_id)

if return_ids_only:
return [i['id'] for i in data]

return data

0 comments on commit 3a2bbad

Please sign in to comment.