Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Check bundled packages when querying package info in getInfo API #141462

Merged
merged 3 commits into from
Sep 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
RegistrySearchResults,
GetCategoriesRequest,
PackageVerificationResult,
ArchivePackage,
} from '../../../types';
import {
getArchiveFilelist,
Expand Down Expand Up @@ -159,7 +160,10 @@ export async function fetchFindLatestPackageOrUndefined(
}
}

export async function fetchInfo(pkgName: string, pkgVersion: string): Promise<RegistryPackage> {
export async function fetchInfo(
pkgName: string,
pkgVersion: string
): Promise<RegistryPackage | ArchivePackage> {
const registryUrl = getRegistryUrl();
try {
// Trailing slash avoids 301 redirect / extra hop
Expand All @@ -168,6 +172,18 @@ export async function fetchInfo(pkgName: string, pkgVersion: string): Promise<Re
return res;
} catch (err) {
if (err instanceof RegistryResponseError && err.status === 404) {
// Check bundled packages in case the exact package being requested is available on disk
const bundledPackage = await getBundledPackageByName(pkgName);

if (bundledPackage && bundledPackage.version === pkgVersion) {
const archivePackage = await generatePackageInfoFromArchiveBuffer(
bundledPackage.buffer,
'application/zip'
);

return archivePackage.packageInfo;
}

throw new PackageNotFoundError(`${pkgName}@${pkgVersion} not found`);
}
throw err;
Expand Down