-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Remove use of Redux from the Endpoint P…
…olicy Settings form (#161511) ## Summary - Re-creates all policy settings form components so that the Policy settings are provided as a prop - Adds `mode = view` to the policy form. When in this mode (user has no authz to edit), form will be displayed in view only mode (no more `disabled` form elements)
- Loading branch information
1 parent
f022456
commit 3ba51e4
Showing
65 changed files
with
2,795 additions
and
2,836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
x-pack/plugins/security_solution/public/management/hooks/policy/use_fetch_endpoint_policy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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 type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query'; | ||
import type { IHttpFetchError } from '@kbn/core-http-browser'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common'; | ||
import { | ||
DefaultPolicyNotificationMessage, | ||
DefaultPolicyRuleNotificationMessage, | ||
} from '../../../../common/endpoint/models/policy_config'; | ||
import type { GetPolicyResponse } from '../../pages/policy/types'; | ||
import { useHttp } from '../../../common/lib/kibana'; | ||
import type { PolicyData, PolicyConfig } from '../../../../common/endpoint/types'; | ||
import type { ManifestSchema } from '../../../../common/endpoint/schema/manifest'; | ||
|
||
interface ApiDataResponse { | ||
/** Data return from the Fleet API. Its the full integration policy (package policy) */ | ||
item: PolicyData; | ||
/** Endpoint policy settings from the data retrieved from fleet */ | ||
settings: PolicyConfig; | ||
/** Endpoint policy manifest info from the data retrieved from fleet */ | ||
artifactManifest: ManifestSchema; | ||
} | ||
|
||
type UseFetchEndpointPolicyResponse = UseQueryResult<ApiDataResponse, IHttpFetchError>; | ||
|
||
/** | ||
* Retrieve a single endpoint integration policy (details) | ||
* @param policyId | ||
* @param options | ||
*/ | ||
export const useFetchEndpointPolicy = ( | ||
policyId: string, | ||
options: UseQueryOptions<ApiDataResponse, IHttpFetchError> = {} | ||
): UseFetchEndpointPolicyResponse => { | ||
const http = useHttp(); | ||
|
||
return useQuery<ApiDataResponse, IHttpFetchError>({ | ||
queryKey: ['get-policy-details', policyId], | ||
...options, | ||
queryFn: async () => { | ||
const apiResponse = await http.get<GetPolicyResponse>( | ||
packagePolicyRouteService.getInfoPath(policyId) | ||
); | ||
|
||
applyDefaultsToPolicyIfNeeded(apiResponse.item); | ||
|
||
return { | ||
item: apiResponse.item, | ||
settings: apiResponse.item.inputs[0].config.policy.value, | ||
artifactManifest: apiResponse.item.inputs[0].config.artifact_manifest.value, | ||
}; | ||
}, | ||
}); | ||
}; | ||
|
||
const applyDefaultsToPolicyIfNeeded = (policyItem: PolicyData): void => { | ||
const settings = policyItem.inputs[0].config.policy.value; | ||
|
||
// sets default user notification message if policy config message is empty | ||
if (settings.windows.popup.malware.message === '') { | ||
settings.windows.popup.malware.message = DefaultPolicyNotificationMessage; | ||
settings.mac.popup.malware.message = DefaultPolicyNotificationMessage; | ||
settings.linux.popup.malware.message = DefaultPolicyNotificationMessage; | ||
} | ||
if (settings.windows.popup.ransomware.message === '') { | ||
settings.windows.popup.ransomware.message = DefaultPolicyNotificationMessage; | ||
} | ||
if (settings.windows.popup.memory_protection.message === '') { | ||
settings.windows.popup.memory_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
if (settings.mac.popup.memory_protection.message === '') { | ||
settings.mac.popup.memory_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
if (settings.linux.popup.memory_protection.message === '') { | ||
settings.linux.popup.memory_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
if (settings.windows.popup.behavior_protection.message === '') { | ||
settings.windows.popup.behavior_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
if (settings.mac.popup.behavior_protection.message === '') { | ||
settings.mac.popup.behavior_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
if (settings.linux.popup.behavior_protection.message === '') { | ||
settings.linux.popup.behavior_protection.message = DefaultPolicyRuleNotificationMessage; | ||
} | ||
}; |
37 changes: 37 additions & 0 deletions
37
...curity_solution/public/management/hooks/policy/use_fetch_endpoint_policy_agent_summary.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query'; | ||
import type { IHttpFetchError } from '@kbn/core-http-browser'; | ||
import type { GetAgentStatusResponse } from '@kbn/fleet-plugin/common'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { agentRouteService } from '@kbn/fleet-plugin/common'; | ||
import { useHttp } from '../../../common/lib/kibana'; | ||
|
||
type EndpointPolicyAgentSummary = GetAgentStatusResponse['results']; | ||
|
||
export const useFetchAgentByAgentPolicySummary = ( | ||
/** | ||
* The Fleet Agent Policy ID (NOT the endpoint policy id) | ||
*/ | ||
agentPolicyId: string, | ||
options: UseQueryOptions<EndpointPolicyAgentSummary, IHttpFetchError> = {} | ||
): UseQueryResult<EndpointPolicyAgentSummary, IHttpFetchError> => { | ||
const http = useHttp(); | ||
|
||
return useQuery<EndpointPolicyAgentSummary, IHttpFetchError>({ | ||
queryKey: ['get-policy-agent-summary', agentPolicyId], | ||
...options, | ||
queryFn: async () => { | ||
return ( | ||
await http.get<GetAgentStatusResponse>(agentRouteService.getStatusPath(), { | ||
query: { policyId: agentPolicyId }, | ||
}) | ||
).results; | ||
}, | ||
}); | ||
}; |
45 changes: 45 additions & 0 deletions
45
...ck/plugins/security_solution/public/management/hooks/policy/use_update_endpoint_policy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; | ||
import type { IHttpFetchError } from '@kbn/core-http-browser'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common'; | ||
import { getPolicyDataForUpdate } from '../../../../common/endpoint/service/policy'; | ||
import { useHttp } from '../../../common/lib/kibana'; | ||
import type { PolicyData } from '../../../../common/endpoint/types'; | ||
import type { UpdatePolicyResponse } from '../../pages/policy/types'; | ||
|
||
interface UpdateParams { | ||
policy: PolicyData; | ||
} | ||
|
||
type UseUpdateEndpointPolicyOptions = UseMutationOptions< | ||
UpdatePolicyResponse, | ||
IHttpFetchError, | ||
UpdateParams | ||
>; | ||
|
||
type UseUpdateEndpointPolicyResult = UseMutationResult< | ||
UpdatePolicyResponse, | ||
IHttpFetchError, | ||
UpdateParams | ||
>; | ||
|
||
export const useUpdateEndpointPolicy = ( | ||
options?: UseUpdateEndpointPolicyOptions | ||
): UseUpdateEndpointPolicyResult => { | ||
const http = useHttp(); | ||
|
||
return useMutation<UpdatePolicyResponse, IHttpFetchError, UpdateParams>(({ policy }) => { | ||
const update = getPolicyDataForUpdate(policy); | ||
|
||
return http.put(packagePolicyRouteService.getUpdatePath(policy.id), { | ||
body: JSON.stringify(update), | ||
}); | ||
}, options); | ||
}; |
Oops, something went wrong.