Skip to content

Commit

Permalink
pr comments + refactor cloudformation url to be included on cspObject
Browse files Browse the repository at this point in the history
  • Loading branch information
animehart committed May 16, 2023
1 parent 74790cd commit d329d70
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ import {
FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE,
FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE,
} from '../../../common';
import { getCloudFormationTemplateUrlFromPackagePolicy } from '../../services';

import type { K8sMode, CSPMode } from './types';

interface CSPObject {
status: CSPMode;
cloudformationUrl: string;
}
import type { K8sMode, CSPObject } from './types';

// Packages that requires custom elastic-agent manifest
const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]);
Expand Down Expand Up @@ -83,16 +79,20 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) {
return;
}

const pkgArray = agentPolicy?.package_policies?.map((e) => isCSPPackage(e));
const cspPackageObj = agentPolicy?.package_policies?.map((pkgPolicy) =>
getCSPPackageType(pkgPolicy)
);

const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(agentPolicy);

if (pkgArray?.includes('IS_CSP_KSPM')) {
setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: 'PlaceHolder' });
} else if (pkgArray?.includes('IS_CSP_CSPM')) {
setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: 'PlaceHolder' });
} else if (pkgArray?.includes('IS_CSP_CNVM')) {
setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: 'PlaceHolder' });
if (cspPackageObj?.includes('IS_CSP_KSPM')) {
setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: cloudFormationTemplateUrl });
} else if (cspPackageObj?.includes('IS_CSP_CSPM')) {
setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: cloudFormationTemplateUrl });
} else if (cspPackageObj?.includes('IS_CSP_CNVM')) {
setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: cloudFormationTemplateUrl });
} else {
setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: 'PlaceHolder' });
setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: cloudFormationTemplateUrl });
}
}

Expand All @@ -109,7 +109,7 @@ const isK8sPackage = (pkg: PackagePolicy) => {
return K8S_PACKAGES.has(name);
};

const isCSPPackage = (pkg: PackagePolicy) => {
const getCSPPackageType = (pkg: PackagePolicy) => {
const name = pkg.package?.name as string;
if (name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<FlyOutProps> = ({
agentPolicies={agentPolicies}
isFleetServerPolicySelected={isFleetServerPolicySelected}
isK8s={isK8s}
isCSP={isCSP.status}
isCSP={isCSP}
refreshAgentPolicies={refreshAgentPolicies}
isLoadingAgentPolicies={isLoadingAgentPolicies}
mode={mode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ 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 {
getCloudFormationTemplateUrlFromPackagePolicy,
policyHasFleetServer,
} from '../../services';
import { policyHasFleetServer } from '../../services';
import { AdvancedTab } from '../../applications/fleet/components/fleet_server_instructions/advanced_tab';

import type { InstructionProps } from './types';
Expand All @@ -36,6 +33,7 @@ export const Instructions = (props: InstructionProps) => {
setMode,
isIntegrationFlow,
refreshAgentPolicies,
isCSP,
} = props;
const fleetStatus = useFleetStatus();
const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } =
Expand Down Expand Up @@ -82,20 +80,16 @@ export const Instructions = (props: InstructionProps) => {
isFleetServerUnhealthy ||
(fleetStatus.missingRequirements ?? []).some((r) => r === FLEET_SERVER_PACKAGE));

const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(
props.selectedPolicy
);

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

if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth)
return <Loading size="l" />;
Expand Down Expand Up @@ -124,7 +118,7 @@ export const Instructions = (props: InstructionProps) => {
{isFleetServerPolicySelected ? (
<AdvancedTab selectedPolicyId={props.selectedPolicy?.id} onClose={() => undefined} />
) : (
<ManagedSteps {...props} cloudFormationTemplateUrl={cloudFormationTemplateUrl} />
<ManagedSteps {...props} cloudFormationTemplateUrl={isCSP?.cloudformationUrl} />
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const StandaloneSteps: React.FunctionComponent<InstructionProps> = ({
InstallStandaloneAgentStep({
installCommand: standaloneInstallCommands,
isK8s,
isCSP,
isCSP: isCSP?.status,
})
);

Expand Down Expand Up @@ -263,7 +263,7 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
apiKeyData,
selectedApiKeyId,
isK8s,
isCSP,
isCSP: isCSP?.status,
enrollToken,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export type CSPMode = 'IS_LOADING' | 'IS_NOT_CSP' | 'IS_CSP_KSPM' | 'IS_CSP_CNVM
export type FlyoutMode = 'managed' | 'standalone';
export type SelectionType = 'tabs' | 'radio' | undefined;

export interface CSPObject {
status: CSPMode;
cloudformationUrl: string | undefined;
}

export interface BaseProps {
/**
* The user selected policy to be used. If this value is `undefined` a value must be provided for `agentPolicies`.
Expand All @@ -30,7 +35,7 @@ export interface BaseProps {

isK8s?: K8sMode;

isCSP?: CSPMode;
isCSP?: CSPObject;

/**
* There is a step in the agent enrollment process that allows users to see the data from an integration represented in the UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { PlatformSelector } from '../platform_selector';
interface Props {
installCommand: CommandsByPlatform;
isK8s: K8sMode | undefined;
isCSP?: CSPMode | undefined;
isCSP: CSPMode | undefined;
enrollToken?: string;
fullCopyButton?: boolean;
isManaged?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
<EuiCallOut
title={i18n.translate('xpack.fleet.enrollmentInstructions.macCallout', {
defaultMessage:
'We recommend against deploying CSPM within Mac as it is currently not being supported.',
'We recommend against deploying this integration within Mac as it is currently not being supported.',
})}
color="warning"
iconType="warning"
Expand Down

0 comments on commit d329d70

Please sign in to comment.