Skip to content

Commit

Permalink
[Fleet] [Cloud Security] Show only ColudFormation deployment option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloh authored May 15, 2023
1 parent d184362 commit 3ea70e0
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ function getArtifact(platform: PLATFORM_TYPE, kibanaVersion: string) {
kubernetes: {
downloadCommand: '',
},
cloudFormation: {
downloadCommand: '',
},
};

return artifactMap[platform];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { EuiButton, EuiSpacer, EuiCallOut, EuiSkeletonText } from '@elastic/eui';
import { EuiButton, EuiSpacer, EuiCallOut, EuiSkeletonText, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';

Expand Down Expand Up @@ -91,15 +91,12 @@ export const CloudFormationInstructions: React.FunctionComponent<Props> = ({
}
)}
>
<EuiSpacer size="m" />
<EuiCallOut
title={i18n.translate('xpack.fleet.agentEnrollment.cloudFormation.callout', {
defaultMessage:
'Sign in to your AWS cloud provider account, and switch to the region that you want to scan, then click Launch CloudFormation.',
})}
color="warning"
iconType="warning"
/>
<EuiText>
<FormattedMessage
id="xpack.fleet.agentEnrollment.cloudFormation.instructions"
defaultMessage="Sign in to your AWS cloud provider account, and switch to the region that you want to scan, then click Launch CloudFormation."
/>
</EuiText>
<EuiSpacer size="m" />
<EuiButton
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { FleetServerRequirementPage } from '../../applications/fleet/sections/ag
import { AGENTS_PREFIX, FLEET_SERVER_PACKAGE, SO_SEARCH_LIMIT } from '../../constants';
import { useFleetServerUnhealthy } from '../../applications/fleet/sections/agents/hooks/use_fleet_server_unhealthy';
import { Loading } from '..';
import { policyHasFleetServer } from '../../services';
import {
getCloudFormationTemplateUrlFromPackagePolicy,
policyHasFleetServer,
} from '../../services';
import { AdvancedTab } from '../../applications/fleet/components/fleet_server_instructions/advanced_tab';

import type { InstructionProps } from './types';
Expand Down Expand Up @@ -78,13 +81,21 @@ export const Instructions = (props: InstructionProps) => {
(fleetServers.length === 0 ||
isFleetServerUnhealthy ||
(fleetStatus.missingRequirements ?? []).some((r) => r === FLEET_SERVER_PACKAGE));

const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(
props.selectedPolicy
);

useEffect(() => {
if (!isIntegrationFlow && showAgentEnrollment) {
// If we have a cloudFormationTemplateUrl, we want to hide the selection type
if (cloudFormationTemplateUrl) {
setSelectionType(undefined);
} else if (!isIntegrationFlow && showAgentEnrollment) {
setSelectionType('radio');
} else {
setSelectionType('tabs');
}
}, [isIntegrationFlow, showAgentEnrollment, setSelectionType]);
}, [isIntegrationFlow, showAgentEnrollment, setSelectionType, cloudFormationTemplateUrl]);

if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth)
return <Loading size="l" />;
Expand Down Expand Up @@ -113,7 +124,7 @@ export const Instructions = (props: InstructionProps) => {
{isFleetServerPolicySelected ? (
<AdvancedTab selectedPolicyId={props.selectedPolicy?.id} onClose={() => undefined} />
) : (
<ManagedSteps {...props} />
<ManagedSteps {...props} cloudFormationTemplateUrl={cloudFormationTemplateUrl} />
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/st

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

import {
fullAgentPolicyToYaml,
agentPolicyRouteService,
getCloudFormationTemplateUrlFromPackagePolicy,
} from '../../../services';
import { fullAgentPolicyToYaml, agentPolicyRouteService } from '../../../services';

import { StandaloneInstructions, ManualInstructions } from '../../enrollment_instructions';

Expand All @@ -40,6 +36,7 @@ import {
ConfigureStandaloneAgentStep,
AgentEnrollmentConfirmationStep,
InstallManagedAgentStep,
InstallCloudFormationManagedAgentStep,
IncomingDataConfirmationStep,
} from '.';

Expand Down Expand Up @@ -199,6 +196,7 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
onClickViewAgents,
isK8s,
installedPackagePolicy,
cloudFormationTemplateUrl,
}) => {
const kibanaVersion = useKibanaVersion();
const core = useStartServices();
Expand All @@ -220,8 +218,6 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
});

const instructionsSteps = useMemo(() => {
const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(selectedPolicy);

const steps: EuiContainedStepProps[] = !agentPolicy
? [
AgentPolicySelectionStep({
Expand All @@ -247,16 +243,27 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
);
}

steps.push(
InstallManagedAgentStep({
installCommand: installManagedCommands,
apiKeyData,
selectedApiKeyId,
isK8s,
enrollToken,
cloudFormationTemplateUrl,
})
);
if (cloudFormationTemplateUrl) {
steps.push(
InstallCloudFormationManagedAgentStep({
apiKeyData,
selectedApiKeyId,
enrollToken,
cloudFormationTemplateUrl,
})
);
} else {
steps.push(
InstallManagedAgentStep({
installCommand: installManagedCommands,
apiKeyData,
selectedApiKeyId,
isK8s,
enrollToken,
})
);
}

if (selectedApiKeyId && apiKeyData) {
steps.push(
AgentEnrollmentConfirmationStep({
Expand Down Expand Up @@ -300,6 +307,7 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
link,
agentDataConfirmed,
installedPackagePolicy,
cloudFormationTemplateUrl,
]);

return <EuiSteps steps={instructionsSteps} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './agent_enrollment_key_selection_step';
export * from './agent_policy_selection_step';
export * from './configure_standalone_agent_step';
export * from './incoming_data_confirmation_step';
export * from './install_cloud_formation_managed_agent_step';
export * from './install_managed_agent_step';
export * from './install_standalone_agent_step';
export * from './installation_mode_selection_step';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 React from 'react';

import { i18n } from '@kbn/i18n';

import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';

import type { GetOneEnrollmentAPIKeyResponse } from '../../../../common/types/rest_spec/enrollment_api_key';

import { CloudFormationInstructions } from '../cloud_formation_instructions';

export const InstallCloudFormationManagedAgentStep = ({
selectedApiKeyId,
apiKeyData,
enrollToken,
isComplete,
cloudFormationTemplateUrl,
}: {
selectedApiKeyId?: string;
apiKeyData?: GetOneEnrollmentAPIKeyResponse | null;
enrollToken?: string;
isComplete?: boolean;
cloudFormationTemplateUrl: string;
}): EuiContainedStepProps => {
const nonCompleteStatus = selectedApiKeyId ? undefined : 'disabled';
const status = isComplete ? 'complete' : nonCompleteStatus;
return {
status,
title: i18n.translate('xpack.fleet.agentEnrollment.cloudFormation.stepEnrollAndRunAgentTitle', {
defaultMessage: 'Install Elastic Agent on your cloud',
}),
children:
selectedApiKeyId && apiKeyData ? (
<CloudFormationInstructions
cloudFormationTemplateUrl={cloudFormationTemplateUrl}
enrollmentAPIKey={enrollToken}
/>
) : (
<React.Fragment />
),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const InstallManagedAgentStep = ({
isComplete,
fullCopyButton,
onCopy,
cloudFormationTemplateUrl,
}: {
selectedApiKeyId?: string;
apiKeyData?: GetOneEnrollmentAPIKeyResponse | null;
Expand All @@ -37,7 +36,6 @@ export const InstallManagedAgentStep = ({
isComplete?: boolean;
fullCopyButton?: boolean;
onCopy?: () => void;
cloudFormationTemplateUrl?: string | null;
}): EuiContainedStepProps => {
const nonCompleteStatus = selectedApiKeyId ? undefined : 'disabled';
const status = isComplete ? 'complete' : nonCompleteStatus;
Expand All @@ -54,7 +52,6 @@ export const InstallManagedAgentStep = ({
enrollToken={enrollToken}
onCopy={onCopy}
fullCopyButton={fullCopyButton}
cloudFormationTemplateUrl={cloudFormationTemplateUrl}
/>
) : (
<React.Fragment />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ export interface InstructionProps extends BaseProps {
setSelectedAPIKeyId: (key?: string) => void;
fleetServerHosts: string[];
fleetProxy?: FleetProxy;
cloudFormationTemplateUrl?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface Props {
fullCopyButton?: boolean;
isManaged?: boolean;
onCopy?: () => void;
cloudFormationTemplateUrl?: string | null;
}

export const InstallSection: React.FunctionComponent<Props> = ({
Expand All @@ -31,7 +30,6 @@ export const InstallSection: React.FunctionComponent<Props> = ({
fullCopyButton = false,
isManaged = true,
onCopy,
cloudFormationTemplateUrl,
}) => {
return (
<>
Expand All @@ -49,7 +47,6 @@ export const InstallSection: React.FunctionComponent<Props> = ({
hasK8sIntegrationMultiPage={isK8s === 'IS_KUBERNETES_MULTIPAGE'}
isManaged={isManaged}
enrollToken={enrollToken}
cloudFormationTemplateUrl={cloudFormationTemplateUrl}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ cd elastic-agent-${kibanaVersion}-windows-x86_64
deb: linuxDebCommand,
rpm: linuxRpmCommand,
kubernetes: k8sCommand,
cloudFormation: '',
};
};
27 changes: 4 additions & 23 deletions x-pack/plugins/fleet/public/components/platform_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { CLOUD_FORMATION_PLATFORM_OPTION, type PLATFORM_TYPE } from '../hooks';
import { type PLATFORM_TYPE } from '../hooks';
import { REDUCED_PLATFORM_OPTIONS, PLATFORM_OPTIONS, usePlatform } from '../hooks';

import { KubernetesInstructions } from './agent_enrollment_flyout/kubernetes_instructions';
import { CloudFormationInstructions } from './agent_enrollment_flyout/cloud_formation_instructions';

interface Props {
linuxCommand: string;
Expand All @@ -39,7 +38,6 @@ interface Props {
enrollToken?: string | undefined;
fullCopyButton?: boolean;
onCopy?: () => void;
cloudFormationTemplateUrl?: string | null;
}

// Otherwise the copy button is over the text
Expand All @@ -61,15 +59,12 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
hasFleetServer,
fullCopyButton,
onCopy,
cloudFormationTemplateUrl,
}) => {
const getInitialPlatform = useCallback(() => {
if (cloudFormationTemplateUrl) return 'cloudFormation';

if (hasK8sIntegration) return 'kubernetes';

return 'linux';
}, [cloudFormationTemplateUrl, hasK8sIntegration]);
}, [hasK8sIntegration]);

const { platform, setPlatform } = usePlatform(getInitialPlatform());

Expand All @@ -80,12 +75,8 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
const getPlatformOptions = useCallback(() => {
const platformOptions = isReduced ? REDUCED_PLATFORM_OPTIONS : PLATFORM_OPTIONS;

if (cloudFormationTemplateUrl) {
return platformOptions.concat(CLOUD_FORMATION_PLATFORM_OPTION);
}

return platformOptions;
}, [cloudFormationTemplateUrl, isReduced]);
}, [isReduced]);

const [copyButtonClicked, setCopyButtonClicked] = useState(false);

Expand Down Expand Up @@ -118,7 +109,6 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
deb: linuxDebCommand,
rpm: linuxRpmCommand,
kubernetes: k8sCommand,
cloudFormation: '',
};
const onTextAreaClick = () => {
if (onCopy) onCopy();
Expand Down Expand Up @@ -165,16 +155,7 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
<EuiSpacer size="s" />
</>
)}
{platform === 'cloudFormation' && cloudFormationTemplateUrl && (
<>
<CloudFormationInstructions
cloudFormationTemplateUrl={cloudFormationTemplateUrl}
enrollmentAPIKey={enrollToken}
/>
<EuiSpacer size="s" />
</>
)}
{!hasK8sIntegrationMultiPage && platform !== 'cloudFormation' && (
{!hasK8sIntegrationMultiPage && (
<>
{platform === 'kubernetes' && (
<EuiText>
Expand Down
17 changes: 1 addition & 16 deletions x-pack/plugins/fleet/public/hooks/use_platform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
import { useState } from 'react';
import { i18n } from '@kbn/i18n';

export type PLATFORM_TYPE =
| 'linux'
| 'mac'
| 'windows'
| 'rpm'
| 'deb'
| 'kubernetes'
| 'cloudFormation';
export type PLATFORM_TYPE = 'linux' | 'mac' | 'windows' | 'rpm' | 'deb' | 'kubernetes';

export const REDUCED_PLATFORM_OPTIONS: Array<{
label: string;
Expand Down Expand Up @@ -59,14 +52,6 @@ export const REDUCED_PLATFORM_OPTIONS: Array<{
},
];

export const CLOUD_FORMATION_PLATFORM_OPTION = {
id: 'cloudFormation',
label: i18n.translate('xpack.fleet.enrollmentInstructions.platformButtons.cloudFormation', {
defaultMessage: 'CloudFormation',
}),
'data-test-subj': 'platformTypeCloudFormation',
};

export const PLATFORM_OPTIONS = [
...REDUCED_PLATFORM_OPTIONS,
{
Expand Down

0 comments on commit 3ea70e0

Please sign in to comment.