mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fixing the generator to use bulk api to install endpoint package (#103094)
This commit is contained in:
parent
5b0d325d7e
commit
28162810ad
1 changed files with 43 additions and 1 deletions
|
@ -15,9 +15,16 @@ import { KbnClient } from '@kbn/test';
|
|||
import { AxiosResponse } from 'axios';
|
||||
import { indexHostsAndAlerts } from '../../common/endpoint/index_data';
|
||||
import { ANCESTRY_LIMIT, EndpointDocGenerator } from '../../common/endpoint/generate_data';
|
||||
import { AGENTS_SETUP_API_ROUTES, SETUP_API_ROUTE } from '../../../fleet/common/constants';
|
||||
import {
|
||||
AGENTS_SETUP_API_ROUTES,
|
||||
EPM_API_ROUTES,
|
||||
SETUP_API_ROUTE,
|
||||
} from '../../../fleet/common/constants';
|
||||
import {
|
||||
BulkInstallPackageInfo,
|
||||
BulkInstallPackagesResponse,
|
||||
CreateFleetSetupResponse,
|
||||
IBulkInstallPackageHTTPError,
|
||||
PostIngestSetupResponse,
|
||||
} from '../../../fleet/common/types/rest_spec';
|
||||
import { KbnClientWithApiKeySupport } from './kbn_client_with_api_key_support';
|
||||
|
@ -44,6 +51,12 @@ async function deleteIndices(indices: string[], client: Client) {
|
|||
}
|
||||
}
|
||||
|
||||
function isFleetBulkInstallError(
|
||||
installResponse: BulkInstallPackageInfo | IBulkInstallPackageHTTPError
|
||||
): installResponse is IBulkInstallPackageHTTPError {
|
||||
return 'error' in installResponse && installResponse.error !== undefined;
|
||||
}
|
||||
|
||||
async function doIngestSetup(kbnClient: KbnClient) {
|
||||
// Setup Ingest
|
||||
try {
|
||||
|
@ -76,6 +89,35 @@ async function doIngestSetup(kbnClient: KbnClient) {
|
|||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Install/upgrade the endpoint package
|
||||
try {
|
||||
const installEndpointPackageResp = (await kbnClient.request({
|
||||
path: EPM_API_ROUTES.BULK_INSTALL_PATTERN,
|
||||
method: 'POST',
|
||||
body: {
|
||||
packages: ['endpoint'],
|
||||
},
|
||||
})) as AxiosResponse<BulkInstallPackagesResponse>;
|
||||
|
||||
const bulkResp = installEndpointPackageResp.data.response;
|
||||
if (bulkResp.length <= 0) {
|
||||
throw new Error('Installing the Endpoint package failed, response was empty, existing');
|
||||
}
|
||||
|
||||
if (isFleetBulkInstallError(bulkResp[0])) {
|
||||
if (bulkResp[0].error instanceof Error) {
|
||||
throw new Error(
|
||||
`Installing the Endpoint package failed: ${bulkResp[0].error.message}, exiting`
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(bulkResp[0].error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue