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

[Integrations UI] Allow for versionless integration details urls #103484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/packages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ export async function getPackageInfo(options: {
Registry.fetchFindLatestPackage(pkgName),
]);

// If no package version is provided, use the installed version in the response
let responsePkgVersion = pkgVersion || savedObject?.attributes.install_version;

// If no installed version of the given package exists, default to the latest version of the package
if (!responsePkgVersion) {
responsePkgVersion = latestPackage.version;
}

const getPackageRes = await getPackageFromSource({
pkgName,
pkgVersion,
pkgVersion: responsePkgVersion,
savedObjectsClient,
installedPkg: savedObject?.attributes,
});
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/fleet/server/services/epm/registry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ test('testPathParts', () => {
});

describe('splitPkgKey tests', () => {
it('throws an error if the delimiter is not found', () => {
expect(() => {
splitPkgKey('awesome_package');
}).toThrow();
});

it('throws an error if there is nothing before the delimiter', () => {
expect(() => {
splitPkgKey('-0.0.1-dev1');
Expand All @@ -71,6 +65,12 @@ describe('splitPkgKey tests', () => {
}).toThrow();
});

it('returns name and empty version if no delimiter is found', () => {
const { pkgName, pkgVersion } = splitPkgKey('awesome_package');
expect(pkgName).toBe('awesome_package');
expect(pkgVersion).toBe('');
});

it('returns the name and version if the delimiter is found once', () => {
const { pkgName, pkgVersion } = splitPkgKey('awesome-0.1.0');
expect(pkgName).toBe('awesome');
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/fleet/server/services/epm/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ export interface SearchParams {
* @param pkgkey a string containing the package name delimited by the package version
*/
export function splitPkgKey(pkgkey: string): { pkgName: string; pkgVersion: string } {
// this will return an empty string if `indexOf` returns -1
const pkgName = pkgkey.substr(0, pkgkey.indexOf('-'));
// If no version is provided, use the provided package key as the
// package name and return an empty version value
if (!pkgkey.includes('-')) {
return { pkgName: pkgkey, pkgVersion: '' };
}

const pkgName = pkgkey.includes('-') ? pkgkey.substr(0, pkgkey.indexOf('-')) : pkgkey;

if (pkgName === '') {
throw new PackageKeyInvalidError('Package key parsing failed: package name was empty');
}
Expand Down