Skip to content

Commit

Permalink
[Connectors][ServiceNow] Remove SN flags (elastic#117511)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas authored Nov 5, 2021
1 parent d0567f8 commit 5ce12b2
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 98 deletions.
7 changes: 1 addition & 6 deletions x-pack/plugins/actions/server/builtin_action_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { getActionType as getJiraActionType } from './jira';
import { getActionType as getResilientActionType } from './resilient';
import { getActionType as getTeamsActionType } from './teams';
import { ENABLE_ITOM } from '../constants/connectors';
export type { ActionParamsType as EmailActionParams } from './email';
export { ActionTypeId as EmailActionTypeId } from './email';
export type { ActionParamsType as IndexActionParams } from './es_index';
Expand Down Expand Up @@ -72,12 +71,8 @@ export function registerBuiltInActionTypes({
actionTypeRegistry.register(getWebhookActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getServiceNowITSMActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getServiceNowSIRActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getServiceNowITOMActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getJiraActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getResilientActionType({ logger, configurationUtilities }));
actionTypeRegistry.register(getTeamsActionType({ logger, configurationUtilities }));

// TODO: Remove when ITOM is ready
if (ENABLE_ITOM) {
actionTypeRegistry.register(getServiceNowITOMActionType({ logger, configurationUtilities }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('config', () => {
importSetTable: 'x_elas2_inc_int_elastic_incident',
appScope: 'x_elas2_inc_int',
table: 'em_event',
useImportAPI: true,
useImportAPI: false,
commentFieldKey: 'work_notes',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* 2.0.
*/

import {
ENABLE_ITOM,
ENABLE_NEW_SN_ITSM_CONNECTOR,
ENABLE_NEW_SN_SIR_CONNECTOR,
} from '../../constants/connectors';
import { SNProductsConfig } from './types';

export const serviceNowITSMTable = 'incident';
Expand All @@ -24,21 +19,21 @@ export const snExternalServiceConfig: SNProductsConfig = {
importSetTable: 'x_elas2_inc_int_elastic_incident',
appScope: 'x_elas2_inc_int',
table: 'incident',
useImportAPI: ENABLE_NEW_SN_ITSM_CONNECTOR,
useImportAPI: true,
commentFieldKey: 'work_notes',
},
'.servicenow-sir': {
importSetTable: 'x_elas2_sir_int_elastic_si_incident',
appScope: 'x_elas2_sir_int',
table: 'sn_si_incident',
useImportAPI: ENABLE_NEW_SN_SIR_CONNECTOR,
useImportAPI: true,
commentFieldKey: 'work_notes',
},
'.servicenow-itom': {
importSetTable: 'x_elas2_inc_int_elastic_incident',
appScope: 'x_elas2_inc_int',
table: 'em_event',
useImportAPI: ENABLE_ITOM,
useImportAPI: false,
commentFieldKey: 'work_notes',
},
};
Expand Down
15 changes: 0 additions & 15 deletions x-pack/plugins/actions/server/constants/connectors.ts

This file was deleted.

41 changes: 41 additions & 0 deletions x-pack/plugins/cases/public/components/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,49 @@ describe('Utils', () => {
});

describe('isDeprecatedConnector', () => {
const connector = {
id: 'test',
actionTypeId: '.webhook',
name: 'Test',
config: { usesTableApi: false },
secrets: {},
isPreconfigured: false,
};

it('returns false if the connector is not defined', () => {
expect(isDeprecatedConnector()).toBe(false);
});

it('returns false if the connector is not ITSM or SecOps', () => {
expect(isDeprecatedConnector(connector)).toBe(false);
});

it('returns false if the connector is .servicenow and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow' })).toBe(false);
});

it('returns false if the connector is .servicenow-sir and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow-sir' })).toBe(false);
});

it('returns true if the connector is .servicenow and the usesTableApi=true', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow',
config: { usesTableApi: true },
})
).toBe(true);
});

it('returns true if the connector is .servicenow-sir and the usesTableApi=true', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow-sir',
config: { usesTableApi: true },
})
).toBe(true);
});
});
});
33 changes: 10 additions & 23 deletions x-pack/plugins/cases/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import { StartPlugins } from '../types';
import { connectorValidator as swimlaneConnectorValidator } from './connectors/swimlane/validator';
import { connectorValidator as servicenowConnectorValidator } from './connectors/servicenow/validator';
import { CaseActionConnector } from './types';
import {
ENABLE_NEW_SN_ITSM_CONNECTOR,
ENABLE_NEW_SN_SIR_CONNECTOR,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../actions/server/constants/connectors';

export const getConnectorById = (
id: string,
Expand Down Expand Up @@ -83,24 +78,16 @@ export const isDeprecatedConnector = (connector?: CaseActionConnector): boolean
return false;
}

if (!ENABLE_NEW_SN_ITSM_CONNECTOR && connector.actionTypeId === '.servicenow') {
return true;
if (connector.actionTypeId === '.servicenow' || connector.actionTypeId === '.servicenow-sir') {
/**
* Connector's prior to the Elastic ServiceNow application
* use the Table API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI)
* Connectors after the Elastic ServiceNow application use the
* Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
* A ServiceNow connector is considered deprecated if it uses the Table API.
*/
return !!connector.config.usesTableApi;
}

if (!ENABLE_NEW_SN_SIR_CONNECTOR && connector.actionTypeId === '.servicenow-sir') {
return true;
}

/**
* Connector's prior to the Elastic ServiceNow application
* use the Table API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI)
* Connectors after the Elastic ServiceNow application use the
* Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
* A ServiceNow connector is considered deprecated if it uses the Table API.
*
* All other connectors do not have the usesTableApi config property
* so the function will always return false for them.
*/

return !!connector.config.usesTableApi;
return false;
};
8 changes: 1 addition & 7 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ENABLE_ITOM } from '../../actions/server/constants/connectors';
import type { TransformConfigSchema } from './transforms/types';
import { ENABLE_CASE_CONNECTOR } from '../../cases/common';
import { METADATA_TRANSFORMS_PATTERN } from './endpoint/constants';
Expand Down Expand Up @@ -326,6 +324,7 @@ export const NOTIFICATION_SUPPORTED_ACTION_TYPES_IDS = [
'.resilient',
'.servicenow',
'.servicenow-sir',
'.servicenow-itom',
'.slack',
'.swimlane',
'.teams',
Expand All @@ -336,11 +335,6 @@ if (ENABLE_CASE_CONNECTOR) {
NOTIFICATION_SUPPORTED_ACTION_TYPES_IDS.push('.case');
}

// TODO: Remove when ITOM is ready
if (ENABLE_ITOM) {
NOTIFICATION_SUPPORTED_ACTION_TYPES_IDS.push('.servicenow-itom');
}

export const NOTIFICATION_THROTTLE_NO_ACTIONS = 'no_actions' as const;
export const NOTIFICATION_THROTTLE_RULE = 'rule' as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {
import { getJiraActionType } from './jira';
import { getResilientActionType } from './resilient';
import { getTeamsActionType } from './teams';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ENABLE_ITOM } from '../../../../../actions/server/constants/connectors';

export function registerBuiltInActionTypes({
actionTypeRegistry,
Expand All @@ -38,13 +36,9 @@ export function registerBuiltInActionTypes({
actionTypeRegistry.register(getSwimlaneActionType());
actionTypeRegistry.register(getWebhookActionType());
actionTypeRegistry.register(getServiceNowITSMActionType());
actionTypeRegistry.register(getServiceNowITOMActionType());
actionTypeRegistry.register(getServiceNowSIRActionType());
actionTypeRegistry.register(getJiraActionType());
actionTypeRegistry.register(getResilientActionType());
actionTypeRegistry.register(getTeamsActionType());

// TODO: Remove when ITOM is ready
if (ENABLE_ITOM) {
actionTypeRegistry.register(getServiceNowITOMActionType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,49 @@ describe('helpers', () => {
});

describe('isDeprecatedConnector', () => {
const connector = {
id: 'test',
actionTypeId: '.webhook',
name: 'Test',
config: { apiUrl: 'http://example.com', usesTableApi: false },
secrets: { username: 'test', password: 'test' },
isPreconfigured: false as const,
};

it('returns false if the connector is not defined', () => {
expect(isDeprecatedConnector()).toBe(false);
});

it('returns false if the connector is not ITSM or SecOps', () => {
expect(isDeprecatedConnector(connector)).toBe(false);
});

it('returns false if the connector is .servicenow and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow' })).toBe(false);
});

it('returns false if the connector is .servicenow-sir and the usesTableApi=false', () => {
expect(isDeprecatedConnector({ ...connector, actionTypeId: '.servicenow-sir' })).toBe(false);
});

it('returns true if the connector is .servicenow and the usesTableApi=true', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow',
config: { ...connector.config, usesTableApi: true },
})
).toBe(true);
});

it('returns true if the connector is .servicenow-sir and the usesTableApi=true', () => {
expect(
isDeprecatedConnector({
...connector,
actionTypeId: '.servicenow-sir',
config: { ...connector.config, usesTableApi: true },
})
).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
*/

import { EuiSelectOption } from '@elastic/eui';
import {
ENABLE_NEW_SN_ITSM_CONNECTOR,
ENABLE_NEW_SN_SIR_CONNECTOR,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../actions/server/constants/connectors';
import { IErrorObject } from '../../../../../public/types';
import { AppInfo, Choice, RESTApiError, ServiceNowActionConnector } from './types';

Expand All @@ -33,22 +28,16 @@ export const isDeprecatedConnector = (connector?: ServiceNowActionConnector): bo
return false;
}

if (!ENABLE_NEW_SN_ITSM_CONNECTOR && connector.actionTypeId === '.servicenow') {
return true;
if (connector.actionTypeId === '.servicenow' || connector.actionTypeId === '.servicenow-sir') {
/**
* Connector's prior to the Elastic ServiceNow application
* use the Table API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_TableAPI)
* Connectors after the Elastic ServiceNow application use the
* Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
* A ServiceNow connector is considered deprecated if it uses the Table API.
*/
return !!connector.config.usesTableApi;
}

if (!ENABLE_NEW_SN_SIR_CONNECTOR && connector.actionTypeId === '.servicenow-sir') {
return true;
}

/**
* Connectors after the Elastic ServiceNow application use the
* Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
* A ServiceNow connector is considered deprecated if it uses the Table API.
*
* All other connectors do not have the usesTableApi config property
* so the function will always return false for them.
*/

return !!connector.config.usesTableApi;
return false;
};
Loading

0 comments on commit 5ce12b2

Please sign in to comment.