Skip to content

Commit

Permalink
Check bundled packages when querying package info in getInfo API
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed Sep 22, 2022
1 parent b026d2c commit 607014a
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit 607014a

Please sign in to comment.