Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
isDisabled={disabled}
>
<EuiSuperSelect
disabled={disabled || isManagedPolicy}
disabled={disabled || isManagedOrAgentlessPolicy}
valueOfSelected={dataOutputValueOfSelected}
fullWidth
isLoading={isLoadingOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function useOutputs(
packageName: string
) {
const licenseService = useLicense();
const canUseOutputPerIntegration = licenseService.hasAtLeast(LICENCE_FOR_OUTPUT_PER_INTEGRATION);
const canUseOutputPerIntegration =
licenseService.hasAtLeast(LICENCE_FOR_OUTPUT_PER_INTEGRATION) &&
!packagePolicy.supports_agentless;
const { data: outputsData, isLoading } = useGetOutputs();
const allowedOutputTypes = getAllowedOutputTypesForPackagePolicy(packagePolicy);
const allowedOutputs = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ describe('PackagePolicyInputPanel', () => {
isAgentlessDefault: false,
isAgentlessAgentPolicy: jest.fn(),
isAgentlessIntegration: jest.fn(),
isServerless: false,
isCloud: true,
});
});

Expand Down Expand Up @@ -396,6 +398,8 @@ describe('PackagePolicyInputPanel', () => {
isAgentlessDefault: false,
isAgentlessAgentPolicy: jest.fn(),
isAgentlessIntegration: jest.fn(),
isServerless: false,
isCloud: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jest.mock('../../../../../services');
jest.mock('../../../../../hooks', () => ({
...jest.requireActual('../../../../../hooks'),
sendGetOneAgentPolicy: jest.fn(),
sendGetOneFleetServerHost: jest.fn().mockResolvedValue({}),
sendGetOneOutput: jest.fn().mockResolvedValue({}),
useStartServices: jest.fn(),
useConfig: jest.fn(),
}));
Expand Down Expand Up @@ -295,10 +297,13 @@ describe('useSetupTechnology', () => {
},
});

(generateNewAgentPolicyWithDefaults as MockFn).mockReturnValue({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
(generateNewAgentPolicyWithDefaults as MockFn).mockImplementation((overrides: any) => {
return {
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
...overrides,
};
});
jest.clearAllMocks();
});
Expand Down Expand Up @@ -728,7 +733,9 @@ describe('useSetupTechnology', () => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
});
});
});
Expand Down Expand Up @@ -768,9 +775,11 @@ describe('useSetupTechnology', () => {
expect(generateNewAgentPolicyWithDefaults).toHaveBeenCalled();
expect(updatePackagePolicyMock).toHaveBeenCalledWith({ supports_agentless: true });
expect(setNewAgentPolicy).toHaveBeenCalledWith({
inactivity_timeout: 3600,
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
});

rerender({
Expand All @@ -788,7 +797,9 @@ describe('useSetupTechnology', () => {
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-2',
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
supports_agentless: true,
});
});
Expand Down Expand Up @@ -934,6 +945,7 @@ describe('useSetupTechnology', () => {
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
global_data_tags: [
{ name: 'organization', value: 'org' },
{ name: 'division', value: 'div' },
Expand Down Expand Up @@ -1192,7 +1204,9 @@ describe('useSetupTechnology', () => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
});
expect(setNewAgentPolicy).not.toHaveBeenCalledWith({
global_data_tags: [
Expand Down Expand Up @@ -1266,7 +1280,9 @@ describe('useSetupTechnology', () => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
});
expect(setNewAgentPolicy).not.toHaveBeenCalledWith({
global_data_tags: [
Expand Down Expand Up @@ -1311,7 +1327,9 @@ describe('useSetupTechnology', () => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
global_data_tags: undefined,
inactivity_timeout: 3600,
monitoring_enabled: ['logs', 'metrics'],
});
expect(setNewAgentPolicy).not.toHaveBeenCalledWith({
global_data_tags: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useCallback, useRef, useState, useEffect, useMemo } from 'react';

import { useConfig } from '../../../../../hooks';
import { useConfig, sendGetOneFleetServerHost, sendGetOneOutput } from '../../../../../hooks';
import { generateNewAgentPolicyWithDefaults } from '../../../../../../../../common/services/generate_new_agent_policy';
import type {
AgentPolicy,
Expand All @@ -24,6 +24,10 @@ import {
AGENTLESS_GLOBAL_TAG_NAME_TEAM,
AGENTLESS_AGENT_POLICY_INACTIVITY_TIMEOUT,
AGENTLESS_AGENT_POLICY_MONITORING,
SERVERLESS_DEFAULT_OUTPUT_ID,
DEFAULT_OUTPUT_ID,
SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID,
DEFAULT_FLEET_SERVER_HOST_ID,
} from '../../../../../../../../common/constants';
import {
isAgentlessIntegration as isAgentlessIntegrationFn,
Expand Down Expand Up @@ -58,6 +62,8 @@ export const useAgentless = () => {
isAgentlessDefault,
isAgentlessAgentPolicy,
isAgentlessIntegration,
isServerless,
isCloud,
};
};

Expand All @@ -82,7 +88,7 @@ export function useSetupTechnology({
agentPolicies?: AgentPolicy[];
integrationToEnable?: string;
}) {
const { isAgentlessEnabled, isAgentlessDefault } = useAgentless();
const { isAgentlessEnabled, isAgentlessDefault, isServerless, isCloud } = useAgentless();

// this is a placeholder for the new agent-BASED policy that will be used when the user switches from agentless to agent-based and back
const orginalAgentPolicyRef = useRef<NewAgentPolicy>({ ...newAgentPolicy });
Expand Down Expand Up @@ -112,6 +118,43 @@ export function useSetupTechnology({
}, [isAgentlessEnabled, isAgentlessDefault, packageInfo, integrationToEnable]);

const agentlessPolicyName = getAgentlessAgentPolicyNameFromPackagePolicyName(packagePolicy.name);
const [agentlessPolicyOutputId, setAgentlessPolicyOutputId] = useState<string | undefined>();
const [agentlessPolicyFleetServerHostId, setAgentlessPolicyFleetServerHostId] = useState<
string | undefined
>();

useEffect(() => {
const fetchOutputId = async () => {
const outputId = isServerless
? SERVERLESS_DEFAULT_OUTPUT_ID
: isCloud
? DEFAULT_OUTPUT_ID
: undefined;
if (outputId) {
const outputData = await sendGetOneOutput(outputId);
setAgentlessPolicyOutputId(outputData.data?.item ? outputId : undefined);
} else {
setAgentlessPolicyOutputId(undefined);
}
};
const fetchFleetServerHostId = async () => {
const hostId = isServerless
? SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID
: isCloud
? DEFAULT_FLEET_SERVER_HOST_ID
: undefined;

if (hostId) {
const hostData = await sendGetOneFleetServerHost(hostId);
setAgentlessPolicyFleetServerHostId(hostData.data?.item ? hostId : undefined);
} else {
setAgentlessPolicyFleetServerHostId(undefined);
}
};

fetchOutputId();
fetchFleetServerHostId();
}, [isCloud, isServerless]);

const handleSetupTechnologyChange = useCallback(
(setupTechnology: SetupTechnology) => {
Expand Down Expand Up @@ -145,6 +188,10 @@ export function useSetupTechnology({
inactivity_timeout: AGENTLESS_AGENT_POLICY_INACTIVITY_TIMEOUT,
supports_agentless: true,
monitoring_enabled: AGENTLESS_AGENT_POLICY_MONITORING,
...(agentlessPolicyOutputId ? { data_output_id: agentlessPolicyOutputId } : {}),
...(agentlessPolicyFleetServerHostId
? { fleet_server_host_id: agentlessPolicyFleetServerHostId }
: {}),
}),
name: agentlessPolicyName,
global_data_tags: getGlobaDataTags(packageInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export function useGetFleetServerHosts() {
});
}

export function sendGetOneFleetServerHost(itemId: string) {
return sendRequest({
method: 'get',
path: fleetServerHostsRoutesService.getInfoPath(itemId),
version: API_VERSIONS.public.v1,
});
}

export function sendDeleteFleetServerHost(itemId: string) {
return sendRequest({
method: 'delete',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function useDefaultOutput() {
return { output, refresh: outputsRequest.resendRequest };
}

export function sendGetOneOutput(outputId: string) {
return sendRequest({
method: 'get',
path: outputRoutesService.getInfoPath(outputId),
version: API_VERSIONS.public.v1,
});
}

export function sendPutOutput(outputId: string, body: PutOutputRequest['body']) {
return sendRequest({
method: 'put',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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 { ensureCorrectAgentlessSettingsIds } from './agentless_settings_ids';
import { agentPolicyService } from './agent_policy';

jest.mock('.', () => ({
appContextService: {
getLogger: () => ({
debug: jest.fn(),
}),
getCloud: () => ({
isCloudEnabled: true,
isServerlessEnabled: true,
}),
getInternalUserSOClientWithoutSpaceExtension: () => ({
find: jest.fn().mockImplementation(() => {
return {
saved_objects: [{ id: 'agent_policy_1' }, { id: 'agent_policy_2' }],
};
}),
}),
},
}));

jest.mock('./agent_policy', () => ({
agentPolicyService: {
find: jest.fn(),
update: jest.fn(),
},
getAgentPolicySavedObjectType: jest.fn().mockResolvedValue('ingest-agent-policies'),
}));

jest.mock('./output', () => ({
outputService: {
get: jest.fn().mockResolvedValue({
id: 'es-default-output',
}),
},
}));

jest.mock('./fleet_server_host', () => ({
fleetServerHostService: {
get: jest.fn().mockResolvedValue({
id: 'default-fleet-server',
}),
},
}));

describe('correct agentless policy settings', () => {
it('should correct agentless policy settings', async () => {
await ensureCorrectAgentlessSettingsIds(undefined as any);

expect(agentPolicyService.update).toHaveBeenCalledWith(
expect.anything(),
undefined,
'agent_policy_1',
{
data_output_id: 'es-default-output',
fleet_server_host_id: 'default-fleet-server',
}
);
expect(agentPolicyService.update).toHaveBeenCalledWith(
expect.anything(),
undefined,
'agent_policy_2',
{
data_output_id: 'es-default-output',
fleet_server_host_id: 'default-fleet-server',
}
);
});
});
Loading
Loading