Skip to content

Commit

Permalink
Merge branch 'main' into 162299-fix-test
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi authored Sep 25, 2023
2 parents e1b1427 + 9cbd597 commit 944ab3c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dev/build/tasks/fleet/download_elastic_gpg_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { downloadToDisk } from '../../lib';
const ARTIFACTS_URL = 'https://artifacts.elastic.co/';
const GPG_KEY_NAME = 'GPG-KEY-elasticsearch';
const GPG_KEY_SHA512 =
'84ee193cc337344d9a7da9021daf3f5ede83f5f1ab049d169f3634921529dcd096abf7a91eec7f26f3a6913e5e38f88f69a5e2ce79ad155d46edc75705a648c6';
'62a567354286deb02baf5fc6b82ddf6c7067898723463da9ae65b132b8c6d6f064b2874e390885682376228eed166c1c82fe7f11f6c9a69f0c157029c548fa3d';

export async function downloadElasticGpgKey(pkgDir: string, log: ToolingLog) {
const gpgKeyUrl = ARTIFACTS_URL + GPG_KEY_NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { getManifestDownloadLink } from './kubernetes_instructions';

describe('getManifestDownloadLink', () => {
it('should return the correct link', () => {
expect(getManifestDownloadLink('https://fleet.host', 'enrollmentToken')).toEqual(
'/api/fleet/kubernetes/download?fleetServer=https%3A%2F%2Ffleet.host&enrolToken=enrollmentToken'
);
expect(getManifestDownloadLink('https://fleet.host')).toEqual(
'/api/fleet/kubernetes/download?fleetServer=https%3A%2F%2Ffleet.host'
);
expect(getManifestDownloadLink(undefined, 'enrollmentToken')).toEqual(
'/api/fleet/kubernetes/download?enrolToken=enrollmentToken'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ interface Props {
fleetServerHost?: string;
}

export const getManifestDownloadLink = (fleetServerHost?: string, enrollmentAPIKey?: string) => {
const searchParams = new URLSearchParams({
...(fleetServerHost && { fleetServer: fleetServerHost }),
...(enrollmentAPIKey && { enrolToken: enrollmentAPIKey }),
});

return `${agentPolicyRouteService.getK8sFullDownloadPath()}?${searchParams.toString()}`;
};

export const KubernetesInstructions: React.FunctionComponent<Props> = ({
enrollmentAPIKey,
onCopy,
Expand Down Expand Up @@ -111,13 +120,8 @@ export const KubernetesInstructions: React.FunctionComponent<Props> = ({
</EuiCopy>
);

const searchParams = new URLSearchParams({
...(fleetServerHost && { fleetServer: fleetServerHost }),
...(enrollmentAPIKey && { enrolToken: enrollmentAPIKey }),
});

const downloadLink = core.http.basePath.prepend(
`${agentPolicyRouteService.getK8sFullDownloadPath()}${searchParams.toString()}`
getManifestDownloadLink(fleetServerHost, enrollmentAPIKey)
);

const k8sDownloadYaml = (
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/profiling_data_access/common/fleet_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { SavedObjectsClientContract } from '@kbn/core/server';
import type { PackagePolicyClient } from '@kbn/fleet-plugin/server';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE, PackagePolicy } from '@kbn/fleet-plugin/common';
import { getApmPolicy } from './get_apm_policy';
import { PartialSetupState, ProfilingSetupOptions } from './setup';

Expand All @@ -21,9 +22,11 @@ async function getPackagePolicy({
packagePolicyClient: PackagePolicyClient;
soClient: SavedObjectsClientContract;
packageName: string;
}) {
const packagePolicies = await packagePolicyClient.list(soClient, {});
return packagePolicies.items.find((pkg) => pkg.name === packageName);
}): Promise<PackagePolicy | undefined> {
const packagePolicies = await packagePolicyClient.list(soClient, {
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:${packageName}`,
});
return packagePolicies.items[0];
}

export async function getCollectorPolicy({
Expand Down

0 comments on commit 944ab3c

Please sign in to comment.