forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps] Granular Connector RBAC - adding back UIs for testing c…
…onnectors in stack management (elastic#204804) Part of elastic#180908 ## Summary As part of the changes for EDR Connector Execution for Testing, this PRs updates the SentinelOne and Crowdstrike params UIs to limit to a single sub-action. SentinelOne: <img width="861" alt="Screenshot 2024-12-18 at 11 16 49 AM" src="https://github.com/user-attachments/assets/1a839d21-7ba7-4c4e-b3e9-8772725fad63" /> Crowdstrike: <img width="855" alt="Screenshot 2024-12-18 at 11 17 01 AM" src="https://github.com/user-attachments/assets/b6c17964-8c49-4b5a-b1c7-bb4c6bb89621" /> ### Checklist Check the PR satisfies following conditions. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To test 1. In Stack Management create SentinelOne and Crowdstrike connectors (They don't need to work, you can use fake values for the url and token) 2. Test the new connectors. Verify that you only see one action type and that it can't be changed and that the params are correctly sent in the request.
- Loading branch information
Showing
10 changed files
with
267 additions
and
31 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
38 changes: 38 additions & 0 deletions
38
...ns/shared/stack_connectors/public/connector_types/crowdstrike/crowdstrike_params.test.tsx
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,38 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { SUB_ACTION } from '../../../common/crowdstrike/constants'; | ||
import type { CrowdstrikeActionParams } from '../../../common/crowdstrike/types'; | ||
import CrowdstrikeParamsFields from './crowdstrike_params'; | ||
|
||
const actionParams = { | ||
subAction: SUB_ACTION.GET_AGENT_DETAILS, | ||
subActionParams: { | ||
ids: ['test'], | ||
}, | ||
} as unknown as CrowdstrikeActionParams; | ||
|
||
describe('CrowdstrikeParamsFields renders', () => { | ||
test('all params fields are rendered', () => { | ||
const wrapper = mountWithIntl( | ||
<CrowdstrikeParamsFields | ||
actionParams={actionParams} | ||
errors={{ body: [] }} | ||
editAction={jest.fn()} | ||
index={0} | ||
messageVariables={[]} | ||
/> | ||
); | ||
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').length > 0).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').first().prop('readOnly')).toEqual( | ||
true | ||
); | ||
expect(wrapper.find('[data-test-subj="agentIdSelect"]').length > 0).toBeTruthy(); | ||
}); | ||
}); |
112 changes: 112 additions & 0 deletions
112
...plugins/shared/stack_connectors/public/connector_types/crowdstrike/crowdstrike_params.tsx
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,112 @@ | ||
/* | ||
* 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 React, { useMemo, useCallback, useState, useEffect } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSuperSelect, EuiComboBox } from '@elastic/eui'; | ||
import { ActionParamsProps } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import { SUB_ACTION } from '../../../common/crowdstrike/constants'; | ||
import type { CrowdstrikeActionParams } from '../../../common/crowdstrike/types'; | ||
import * as i18n from './translations'; | ||
|
||
const actionTypeOptions = [ | ||
{ | ||
value: SUB_ACTION.GET_AGENT_DETAILS, | ||
inputDisplay: i18n.GET_AGENT_DETAILS_ACTION_LABEL, | ||
}, | ||
]; | ||
|
||
const CrowdstrikeParamsFields: React.FunctionComponent< | ||
ActionParamsProps<CrowdstrikeActionParams> | ||
> = ({ actionParams, editAction, index, errors }) => { | ||
const [subActionValue] = useState<string | undefined>(SUB_ACTION.GET_AGENT_DETAILS); | ||
|
||
const { ids } = useMemo( | ||
() => | ||
actionParams.subActionParams ?? | ||
({ | ||
ids: [], | ||
} as unknown as CrowdstrikeActionParams['subActionParams']), | ||
[actionParams.subActionParams] | ||
); | ||
|
||
const labelOptions = useMemo(() => (ids ? ids.map((label: string) => ({ label })) : []), [ids]); | ||
|
||
const editSubActionParams = useCallback( | ||
(value: any) => { | ||
return editAction( | ||
'subActionParams', | ||
{ | ||
ids: value, | ||
}, | ||
index | ||
); | ||
}, | ||
[editAction, index] | ||
); | ||
|
||
useEffect(() => { | ||
if (!actionParams.subAction) { | ||
editAction('subAction', SUB_ACTION.GET_AGENT_DETAILS, index); | ||
} | ||
if (!actionParams.subActionParams) { | ||
editAction( | ||
'subActionParams', | ||
{ | ||
ids: [], | ||
}, | ||
index | ||
); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [actionParams]); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
<EuiFlexItem> | ||
<EuiFormRow fullWidth label={i18n.ACTION_TYPE_LABEL}> | ||
<EuiSuperSelect | ||
fullWidth | ||
options={actionTypeOptions} | ||
valueOfSelected={subActionValue} | ||
readOnly={true} | ||
data-test-subj="actionTypeSelect" | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiFormRow | ||
fullWidth | ||
label={i18n.AGENT_IDS_LABEL} | ||
error={errors['subActionParams.ids'] as string[]} | ||
> | ||
<EuiComboBox | ||
noSuggestions | ||
fullWidth | ||
selectedOptions={labelOptions} | ||
onCreateOption={(searchValue: string) => { | ||
const newOptions = [...labelOptions, { label: searchValue }]; | ||
editSubActionParams(newOptions.map((newOption) => newOption.label)); | ||
}} | ||
onChange={(selectedOptions: Array<{ label: string }>) => { | ||
editSubActionParams(selectedOptions.map((selectedOption) => selectedOption.label)); | ||
}} | ||
onBlur={() => { | ||
if (!ids) { | ||
editSubActionParams([]); | ||
} | ||
}} | ||
isClearable={true} | ||
data-test-subj="agentIdSelect" | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { CrowdstrikeParamsFields as default }; |
13 changes: 0 additions & 13 deletions
13
...s/shared/stack_connectors/public/connector_types/crowdstrike/crowdstrike_params_empty.tsx
This file was deleted.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
...ns/shared/stack_connectors/public/connector_types/sentinelone/sentinelone_params.test.tsx
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,35 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { SUB_ACTION } from '../../../common/sentinelone/constants'; | ||
import type { SentinelOneActionParams } from '../../../common/sentinelone/types'; | ||
import SentinelOneParamsFields from './sentinelone_params'; | ||
|
||
const actionParams = { | ||
subAction: SUB_ACTION.GET_AGENTS, | ||
subActionParams: {}, | ||
} as unknown as SentinelOneActionParams; | ||
|
||
describe('SentinelOneParamsFields renders', () => { | ||
test('all params fields are rendered', () => { | ||
const wrapper = mountWithIntl( | ||
<SentinelOneParamsFields | ||
actionParams={actionParams} | ||
errors={{ body: [] }} | ||
editAction={jest.fn()} | ||
index={0} | ||
messageVariables={[]} | ||
/> | ||
); | ||
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').length > 0).toBeTruthy(); | ||
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').first().prop('readOnly')).toEqual( | ||
true | ||
); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
...plugins/shared/stack_connectors/public/connector_types/sentinelone/sentinelone_params.tsx
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,51 @@ | ||
/* | ||
* 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 React, { useState, useEffect } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSuperSelect } from '@elastic/eui'; | ||
import { ActionParamsProps } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import { SUB_ACTION } from '../../../common/sentinelone/constants'; | ||
import type { SentinelOneActionParams } from '../../../common/sentinelone/types'; | ||
import * as i18n from './translations'; | ||
|
||
const actionTypeOptions = [ | ||
{ | ||
value: SUB_ACTION.GET_AGENTS, | ||
inputDisplay: i18n.GET_AGENT_ACTION_LABEL, | ||
}, | ||
]; | ||
|
||
const SentinelOneParamsFields: React.FunctionComponent< | ||
ActionParamsProps<SentinelOneActionParams> | ||
> = ({ editAction, index }) => { | ||
const [subAction] = useState<string | undefined>(SUB_ACTION.GET_AGENTS); | ||
|
||
useEffect(() => { | ||
editAction('subActionParams', {}, index); | ||
editAction('subAction', subAction, index); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
<EuiFlexItem> | ||
<EuiFormRow fullWidth label={i18n.ACTION_TYPE_LABEL}> | ||
<EuiSuperSelect | ||
fullWidth | ||
options={actionTypeOptions} | ||
valueOfSelected={subAction} | ||
readOnly={true} | ||
data-test-subj="actionTypeSelect" | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export { SentinelOneParamsFields as default }; |
13 changes: 0 additions & 13 deletions
13
...s/shared/stack_connectors/public/connector_types/sentinelone/sentinelone_params_empty.tsx
This file was deleted.
Oops, something went wrong.
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