diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.test.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.test.tsx new file mode 100644 index 0000000000000..9eab4d3e0c99a --- /dev/null +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.test.tsx @@ -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' + ); + }); +}); diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.tsx index 8125cdb4acf35..a44b7ab4020e9 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/kubernetes_instructions.tsx @@ -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 = ({ enrollmentAPIKey, onCopy, @@ -111,13 +120,8 @@ export const KubernetesInstructions: React.FunctionComponent = ({ ); - 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 = (