Skip to content

Commit

Permalink
[Cloud Security][Fleet] fix broken k8s manifest link (#167059)
Browse files Browse the repository at this point in the history
## Summary

fixes:
- #166931

The issue was introduced in
https://github.com/elastic/kibana/pull/165127/files#diff-276f84c47e09954d668b83d633d87edc09406b69603dac7e63964b70e2342af1R120

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
maxcold authored and pull[bot] committed Sep 29, 2023
1 parent a5da2ff commit 61c5ac8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
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

0 comments on commit 61c5ac8

Please sign in to comment.