Skip to content

Commit

Permalink
[Cloud Security] [Bug] Setting the agentless policy inactivity_timeou…
Browse files Browse the repository at this point in the history
…t to 1 hour so they don't show in the Fleet Agents list in Kibana (elastic#195808)

(cherry picked from commit 808c96b)
  • Loading branch information
seanrathier committed Oct 12, 2024
1 parent 73d98d3 commit 65f7a52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe('useSetupTechnology', () => {
namespace: 'default',
is_managed: false,
supports_agentless: false,
inactivity_timeout: 3600,
};
const packagePolicyMock = createPackagePolicyMock();

Expand All @@ -169,6 +170,7 @@ describe('useSetupTechnology', () => {
(generateNewAgentPolicyWithDefaults as MockFn).mockReturnValue({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
});
jest.clearAllMocks();
});
Expand Down Expand Up @@ -266,12 +268,14 @@ describe('useSetupTechnology', () => {
act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

waitForNextUpdate();

expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
});
});

Expand Down Expand Up @@ -307,6 +311,7 @@ describe('useSetupTechnology', () => {

expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith({
inactivity_timeout: 3600,
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
});
Expand All @@ -325,6 +330,7 @@ describe('useSetupTechnology', () => {
waitFor(() => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-2',
inactivity_timeout: 3600,
supports_agentless: true,
});
});
Expand Down Expand Up @@ -505,6 +511,7 @@ describe('useSetupTechnology', () => {
expect(setNewAgentPolicy).toHaveBeenCalledWith({
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ export function useSetupTechnology({
const [selectedSetupTechnology, setSelectedSetupTechnology] = useState<SetupTechnology>(
SetupTechnology.AGENT_BASED
);
const [newAgentlessPolicy, setNewAgentlessPolicy] = useState<AgentPolicy | NewAgentPolicy>(
generateNewAgentPolicyWithDefaults({
const [newAgentlessPolicy, setNewAgentlessPolicy] = useState<AgentPolicy | NewAgentPolicy>(() => {
const agentless = generateNewAgentPolicyWithDefaults({
inactivity_timeout: 3600,
supports_agentless: true,
monitoring_enabled: ['logs', 'metrics'],
})
);
});
return agentless;
});

useEffect(() => {
if (isEditPage && agentPolicies && agentPolicies.some((policy) => policy.supports_agentless)) {
Expand All @@ -116,7 +118,7 @@ export function useSetupTechnology({
...newAgentlessPolicy,
name: getAgentlessAgentPolicyNameFromPackagePolicyName(packagePolicy.name),
};
if (nextNewAgentlessPolicy.name !== newAgentlessPolicy.name) {
if (!newAgentlessPolicy.name || nextNewAgentlessPolicy.name !== newAgentlessPolicy.name) {
setNewAgentlessPolicy(nextNewAgentlessPolicy);
setNewAgentPolicy(nextNewAgentlessPolicy as NewAgentPolicy);
updateAgentPolicies([nextNewAgentlessPolicy] as AgentPolicy[]);
Expand Down

0 comments on commit 65f7a52

Please sign in to comment.