-
Notifications
You must be signed in to change notification settings - Fork 8k
/
get_latest_apm_package.ts
39 lines (37 loc) · 1.26 KB
/
get_latest_apm_package.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { KibanaRequest } from '@kbn/core/server';
import { APMPluginStartDependencies } from '../../types';
import { APM_PACKAGE_NAME } from './get_cloud_apm_package_policy';
export async function getLatestApmPackage({
fleetPluginStart,
request,
}: {
fleetPluginStart: NonNullable<APMPluginStartDependencies['fleet']>;
request: KibanaRequest;
}) {
const packageClient = fleetPluginStart.packageService.asScoped(request);
const latestPackage = await packageClient.fetchFindLatestPackage(
APM_PACKAGE_NAME
);
const packageInfo =
'buffer' in latestPackage
? (await packageClient.readBundledPackage(latestPackage)).packageInfo
: latestPackage;
const {
name,
version,
title,
policy_templates: policyTemplates,
} = packageInfo;
const firstTemplate = policyTemplates?.[0];
const policyTemplateInputVars =
firstTemplate && 'inputs' in firstTemplate
? firstTemplate.inputs?.[0].vars || []
: [];
return { package: { name, version, title }, policyTemplateInputVars };
}