Skip to content

Commit

Permalink
feat: list modified packages in modified repos
Browse files Browse the repository at this point in the history
RHINENG-9690
  • Loading branch information
psegedy authored and jdobes committed Apr 25, 2024
1 parent f30d7eb commit d9a8181
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
44 changes: 41 additions & 3 deletions vmaas/webapp/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
from collections import defaultdict

from vmaas.webapp.cache import (
REPO_NAME,
Expand All @@ -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, \
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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],
Expand All @@ -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])
Expand Down
10 changes: 10 additions & 0 deletions vmaas/webapp/webapp.v3.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit d9a8181

Please sign in to comment.