Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Connectors] Add support of additional fields for ServiceNow ITSM and SecOps #184023

Merged
merged 35 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1439aba
Share Jira validators
cnasikas May 22, 2024
abf152e
Use shared validators for ITSM and SIR
cnasikas May 22, 2024
f367b32
Create additional fields component
cnasikas May 22, 2024
ee8c47d
Create validateJSON util function
cnasikas May 22, 2024
88d4ad2
Use additional fields component in ITSM and SIR
cnasikas May 22, 2024
b85060c
Validate additional fields using validateJSON in ITSM and SIR
cnasikas May 22, 2024
835a290
Merge branch 'main' into itsm_additional_fields
cnasikas May 23, 2024
742cc75
Add tests
cnasikas May 24, 2024
3defe90
Merge branch 'main' into itsm_additional_fields
cnasikas May 27, 2024
b466ac6
Improve helptext
cnasikas May 27, 2024
1e897fd
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 27, 2024
432c0ed
Fix bug where the errors was showing twice
cnasikas May 27, 2024
21924ac
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas May 27, 2024
4f7fb22
Hide additional fields from recovered action
cnasikas May 27, 2024
517079b
Fix i18n
cnasikas May 27, 2024
829e196
Fix types
cnasikas May 27, 2024
0911772
PR feedback
cnasikas May 28, 2024
5b9ad7b
Fix tests
cnasikas May 28, 2024
b326d8f
Merge branch 'main' into itsm_additional_fields
cnasikas May 28, 2024
5c10313
Merge branch 'main' into itsm_additional_fields
cnasikas May 29, 2024
7cad3d7
PR feedback
cnasikas May 29, 2024
9cdd19f
Fix actions snapshot
cnasikas May 29, 2024
c5cc337
Fix o11y types
cnasikas May 29, 2024
7a9451b
Merge branch 'main' into itsm_additional_fields
kibanamachine May 30, 2024
aa71f73
Merge branch 'main' into itsm_additional_fields
cnasikas May 30, 2024
65df354
Fix test
cnasikas May 30, 2024
aecce0f
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas May 30, 2024
1259aa5
Merge branch 'main' into itsm_additional_fields
kibanamachine Jun 3, 2024
8faa537
Merge branch 'main' into itsm_additional_fields
cnasikas Jun 4, 2024
854a83a
Merge branch 'main' into itsm_additional_fields
cnasikas Jun 6, 2024
95813fd
Merge branch 'main' into itsm_additional_fields
cnasikas Jun 12, 2024
6a593e9
Add feature flag for the intermediate release process
cnasikas Jun 12, 2024
896f3fa
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas Jun 12, 2024
21909ec
Fix tests
cnasikas Jun 12, 2024
2f79482
Merge branch 'main' into itsm_additional_fields
kibanamachine Jun 13, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function getServiceNowActionParams({ defaultActionMessage }: Translations): Serv
externalId: null,
correlation_id: null,
correlation_display: null,
additional_fields: null,
},
comments: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ function getServiceNowActionParams({ defaultActionMessage }: Translations): Serv
externalId: null,
correlation_id: null,
correlation_display: null,
additional_fields: null,
},
comments: [],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export const MAX_ADDITIONAL_FIELDS_LENGTH = 20;
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ describe('jira action params validation', () => {
errors: {
'subActionParams.incident.summary': [],
'subActionParams.incident.labels': [],
'subActionParams.incident.otherFields': [
'Additional fields field must be a valid JSON object.',
],
'subActionParams.incident.otherFields': ['Invalid JSON.'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It is not this PRs fault(maybe I caused it in the past?) but it annoys me so much that we call this otherFields in the code when in practice it should be additionalFields everywhere 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same 🙂 but unfortunately we cannot change it now because it is a backend field and the feature is already released.

},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
} from '@kbn/triggers-actions-ui-plugin/public';
import { MAX_OTHER_FIELDS_LENGTH } from '../../../common/jira/constants';
import { JiraConfig, JiraSecrets, JiraActionParams } from './types';
import { validateJSON } from '../lib/validate_json';

export const JIRA_DESC = i18n.translate('xpack.stackConnectors.components.jira.selectMessageText', {
defaultMessage: 'Create an incident in Jira.',
Expand Down Expand Up @@ -58,19 +59,15 @@ export function getConnectorType(): ConnectorTypeModel<JiraConfig, JiraSecrets,
errors['subActionParams.incident.labels'].push(translations.LABELS_WHITE_SPACES);
}

try {
const otherFields = actionParams.subActionParams?.incident?.otherFields;
if (otherFields) {
const parsedOtherFields = JSON.parse(otherFields);
if (Object.keys(parsedOtherFields).length > MAX_OTHER_FIELDS_LENGTH) {
errors['subActionParams.incident.otherFields'] = [
translations.OTHER_FIELDS_LENGTH_ERROR(MAX_OTHER_FIELDS_LENGTH),
];
}
}
} catch (error) {
errors['subActionParams.incident.otherFields'] = [translations.INVALID_JSON_FORMAT];
const jsonErrors = validateJSON({
value: actionParams.subActionParams?.incident?.otherFields,
maxProperties: MAX_OTHER_FIELDS_LENGTH,
});

if (jsonErrors) {
errors['subActionParams.incident.otherFields'] = [jsonErrors];
}

return validationResult;
},
actionParamsFields: lazy(() => import('./jira_params')),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 { render, screen, waitFor } from '@testing-library/react';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { AdditionalFields } from './additional_fields';
import userEvent from '@testing-library/user-event';

describe('Credentials', () => {
const onChange = jest.fn();
const value = JSON.stringify({ foo: 'test' });
const props = { value, errors: [], onChange };

it('renders the additional fields correctly', async () => {
render(
<IntlProvider locale="en">
<AdditionalFields {...props} />
</IntlProvider>
);

expect(await screen.findByTestId('additionalFields')).toBeInTheDocument();
});

it('sets the value correctly', async () => {
render(
<IntlProvider locale="en">
<AdditionalFields {...props} />
</IntlProvider>
);

expect(await screen.findByText(value)).toBeInTheDocument();
});

/**
* Test for the intermediate release process
*/
it('does not show the component if the value is undefined', async () => {
render(
<IntlProvider locale="en">
<AdditionalFields {...props} value={undefined} />
</IntlProvider>
);

expect(screen.queryByTestId('additional_fieldsJsonEditor')).not.toBeInTheDocument();
});

it('changes the value correctly', async () => {
const newValue = JSON.stringify({ bar: 'test' });

render(
<IntlProvider locale="en">
<AdditionalFields {...props} />
</IntlProvider>
);

const editor = await screen.findByTestId('additional_fieldsJsonEditor');

userEvent.clear(editor);
userEvent.paste(editor, newValue);

await waitFor(() => {
expect(onChange).toHaveBeenCalledWith(newValue);
});

expect(await screen.findByText(newValue)).toBeInTheDocument();
});

it('updating wth an empty string sets its value to null', async () => {
const newValue = JSON.stringify({ bar: 'test' });

render(
<IntlProvider locale="en">
<AdditionalFields {...props} />
</IntlProvider>
);

const editor = await screen.findByTestId('additional_fieldsJsonEditor');

userEvent.paste(editor, newValue);
userEvent.clear(editor);

await waitFor(() => {
expect(onChange).toHaveBeenCalledWith(null);
});
});
});
Loading