[Fleet] Hide Fleet Server policies in standalone agent instructions (#98787)
This commit is contained in:
parent
480483bacc
commit
0f6923ac0c
|
@ -18,6 +18,7 @@ import { AgentPolicyPackageBadges } from '../agent_policy_package_badges';
|
|||
type Props = {
|
||||
agentPolicies?: AgentPolicy[];
|
||||
onAgentPolicyChange?: (key: string) => void;
|
||||
excludeFleetServer?: boolean;
|
||||
} & (
|
||||
| {
|
||||
withKeySelection: true;
|
||||
|
@ -30,7 +31,7 @@ type Props = {
|
|||
|
||||
export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
|
||||
const { notifications } = useStartServices();
|
||||
const { withKeySelection, agentPolicies, onAgentPolicyChange } = props;
|
||||
const { withKeySelection, agentPolicies, onAgentPolicyChange, excludeFleetServer } = props;
|
||||
const onKeyChange = props.withKeySelection && props.onKeyChange;
|
||||
|
||||
const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false);
|
||||
|
@ -182,7 +183,10 @@ export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
|
|||
/>
|
||||
<EuiSpacer size="m" />
|
||||
{selectedState.agentPolicyId && (
|
||||
<AgentPolicyPackageBadges agentPolicyId={selectedState.agentPolicyId} />
|
||||
<AgentPolicyPackageBadges
|
||||
agentPolicyId={selectedState.agentPolicyId}
|
||||
excludeFleetServer={excludeFleetServer}
|
||||
/>
|
||||
)}
|
||||
{withKeySelection && onKeyChange && (
|
||||
<>
|
||||
|
|
|
@ -76,7 +76,7 @@ export const StandaloneInstructions = React.memo<Props>(({ agentPolicies }) => {
|
|||
const yaml = useMemo(() => fullAgentPolicyToYaml(fullAgentPolicy), [fullAgentPolicy]);
|
||||
const steps: EuiContainedStepProps[] = [
|
||||
DownloadStep(),
|
||||
AgentPolicySelectionStep({ agentPolicies, setSelectedPolicyId }),
|
||||
AgentPolicySelectionStep({ agentPolicies, setSelectedPolicyId, excludeFleetServer: true }),
|
||||
{
|
||||
title: i18n.translate('xpack.fleet.agentEnrollment.stepConfigureAgentTitle', {
|
||||
defaultMessage: 'Configure the agent',
|
||||
|
|
|
@ -51,14 +51,19 @@ export const AgentPolicySelectionStep = ({
|
|||
setSelectedAPIKeyId,
|
||||
setSelectedPolicyId,
|
||||
setIsFleetServerPolicySelected,
|
||||
excludeFleetServer,
|
||||
}: {
|
||||
agentPolicies?: AgentPolicy[];
|
||||
setSelectedAPIKeyId?: (key: string) => void;
|
||||
setSelectedPolicyId?: (policyId: string) => void;
|
||||
setIsFleetServerPolicySelected?: (selected: boolean) => void;
|
||||
excludeFleetServer?: boolean;
|
||||
}) => {
|
||||
const regularAgentPolicies = Array.isArray(agentPolicies)
|
||||
? agentPolicies.filter((policy) => policy && !policy.is_managed)
|
||||
? agentPolicies.filter(
|
||||
(policy) =>
|
||||
policy && !policy.is_managed && (!excludeFleetServer || !policy.is_default_fleet_server)
|
||||
)
|
||||
: [];
|
||||
|
||||
const onAgentPolicyChange = useCallback(
|
||||
|
@ -93,6 +98,7 @@ export const AgentPolicySelectionStep = ({
|
|||
withKeySelection={setSelectedAPIKeyId ? true : false}
|
||||
onKeyChange={setSelectedAPIKeyId}
|
||||
onAgentPolicyChange={onAgentPolicyChange}
|
||||
excludeFleetServer={excludeFleetServer}
|
||||
/>
|
||||
),
|
||||
};
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui';
|
||||
import { EuiSpacer, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge, EuiCallOut } from '@elastic/eui';
|
||||
|
||||
import { FLEET_SERVER_PACKAGE } from '../../../../../../common/constants';
|
||||
|
||||
import type { PackagePolicy, PackagePolicyPackage } from '../../../types';
|
||||
import { useGetOneAgentPolicy } from '../../../hooks';
|
||||
|
@ -16,11 +19,13 @@ import { PackageIcon } from '../../../components/package_icon';
|
|||
interface Props {
|
||||
agentPolicyId: string;
|
||||
hideTitle?: boolean;
|
||||
excludeFleetServer?: boolean;
|
||||
}
|
||||
|
||||
export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
|
||||
agentPolicyId,
|
||||
hideTitle,
|
||||
excludeFleetServer,
|
||||
}) => {
|
||||
const agentPolicyRequest = useGetOneAgentPolicy(agentPolicyId);
|
||||
const agentPolicy = agentPolicyRequest.data ? agentPolicyRequest.data.item : null;
|
||||
|
@ -45,6 +50,19 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
|
|||
return [...uniquePackages.values()];
|
||||
}, [agentPolicy]);
|
||||
|
||||
const showFleetServerWarning = useMemo(
|
||||
() => excludeFleetServer && packages?.some((pkg) => pkg.name === FLEET_SERVER_PACKAGE),
|
||||
[packages, excludeFleetServer]
|
||||
);
|
||||
|
||||
const collectedIntegrationsCount = useMemo(
|
||||
() =>
|
||||
packages
|
||||
? packages.filter((pkg) => !excludeFleetServer || pkg.name !== FLEET_SERVER_PACKAGE).length
|
||||
: 0,
|
||||
[packages, excludeFleetServer]
|
||||
);
|
||||
|
||||
if (!agentPolicy || !packages) {
|
||||
return null;
|
||||
}
|
||||
|
@ -58,8 +76,8 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
|
|||
id="xpack.fleet.agentReassignPolicy.policyDescription"
|
||||
defaultMessage="The selected agent policy will collect data for {count, plural, one {{countValue} integration} other {{countValue} integrations}}:"
|
||||
values={{
|
||||
count: packages.length,
|
||||
countValue: <b>{packages.length}</b>,
|
||||
count: collectedIntegrationsCount,
|
||||
countValue: <b>{collectedIntegrationsCount}</b>,
|
||||
}}
|
||||
/>
|
||||
</EuiText>
|
||||
|
@ -68,7 +86,11 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
|
|||
)}
|
||||
{packages.map((pkg, idx) => {
|
||||
return (
|
||||
<EuiBadge key={idx} color="hollow">
|
||||
<EuiBadge
|
||||
key={idx}
|
||||
color="hollow"
|
||||
isDisabled={excludeFleetServer && pkg.name === FLEET_SERVER_PACKAGE}
|
||||
>
|
||||
<EuiFlexGroup direction="row" gutterSize="xs" alignItems="center">
|
||||
<EuiFlexItem grow={false}>
|
||||
<PackageIcon
|
||||
|
@ -89,6 +111,22 @@ export const AgentPolicyPackageBadges: React.FunctionComponent<Props> = ({
|
|||
</EuiBadge>
|
||||
);
|
||||
})}
|
||||
{showFleetServerWarning && (
|
||||
<>
|
||||
<EuiSpacer size="s" />
|
||||
<EuiCallOut
|
||||
size="s"
|
||||
color="warning"
|
||||
iconType="alert"
|
||||
title={i18n.translate(
|
||||
'xpack.fleet.agentReassignPolicy.packageBadgeFleetServerWarning',
|
||||
{
|
||||
defaultMessage: 'Fleet Server will not be enabled in standalone mode.',
|
||||
}
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue