Skip to content

Commit

Permalink
[Cloud Security] fix agent version on cloudformation template in Clou…
Browse files Browse the repository at this point in the history
…d Security integrations (#166485)

## Summary

fixes
- elastic/security-team#7557

using the new `useAgentVersion` hook to get the agent version to prefill
in the Cloudformation template

There is already a PR with the same fix
#166198 but as it also changes the
logic of `useAgentVersion` itself, it might take some time to align.
This PR only fixes the immediate issue we have in Serverless
  • Loading branch information
maxcold committed Sep 18, 2023
1 parent c486443 commit fb2533e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
CloudSecurityIntegrationAwsAccountType,
} from '../components/agent_enrollment_flyout/types';

import { useKibanaVersion } from './use_kibana_version';
import { useAgentVersion } from './use_agent_version';
import { useGetSettings } from './use_request';

const CLOUD_FORMATION_DEFAULT_ACCOUNT_TYPE = 'single-account';
Expand All @@ -26,7 +26,7 @@ export const useCreateCloudFormationUrl = ({
}) => {
const { data, isLoading } = useGetSettings();

const kibanaVersion = useKibanaVersion();
const agentVersion = useAgentVersion();

let isError = false;
let error: string | undefined;
Expand All @@ -49,12 +49,12 @@ export const useCreateCloudFormationUrl = ({
}

const cloudFormationUrl =
enrollmentAPIKey && fleetServerHost && cloudFormationProps?.templateUrl
enrollmentAPIKey && fleetServerHost && cloudFormationProps?.templateUrl && agentVersion
? createCloudFormationUrl(
cloudFormationProps?.templateUrl,
enrollmentAPIKey,
fleetServerHost,
kibanaVersion,
agentVersion,
cloudFormationProps?.awsAccountType
)
: undefined;
Expand All @@ -71,15 +71,18 @@ const createCloudFormationUrl = (
templateURL: string,
enrollmentToken: string,
fleetUrl: string,
kibanaVersion: string,
agentVersion: string,
awsAccountType: CloudSecurityIntegrationAwsAccountType | undefined
) => {
let cloudFormationUrl;

/*
template url has `&param_ElasticAgentVersion=KIBANA_VERSION` part. KIBANA_VERSION is used for templating as agent version used to match Kibana version, but now it's not necessarily the case
*/
cloudFormationUrl = templateURL
.replace('FLEET_ENROLLMENT_TOKEN', enrollmentToken)
.replace('FLEET_URL', fleetUrl)
.replace('KIBANA_VERSION', kibanaVersion);
.replace('KIBANA_VERSION', agentVersion);

if (cloudFormationUrl.includes('ACCOUNT_TYPE')) {
cloudFormationUrl = cloudFormationUrl.replace(
Expand Down

0 comments on commit fb2533e

Please sign in to comment.