Skip to content

Commit

Permalink
Defaulting to agentless placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
seanrathier committed Jan 7, 2025
1 parent f91d4ac commit 5f73293
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ describe('useSetupTechnology', () => {
});
});

it.only('should not have global_data_tags when switching from agentless to agent-based policy', async () => {
it('should not have global_data_tags when switching from agentless to agent-based policy', async () => {
(useConfig as MockFn).mockReturnValue({
agentless: {
enabled: true,
Expand All @@ -699,20 +699,6 @@ describe('useSetupTechnology', () => {
})
);

await waitFor(() => {
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith(
expect.objectContaining({
supports_agentless: true,
global_data_tags: [
{ name: 'organization', value: 'org' },
{ name: 'division', value: 'div' },
{ name: 'team', value: 'team' },
],
})
);
});

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENT_BASED);
});
Expand All @@ -727,5 +713,23 @@ describe('useSetupTechnology', () => {
],
});
});

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

await waitFor(() => {
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith(
expect.objectContaining({
supports_agentless: true,
global_data_tags: [
{ name: 'organization', value: 'org' },
{ name: 'division', value: 'div' },
{ name: 'team', value: 'team' },
],
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function useSetupTechnology({
// 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 newAgentBasedPolicy = useRef<NewAgentPolicy>(newAgentPolicy);
const defaultSetupTechnology = useMemo(() => {
return isOnlyAgentlessIntegration(packageInfo)
return isOnlyAgentlessIntegration(packageInfo) || isAgentlessSetupDefault(packageInfo)
? SetupTechnology.AGENTLESS
: SetupTechnology.AGENT_BASED;
}, [packageInfo]);
Expand All @@ -107,6 +107,7 @@ export function useSetupTechnology({
const nextNewAgentlessPolicy = {
...newAgentlessPolicy,
name: getAgentlessAgentPolicyNameFromPackagePolicyName(packagePolicy.name),
...getAdditionalAgentlessPolicyInfo(packageInfo),
};
if (!newAgentlessPolicy.name || nextNewAgentlessPolicy.name !== newAgentlessPolicy.name) {
setNewAgentlessPolicy(nextNewAgentlessPolicy);
Expand Down Expand Up @@ -141,10 +142,11 @@ export function useSetupTechnology({
agentPolicies,
setSelectedSetupTechnology,
updatePackagePolicy,
packageInfo,
]);

const handleSetupTechnologyChange = useCallback(
(setupTechnology: SetupTechnology, policyTemplateName?: string) => {
(setupTechnology: SetupTechnology) => {
if (!isAgentlessEnabled || setupTechnology === selectedSetupTechnology) {
return;
}
Expand All @@ -153,7 +155,6 @@ export function useSetupTechnology({
if (isAgentlessEnabled) {
const agentlessPolicy = {
...newAgentlessPolicy,
...getAdditionalAgentlessPolicyInfo(policyTemplateName, packageInfo),
} as NewAgentPolicy;

setNewAgentPolicy(agentlessPolicy);
Expand Down Expand Up @@ -183,7 +184,6 @@ export function useSetupTechnology({
updatePackagePolicy,
setNewAgentPolicy,
newAgentlessPolicy,
packageInfo,
setSelectedPolicyTab,
updateAgentPolicies,
]
Expand All @@ -195,36 +195,42 @@ export function useSetupTechnology({
};
}

const getAdditionalAgentlessPolicyInfo = (
policyTemplateName?: string,
packageInfo?: PackageInfo
) => {
if (!policyTemplateName || !packageInfo) {
return {};
}
const agentlessPolicyTemplate = policyTemplateName
? packageInfo?.policy_templates?.find((policy) => policy.name === policyTemplateName)
: undefined;
const isAgentlessSetupDefault = (packageInfo?: PackageInfo) => {
// placegolder for the logic to determine if the agentless setup is the default
return true;
};

const getAdditionalAgentlessPolicyInfo = (packageInfo?: PackageInfo) => {
// this assumes that there is all the deployments modes are the same for all the policy templates
const agentlessPolicyTemplate = packageInfo?.policy_templates?.find(
(policy) => policy.deployment_modes
);

const agentlessInfo = agentlessPolicyTemplate?.deployment_modes?.agentless;
return !agentlessInfo
? {}
: {
global_data_tags: agentlessInfo
? [
{
name: AGENTLESS_GLOBAL_TAG_NAME_ORGANIZATION,
value: agentlessInfo.organization,
},
{
name: AGENTLESS_GLOBAL_TAG_NAME_DIVISION,
value: agentlessInfo.division,
},
{
name: AGENTLESS_GLOBAL_TAG_NAME_TEAM,
value: agentlessInfo.team,
},
]
: [],
};
if (
agentlessInfo === undefined ||
!agentlessInfo.organization ||
!agentlessInfo.division ||
!agentlessInfo.team
) {
return undefined;
}
return {
global_data_tags: agentlessInfo
? [
{
name: AGENTLESS_GLOBAL_TAG_NAME_ORGANIZATION,
value: agentlessInfo.organization,
},
{
name: AGENTLESS_GLOBAL_TAG_NAME_DIVISION,
value: agentlessInfo.division,
},
{
name: AGENTLESS_GLOBAL_TAG_NAME_TEAM,
value: agentlessInfo.team,
},
]
: [],
};
};

0 comments on commit 5f73293

Please sign in to comment.