Add package name to install package response (#221038)

Resolves: https://github.com/elastic/kibana/issues/185932

- Adds a `name` field to the `_meta` object of
`InstallPackageResponseSchema`, which represents the package name.

This addition will appear in the responses for:
- Install from registry: POST
`/api/fleet/epm/packages/<pkgName>/<version?>`
- Install by upload: POST `/api/fleet/epm/packages`
- Create custom integration: POST `/api/fleet/epm/custom_integrations`
This commit is contained in:
Michel Losier 2025-05-21 08:29:33 -07:00 committed by GitHub
parent f4f65561f0
commit b75fdb24ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 80 additions and 15 deletions

View file

@ -24202,10 +24202,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},
@ -25197,10 +25201,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},
@ -26957,10 +26965,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},

View file

@ -24202,10 +24202,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},
@ -25197,10 +25201,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},
@ -26957,10 +26965,14 @@
"properties": {
"install_source": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"install_source"
"install_source",
"name"
],
"type": "object"
},

View file

@ -25781,8 +25781,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:
@ -26451,8 +26454,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:
@ -27376,8 +27382,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:

View file

@ -28023,8 +28023,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:
@ -28693,8 +28696,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:
@ -29618,8 +29624,11 @@ paths:
properties:
install_source:
type: string
name:
type: string
required:
- install_source
- name
items:
items:
anyOf:

View file

@ -130,6 +130,7 @@ export interface InstallPackageResponse {
items: AssetReference[];
_meta: {
install_source: InstallSource;
name: string;
};
}
@ -145,12 +146,13 @@ export interface InstallResult {
error?: Error;
installType: InstallType;
installSource?: InstallSource;
pkgName: string;
}
export interface BulkInstallPackageInfo {
name: string;
version: string;
result: InstallResult;
result: Omit<InstallResult, 'pkgName'>;
}
export interface BulkInstallPackagesResponse {

View file

@ -326,6 +326,7 @@ export const installPackageFromRegistryHandler: FleetRequestHandler<
items: res.assets || [],
_meta: {
install_source: res.installSource ?? installSource,
name: pkgName,
},
};
return response.ok({ body });
@ -367,6 +368,7 @@ export const createCustomIntegrationHandler: FleetRequestHandler<
items: res.assets || [],
_meta: {
install_source: res.installSource ?? installSource,
name: integrationName,
},
};
return response.ok({ body });
@ -493,6 +495,7 @@ export const installPackageByUploadHandler: FleetRequestHandler<
items: res.assets || [],
_meta: {
install_source: res.installSource ?? installSource,
name: res.pkgName,
},
};
return response.ok({ body });

View file

@ -601,6 +601,7 @@ describe('schema validation', () => {
],
_meta: {
install_source: 'registry',
name: 'test',
},
};
(installPackageFromRegistryHandler as jest.Mock).mockImplementation((ctx, request, res) => {

View file

@ -155,10 +155,13 @@ export async function bulkInstallPackages({
installType: installResult.installType,
};
}
const { pkgName, ...restOfInstallResult } = installResult;
return {
name: packageName,
version: pkgKeyProps.version,
result: installResult,
result: restOfInstallResult,
};
})
);

View file

@ -568,6 +568,7 @@ async function installPackageFromRegistry({
error: e,
installType,
installSource,
pkgName,
};
}
}
@ -668,6 +669,7 @@ export async function installPackageWithStateMachine(options: {
status: 'already_installed',
installType,
installSource,
pkgName,
};
}
}
@ -679,7 +681,7 @@ export async function installPackageWithStateMachine(options: {
...telemetryEvent,
errorMessage: err.message,
});
return { error: err, installType, installSource };
return { error: err, installType, installSource, pkgName };
}
// Saved object client need to be scopped with the package space for saved object tagging
@ -722,14 +724,20 @@ export async function installPackageWithStateMachine(options: {
logger.debug(`Removing old assets from previous versions of ${pkgName}`);
await removeOldAssets({
soClient: savedObjectsClient,
pkgName: packageInfo.name,
pkgName,
currentVersion: packageInfo.version,
});
sendEvent({
...telemetryEvent!,
status: 'success',
});
return { assets, status: 'installed' as InstallResultStatus, installType, installSource };
return {
assets,
status: 'installed' as InstallResultStatus,
installType,
installSource,
pkgName,
};
})
.catch(async (err: Error) => {
logger.warn(`Failure to install package [${pkgName}]: [${err.toString()}]`, {
@ -750,7 +758,7 @@ export async function installPackageWithStateMachine(options: {
...telemetryEvent!,
errorMessage: err.message,
});
return { error: err, installType, installSource };
return { error: err, installType, installSource, pkgName };
});
} catch (e) {
sendEvent({
@ -761,6 +769,7 @@ export async function installPackageWithStateMachine(options: {
error: e,
installType,
installSource,
pkgName,
};
} finally {
span?.end();
@ -784,6 +793,7 @@ async function installPackageByUpload({
// if an error happens during getInstallType, report that we don't know
let installType: InstallType = 'unknown';
let pkgName = 'unknown';
const installSource = isBundledPackage ? 'bundled' : 'upload';
const timeToWaitString = moment
@ -806,7 +816,7 @@ async function installPackageByUpload({
}
}
const { packageInfo } = await generatePackageInfoFromArchiveBuffer(archiveBuffer, contentType);
const pkgName = packageInfo.name;
pkgName = packageInfo.name;
const useStreaming = PACKAGES_TO_INSTALL_WITH_STREAMING.includes(pkgName);
// Allow for overriding the version in the manifest for cases where we install
@ -825,7 +835,7 @@ async function installPackageByUpload({
deleteVerificationResult(packageInfo);
setPackageInfo({
name: packageInfo.name,
name: pkgName,
version: pkgVersion,
packageInfo,
});
@ -866,6 +876,7 @@ async function installPackageByUpload({
error: e,
installType,
installSource,
pkgName,
};
}
}

View file

@ -156,6 +156,7 @@ jest.mock('./epm/packages/install', () => ({
error: new Error(installError),
installType: 'install',
installSource: 'registry',
pkgName,
};
}
@ -171,6 +172,7 @@ jest.mock('./epm/packages/install', () => ({
status: 'installed',
installType: 'install',
installSource: 'registry',
pkgName,
};
} else if (args.installSource === 'upload') {
const { archiveBuffer } = args;
@ -182,7 +184,7 @@ jest.mock('./epm/packages/install', () => ({
const packageInstallation = { name: pkgName, version: '1.0.0', title: pkgName };
mockInstalledPackages.set(pkgName, packageInstallation);
return { status: 'installed', installType: 'install', installSource: 'upload' };
return { status: 'installed', installType: 'install', installSource: 'upload', pkgName };
}
}
),

View file

@ -337,6 +337,7 @@ export const InstallPackageResponseSchema = schema.object({
items: schema.arrayOf(AssetReferenceSchema),
_meta: schema.object({
install_source: schema.string(),
name: schema.string(),
}),
});