Skip to content

Commit

Permalink
[Connectors] Split ServiceNow connector type (#141961)
Browse files Browse the repository at this point in the history
* Splitting public servicenow files

* Splitting server servicenow files

* Fixing checks

* Fixing checks

* Moving xmatters to stack

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
ymao1 and kibanamachine authored Oct 5, 2022
1 parent c9af639 commit bb8a3c3
Show file tree
Hide file tree
Showing 107 changed files with 2,020 additions and 547 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
PushToServiceApiParamsITSM as ServiceNowITSMPushToServiceApiParams,
PushToServiceApiParamsSIR as ServiceNowSIRPushToServiceApiParams,
ServiceNowITSMIncident,
} from '@kbn/stack-connectors-plugin/server/connector_types/cases/servicenow/types';
} from '@kbn/stack-connectors-plugin/server/connector_types/lib/servicenow/types';
import { UserProfile } from '@kbn/security-plugin/common';
import { CaseResponse, ConnectorMappingsAttributes } from '../../../common/api';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
export { getCasesWebhookConnectorType } from './cases_webhook';
export { getJiraConnectorType } from './jira';
export { getResilientConnectorType } from './resilient';
export {
getServiceNowITSMConnectorType,
getServiceNowSIRConnectorType,
getServiceNowITOMConnectorType,
} from './servicenow';
export { getServiceNowITSMConnectorType } from './servicenow_itsm';
export { getServiceNowSIRConnectorType } from './servicenow_sir';
export { getSwimlaneConnectorType } from './swimlane';
export { getXmattersConnectorType } from './xmatters';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
* 2.0.
*/

export {
getServiceNowITSMConnectorType,
getServiceNowSIRConnectorType,
getServiceNowITOMConnectorType,
} from './servicenow';
export { getServiceNowITSMConnectorType } from './servicenow_itsm';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 { TypeRegistry } from '@kbn/triggers-actions-ui-plugin/public/application/type_registry';
import { registerConnectorTypes } from '../..';
import type { ActionTypeModel as ConnectorTypeModel } from '@kbn/triggers-actions-ui-plugin/public/types';
import { registrationServicesMock } from '../../../mocks';

const SERVICENOW_ITSM_CONNECTOR_TYPE_ID = '.servicenow';
let connectorTypeRegistry: TypeRegistry<ConnectorTypeModel>;

beforeAll(() => {
connectorTypeRegistry = new TypeRegistry<ConnectorTypeModel>();
registerConnectorTypes({ connectorTypeRegistry, services: registrationServicesMock });
});

describe('connectorTypeRegistry.get() works', () => {
test(`${SERVICENOW_ITSM_CONNECTOR_TYPE_ID}: connector type static data is as expected`, () => {
const connectorTypeModel = connectorTypeRegistry.get(SERVICENOW_ITSM_CONNECTOR_TYPE_ID);
expect(connectorTypeModel.id).toEqual(SERVICENOW_ITSM_CONNECTOR_TYPE_ID);
});
});

describe('servicenow action params validation', () => {
test(`${SERVICENOW_ITSM_CONNECTOR_TYPE_ID}: action params validation succeeds when action params is valid`, async () => {
const connectorTypeModel = connectorTypeRegistry.get(SERVICENOW_ITSM_CONNECTOR_TYPE_ID);
const actionParams = {
subActionParams: { incident: { short_description: 'some title {{test}}' }, comments: [] },
};

expect(await connectorTypeModel.validateParams(actionParams)).toEqual({
errors: { ['subActionParams.incident.short_description']: [] },
});
});

test(`${SERVICENOW_ITSM_CONNECTOR_TYPE_ID}: params validation fails when short_description is not valid`, async () => {
const connectorTypeModel = connectorTypeRegistry.get(SERVICENOW_ITSM_CONNECTOR_TYPE_ID);
const actionParams = {
subActionParams: { incident: { short_description: '' }, comments: [] },
};

expect(await connectorTypeModel.validateParams(actionParams)).toEqual({
errors: {
['subActionParams.incident.short_description']: ['Short description is required.'],
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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 { lazy } from 'react';
import { i18n } from '@kbn/i18n';
import type {
ActionTypeModel as ConnectorTypeModel,
GenericValidationResult,
} from '@kbn/triggers-actions-ui-plugin/public';
import { ServiceNowConfig, ServiceNowSecrets } from '../../lib/servicenow/types';
import { ServiceNowITSMActionParams } from './types';
import {
getConnectorDescriptiveTitle,
getSelectedConnectorIcon,
} from '../../lib/servicenow/helpers';

export const SERVICENOW_ITSM_DESC = i18n.translate(
'xpack.stackConnectors.components.serviceNowITSM.selectMessageText',
{
defaultMessage: 'Create an incident in ServiceNow ITSM.',
}
);

export const SERVICENOW_ITSM_TITLE = i18n.translate(
'xpack.stackConnectors.components.serviceNowITSM.connectorTypeTitle',
{
defaultMessage: 'ServiceNow ITSM',
}
);

export function getServiceNowITSMConnectorType(): ConnectorTypeModel<
ServiceNowConfig,
ServiceNowSecrets,
ServiceNowITSMActionParams
> {
return {
id: '.servicenow',
iconClass: lazy(() => import('./logo')),
selectMessage: SERVICENOW_ITSM_DESC,
actionTypeTitle: SERVICENOW_ITSM_TITLE,
actionConnectorFields: lazy(() => import('../../lib/servicenow/servicenow_connectors')),
validateParams: async (
actionParams: ServiceNowITSMActionParams
): Promise<GenericValidationResult<unknown>> => {
const translations = await import('../../lib/servicenow/translations');
const errors = {
'subActionParams.incident.short_description': new Array<string>(),
};
const validationResult = {
errors,
};
if (
actionParams.subActionParams &&
actionParams.subActionParams.incident &&
!actionParams.subActionParams.incident.short_description?.length
) {
errors['subActionParams.incident.short_description'].push(translations.TITLE_REQUIRED);
}
return validationResult;
},
actionParamsFields: lazy(() => import('./servicenow_itsm_params')),
customConnectorSelectItem: {
getText: getConnectorDescriptiveTitle,
getComponent: getSelectedConnectorIcon,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';
import { act } from '@testing-library/react';

import { ActionConnector } from '@kbn/triggers-actions-ui-plugin/public/types';
import { useGetChoices } from './use_get_choices';
import { useGetChoices } from '../../lib/servicenow/use_get_choices';
import ServiceNowITSMParamsFields from './servicenow_itsm_params';
import { Choice } from './types';
import { Choice } from '../../lib/servicenow/types';
import { merge } from 'lodash';

jest.mock('./use_get_choices');
jest.mock('../../lib/servicenow/use_get_choices');
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');

const useGetChoicesMock = useGetChoices as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import {
TextFieldWithMessageVariables,
useKibana,
} from '@kbn/triggers-actions-ui-plugin/public';
import { ServiceNowITSMActionParams, Choice, Fields } from './types';
import { useGetChoices } from './use_get_choices';
import { choicesToEuiOptions, DEFAULT_CORRELATION_ID } from './helpers';
import { Choice, Fields } from '../../lib/servicenow/types';
import { ServiceNowITSMActionParams } from './types';
import { useGetChoices } from '../../lib/servicenow/use_get_choices';
import { choicesToEuiOptions, DEFAULT_CORRELATION_ID } from '../../lib/servicenow/helpers';

import * as i18n from './translations';
import * as i18n from '../../lib/servicenow/translations';

const useGetChoicesFields = ['urgency', 'severity', 'impact', 'category', 'subcategory'];
const defaultFields: Fields = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { ExecutorSubActionPushParamsITSM } from '../../../../server/connector_types/lib/servicenow/types';

export interface ServiceNowITSMActionParams {
subAction: string;
subActionParams: ExecutorSubActionPushParamsITSM;
}
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 { getServiceNowSIRConnectorType } from './servicenow_sir';
Loading

0 comments on commit bb8a3c3

Please sign in to comment.