api: use content-sources api for package search on stage beta

The Content Sources service can now be used for handling package info and
search. The api call to this service requires a list of repo urls. The
`repos.json` file tracks the supported repositories for each distro.
This is then mapped into a url array for whichever distro we are
searching for packages. The response body is similar to what existed in
image-builder but the key `package_name` needs to be mapped to just
`name`. Also, there is no pagination in Content Sources for `/rpms/names`
so we can currently only fetch a limit of 20 packages.
This commit is contained in:
jkozol 2022-11-02 15:23:34 +01:00 committed by Sanne Raymaekers
parent a96c2df867
commit 414dff3ed7
5 changed files with 167 additions and 25 deletions

View file

@ -228,23 +228,31 @@ const parseSizeUnit = (bytesize) => {
};
const getPackageDescription = async (release, arch, packageName) => {
const args = [release, arch, packageName];
let { data, meta } = await api.getPackages(...args);
let summary;
let pack;
// if the env is stage beta then use content-sources api
// else use image-builder api
if (!insights.chrome.isProd() && insights.chrome.isBeta()) {
const args = [release, packageName];
const data = await api.getPackagesContentSources(...args);
// the package should be found in the 0 index
// if not then fetch all package matches and search for the package
if (data[0]?.name === packageName) {
summary = data[0]?.summary;
pack = data.find((pack) => packageName === pack.name);
} else {
if (data?.length !== meta.count) {
({ data } = await api.getPackages(...args, meta.count));
const args = [release, arch, packageName];
let { data, meta } = await api.getPackages(...args);
// the package should be found in the 0 index
// if not then fetch all package matches and search for the package
if (data[0]?.name === packageName) {
pack = data[0];
} else {
if (data?.length !== meta.count) {
({ data } = await api.getPackages(...args, meta.count));
}
pack = data.find((pack) => packageName === pack.name);
}
const pack = data.find((pack) => packageName === pack.name);
summary = pack?.summary;
}
const summary = pack?.summary;
// if no matching package is found return an empty string for description
return summary || '';
};

View file

@ -108,17 +108,24 @@ const Packages = ({ defaultArch, ...props }) => {
};
const getAllPackages = async () => {
const args = [
getState()?.values?.release,
getState()?.values?.architecture || defaultArch,
packagesSearchName,
];
let { data, meta } = await api.getPackages(...args);
if (data?.length === meta.count) {
return data;
} else if (data) {
({ data } = await api.getPackages(...args, meta.count));
return data;
// if the env is stage beta then use content-sources api
// else use image-builder api
if (!insights.chrome.isProd() && insights.chrome.isBeta()) {
const args = [getState()?.values?.release, packagesSearchName];
return await api.getPackagesContentSources(...args);
} else {
const args = [
getState()?.values?.release,
getState()?.values?.architecture || defaultArch,
packagesSearchName,
];
let { data, meta } = await api.getPackages(...args);
if (data?.length === meta.count) {
return data;
} else if (data) {
({ data } = await api.getPackages(...args, meta.count));
return data;
}
}
};