From 9552ba0fc115ea9aa39b7e8eb086a2a7311ff93b Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 20 Mar 2024 13:08:21 +0100 Subject: [PATCH] tools/osbuild-depsolve-dnf: return repositories in response When generating package sources and rpm stage metadata for a manifest from a list of packages, we need to associate repository configuration options to each package [1]. Previously, a caller had all the repository configurations because they were part of the request, so packages could be associated with all the repository options by the repository ID. Now, osbuild-depsolve-dnf will use repositories loaded from a directory that the caller shouldn't have to read, so returning all repository configurations in the response makes it possible to get all package metadata from the response. This changes the whole structure of the response to a depsolve request. Previously, we returned an array of packages. Now we return an object with two keys: - packages: the array of packages as before - repositories: an object mapping repository IDs to repository configurations. Each package contains the repository ID it comes from (as before), under `repo_id`. This can be used to get repository configurations and determine gpg keys and SSL certs for each package. The new structure avoids duplicating values across all the (sometimes hundreds) of packages. [1] https://github.com/osbuild/images/blob/92497c7b1fcf8a09d136368db031ab65eedd7fa2/pkg/dnfjson/dnfjson.go#L499-L507 --- tools/osbuild-depsolve-dnf | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/osbuild-depsolve-dnf b/tools/osbuild-depsolve-dnf index 1533a9a2..b2bfc16e 100755 --- a/tools/osbuild-depsolve-dnf +++ b/tools/osbuild-depsolve-dnf @@ -253,9 +253,10 @@ class Solver(): continue last_transaction.append(tsi.pkg) - dependencies = [] + packages = [] + pkg_repos = {} for package in last_transaction: - dependencies.append({ + packages.append({ "name": package.name, "epoch": package.epoch, "version": package.version, @@ -264,13 +265,32 @@ class Solver(): "repo_id": package.repoid, "path": package.relativepath, "remote_location": package.remote_location(), - "checksum": ( - f"{hawkey.chksum_name(package.chksum[0])}:" - f"{package.chksum[1].hex()}" - ) + "checksum": f"{hawkey.chksum_name(package.chksum[0])}:{package.chksum[1].hex()}", }) + # collect repository objects by id to create the 'repositories' collection for the response + pkgrepo = package.repo + pkg_repos[pkgrepo.id] = pkgrepo - return dependencies + repositories = {} # full repository configs for the response + for repo in pkg_repos.values(): + repositories[repo.id] = { + "id": repo.id, + "name": repo.name, + "baseurl": list(repo.baseurl) if repo.baseurl else None, + "metalink": repo.metalink, + "mirrorlist": repo.mirrorlist, + "gpgcheck": repo.gpgcheck, + "check_repogpg": repo.repo_gpgcheck, + "ignoressl": not bool(repo.sslverify), + "sslcacert": repo.sslcacert, + "sslclientkey": repo.sslclientkey, + "sslclientcert": repo.sslclientcert, + } + response = { + "packages": packages, + "repos": repositories, + } + return response def setup_cachedir(request):