From d9a818179e0417ce202d5b4ff21f3853a65fa22a Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Wed, 24 Apr 2024 19:26:05 +0200 Subject: [PATCH] feat: list modified packages in modified repos RHINENG-9690 --- vmaas/webapp/repos.py | 44 +++++++++++++++++++++++++++++--- vmaas/webapp/webapp.v3.spec.yaml | 10 ++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/vmaas/webapp/repos.py b/vmaas/webapp/repos.py index 0b6f4a0dc..111716c9f 100755 --- a/vmaas/webapp/repos.py +++ b/vmaas/webapp/repos.py @@ -3,6 +3,7 @@ """ import os +from collections import defaultdict from vmaas.webapp.cache import ( REPO_NAME, @@ -12,7 +13,11 @@ REPO_PRODUCT, REPO_REVISION, REPO_LAST_CHANGE, - REPO_THIRD_PARTY + REPO_THIRD_PARTY, + ERRATA_UPDATED, + ERRATA_ID, + ERRATA_PKGIDS, + PKG_NAME_ID ) from vmaas.common.date_utils import format_datetime from vmaas.common.webapp_utils import paginate, none2empty, parse_datetime, \ @@ -34,6 +39,13 @@ def _modified_since(repo_detail, modified_since_dt): return True return False + @staticmethod + def _errata_modified_since(errata_detail, modified_since_dt): + if not modified_since_dt or (errata_detail[ERRATA_UPDATED] is not None and + errata_detail[ERRATA_UPDATED] > modified_since_dt): + return True + return False + def try_expand_by_regex(self, repos: list) -> list: """Expand list with a POSIX regex if possible""" out_repos = try_expand_by_regex(repos, self.cache.repolabel2ids) @@ -66,6 +78,26 @@ def _filter_third_party(self, repos_to_process, include_third_party): filtered_repos.append(label) return filtered_repos + def _set_updated_packages(self, repo, repo_id, repoid2errataids, modified_since_dt, show_packages): + if modified_since_dt and show_packages: + pkg_names = set() + for errata_id in repoid2errataids[repo_id]: + errata_name = self.cache.errataid2name[errata_id] + errata = self.cache.errata_detail[errata_name] + for pkg_id in errata[ERRATA_PKGIDS]: + name_id = self.cache.package_details[pkg_id][PKG_NAME_ID] + pkg_names.add(self.cache.id2packagename[name_id]) + repo["updated_package_names"] = list(pkg_names) + + def _build_repoid2errataids(self, modified_since_dt, show_packages): + repoid2errataids = defaultdict(list) + if modified_since_dt and show_packages: + for errata in self.cache.errata_detail.values(): + if self._errata_modified_since(errata, modified_since_dt): + for repo_id in self.cache.errataid2repoids[errata[ERRATA_ID]]: + repoid2errataids[repo_id].append(errata[ERRATA_ID]) + return repoid2errataids + def process_list(self, api_version, data): # pylint: disable=unused-argument """ Returns repository details. @@ -77,6 +109,7 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument repos = data.get('repository_list', None) strip_prefixes(repos, REPO_PREFIXES) modified_since = data.get('modified_since', None) + show_packages = data.get("show_packages", False) modified_since_dt = parse_datetime(modified_since) page = data.get("page", None) page_size = data.get("page_size", None) @@ -104,6 +137,8 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument repo_details[label] = self.cache.repo_detail[repo_id] filters.append((filter_item_if_exists, [repo_details])) + repoid2errataids = self._build_repoid2errataids(modified_since_dt, show_packages) + actual_page_size = 0 repo_page_to_process, pagination_response = paginate(repos, page, page_size, filters=filters) latest_repo_change = None @@ -116,7 +151,8 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument cpe_ids = self.cache.repo_id2cpe_ids[repo_id] else: cpe_ids = self.cache.content_set_id2cpe_ids.get(cs_id, []) - repolist.setdefault(label, []).append({ + + repo = { "label": label, "name": repo_detail[REPO_NAME], "url": repo_detail[REPO_URL], @@ -127,7 +163,9 @@ def process_list(self, api_version, data): # pylint: disable=unused-argument "last_change": format_datetime(repo_detail[REPO_LAST_CHANGE]), "cpes": [self.cache.cpe_id2label[cpe_id] for cpe_id in cpe_ids], "third_party": repo_detail[REPO_THIRD_PARTY] - }) + } + self._set_updated_packages(repo, repo_id, repoid2errataids, modified_since_dt, show_packages) + repolist.setdefault(label, []).append(repo) if not latest_repo_change or repo_detail[REPO_LAST_CHANGE] > latest_repo_change: latest_repo_change = repo_detail[REPO_LAST_CHANGE] actual_page_size += len(repolist[label]) diff --git a/vmaas/webapp/webapp.v3.spec.yaml b/vmaas/webapp/webapp.v3.spec.yaml index a373a8a24..6af2989fe 100644 --- a/vmaas/webapp/webapp.v3.spec.yaml +++ b/vmaas/webapp/webapp.v3.spec.yaml @@ -738,6 +738,11 @@ components: enum: [ true, false ] description: Include content from "third party" repositories into the response, disabled by default. default: false + show_packages: + type: boolean + enum: [ true, false ] + description: Show updated package names in a repo since the last modified_since + default: false <<: *req_paging required: - repository_list @@ -779,6 +784,11 @@ components: example: cpe:/a:redhat third_party: type: boolean + updated_package_names: + type: array + items: + type: string + example: kernel last_change: type: string example: '2020-04-16 20:07:58.500192+00'