Skip to content

Commit

Permalink
[Fleet] Allow to download policy and manifest with version in queryst…
Browse files Browse the repository at this point in the history
…ring (#170987)
  • Loading branch information
nchaulet authored Nov 10, 2023
1 parent 45a160b commit b086208
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { useGetOneAgentPolicyFull, useGetOneAgentPolicy, useStartServices } from '../../../hooks';
import { Loading } from '../../../components';
import { fullAgentPolicyToYaml, agentPolicyRouteService } from '../../../services';
import { API_VERSIONS } from '../../../../../../common/constants';

const FlyoutBody = styled(EuiFlyoutBody)`
.euiFlyoutBody__overflowContent {
Expand Down Expand Up @@ -65,9 +66,9 @@ export const AgentPolicyYamlFlyout = memo<{ policyId: string; onClose: () => voi
</>
);

const downloadLink = core.http.basePath.prepend(
agentPolicyRouteService.getInfoFullDownloadPath(policyId)
);
const downloadLink =
core.http.basePath.prepend(agentPolicyRouteService.getInfoFullDownloadPath(policyId)) +
`?apiVersion=${API_VERSIONS.public.v1}`;

return (
<EuiFlyout onClose={onClose} size="l" maxWidth={640}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EuiSteps, EuiSpacer } from '@elastic/eui';
import { safeDump } from 'js-yaml';

import type { FullAgentPolicy } from '../../../../../../../../../../common/types/models/agent_policy';

import { API_VERSIONS } from '../../../../../../../../../../common/constants';
import {
AgentStandaloneBottomBar,
StandaloneModeWarningCallout,
Expand Down Expand Up @@ -95,7 +95,9 @@ export const InstallElasticAgentStandalonePageStep: React.FC<InstallAgentPagePro
const installManagedCommands = StandaloneInstructions(kibanaVersion);

const downloadLink = core.http.basePath.prepend(
`${agentPolicyRouteService.getInfoFullDownloadPath(agentPolicy?.id)}?standalone=true`
`${agentPolicyRouteService.getInfoFullDownloadPath(
agentPolicy?.id
)}?standalone=true&apiVersion=${API_VERSIONS.public.v1}`
);
const steps = [
ConfigureStandaloneAgentStep({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ 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'
'/api/fleet/kubernetes/download?apiVersion=2023-10-31&fleetServer=https%3A%2F%2Ffleet.host&enrolToken=enrollmentToken'
);
expect(getManifestDownloadLink('https://fleet.host')).toEqual(
'/api/fleet/kubernetes/download?fleetServer=https%3A%2F%2Ffleet.host'
'/api/fleet/kubernetes/download?apiVersion=2023-10-31&fleetServer=https%3A%2F%2Ffleet.host'
);
expect(getManifestDownloadLink(undefined, 'enrollmentToken')).toEqual(
'/api/fleet/kubernetes/download?enrolToken=enrollmentToken'
'/api/fleet/kubernetes/download?apiVersion=2023-10-31&enrolToken=enrollmentToken'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n';

import { useStartServices } from '../../hooks';

import { agentPolicyRouteService } from '../../../common';
import { agentPolicyRouteService, API_VERSIONS } from '../../../common';

import { sendGetK8sManifest } from '../../hooks/use_request/k8s';

Expand All @@ -33,6 +33,7 @@ interface Props {

export const getManifestDownloadLink = (fleetServerHost?: string, enrollmentAPIKey?: string) => {
const searchParams = new URLSearchParams({
apiVersion: API_VERSIONS.public.v1,
...(fleetServerHost && { fleetServer: fleetServerHost }),
...(enrollmentAPIKey && { enrolToken: enrollmentAPIKey }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { safeDump } from 'js-yaml';
import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';

import type { FullAgentPolicy } from '../../../../common/types/models/agent_policy';

import { API_VERSIONS } from '../../../../common/constants';
import {
fullAgentPolicyToYaml,
agentPolicyRouteService,
Expand Down Expand Up @@ -73,10 +73,12 @@ export const StandaloneSteps: React.FunctionComponent<InstructionProps> = ({
? core.http.basePath.prepend(
`${agentPolicyRouteService.getInfoFullDownloadPath(
selectedPolicy?.id
)}?kubernetes=true&standalone=true`
)}?kubernetes=true&standalone=true&apiVersion=${API_VERSIONS.public.v1}`
)
: core.http.basePath.prepend(
`${agentPolicyRouteService.getInfoFullDownloadPath(selectedPolicy?.id)}?standalone=true`
`${agentPolicyRouteService.getInfoFullDownloadPath(
selectedPolicy?.id
)}?standalone=true&apiVersion=${API_VERSIONS.public.v1}`
);
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/server/routes/agent_policy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
fleetAuthz: {
fleet: { all: true },
},
enableQueryVersion: true,
})
.addVersion(
{
Expand Down Expand Up @@ -206,6 +207,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
fleetAuthz: {
fleet: { all: true },
},
enableQueryVersion: true,
})
.addVersion(
{
Expand Down

0 comments on commit b086208

Please sign in to comment.