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 @@ -60,8 +60,6 @@ export function getConnectorType(): ConnectorTypeModel<
return { errors };
},
actionConnectorFields: lazy(() => import('./crowdstrike_connector')),
actionParamsFields: lazy(() => import('./crowdstrike_params_empty')),
// TODO: Enable once we add support for automated response actions
// actionParamsFields: lazy(() => import('./crowdstrike_params')),
actionParamsFields: lazy(() => import('./crowdstrike_params')),
};
}
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();
});
});
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 };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ export const INVALID_ACTION = i18n.translate(
defaultMessage: 'Invalid action name.',
}
);

export const ACTION_TYPE_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.actionTypeFieldLabel',
{
defaultMessage: 'Action type',
}
);

export const GET_AGENT_DETAILS_ACTION_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.getAgentDetailsActionLabel',
{
defaultMessage: 'Get agent details',
}
);

export const AGENT_IDS_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.agentIdsLabel',
{
defaultMessage: 'Agent IDs',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export function getConnectorType(): ConnectorTypeModel<
return { errors };
},
actionConnectorFields: lazy(() => import('./sentinelone_connector')),
actionParamsFields: lazy(() => import('./sentinelone_params_empty')),
actionParamsFields: lazy(() => import('./sentinelone_params')),
};
}
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
);
});
});
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 };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export const RELEASE_AGENT_ACTION_LABEL = i18n.translate(
}
);

export const GET_AGENT_ACTION_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.getAgentActionLabel',
{
defaultMessage: 'Get agent details',
}
);

export const AGENTS_FIELD_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.agentsFieldLabel',
{
Expand All @@ -90,7 +97,7 @@ export const AGENTS_FIELD_PLACEHOLDER = i18n.translate(
export const ACTION_TYPE_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.actionTypeFieldLabel',
{
defaultMessage: 'Action Type',
defaultMessage: 'Action type',
}
);

Expand Down
Loading