Skip to content

Commit

Permalink
[Connectors][ServiceNow] Rename isLegacy configuration property (#115028
Browse files Browse the repository at this point in the history
)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Oct 25, 2021
1 parent 59815a0 commit 62e2038
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('api_sir', () => {
});

describe('prepareParams', () => {
test('it prepares the params correctly when the connector is legacy', async () => {
test('it prepares the params correctly when the connector uses the old API', async () => {
expect(prepareParams(true, sirParams)).toEqual({
...sirParams,
incident: {
Expand All @@ -145,7 +145,7 @@ describe('api_sir', () => {
});
});

test('it prepares the params correctly when the connector is not legacy', async () => {
test('it prepares the params correctly when the connector does not uses the old API', async () => {
expect(prepareParams(false, sirParams)).toEqual({
...sirParams,
incident: {
Expand All @@ -158,7 +158,7 @@ describe('api_sir', () => {
});
});

test('it prepares the params correctly when the connector is legacy and the observables are undefined', async () => {
test('it prepares the params correctly when the connector uses the old API and the observables are undefined', async () => {
const {
dest_ip: destIp,
source_ip: sourceIp,
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('api_sir', () => {
const res = await apiSIR.pushToService({
externalService,
params,
config: { isLegacy: false },
config: { usesTableApi: false },
secrets: {},
logger: mockedLogger,
commentFieldKey: 'work_notes',
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('api_sir', () => {
await apiSIR.pushToService({
externalService,
params,
config: { isLegacy: false },
config: { usesTableApi: false },
secrets: {},
logger: mockedLogger,
commentFieldKey: 'work_notes',
Expand All @@ -244,12 +244,12 @@ describe('api_sir', () => {
);
});

test('it does not call bulkAddObservableToIncident if it a legacy connector', async () => {
test('it does not call bulkAddObservableToIncident if the connector uses the old API', async () => {
const params = { ...sirParams, incident: { ...sirParams.incident, externalId: null } };
await apiSIR.pushToService({
externalService,
params,
config: { isLegacy: true },
config: { usesTableApi: true },
secrets: {},
logger: mockedLogger,
commentFieldKey: 'work_notes',
Expand All @@ -274,7 +274,7 @@ describe('api_sir', () => {
await apiSIR.pushToService({
externalService,
params,
config: { isLegacy: false },
config: { usesTableApi: false },
secrets: {},
logger: mockedLogger,
commentFieldKey: 'work_notes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ const observablesToString = (obs: string | string[] | null | undefined): string
};

export const prepareParams = (
isLegacy: boolean,
usesTableApi: boolean,
params: PushToServiceApiParamsSIR
): PushToServiceApiParamsSIR => {
if (isLegacy) {
if (usesTableApi) {
/**
* The schema has change to accept an array of observables
* or a string. In the case of a legacy connector we need to
* or a string. In the case of connector that uses the old API we need to
* convert the observables to a string
*/
return {
Expand All @@ -81,8 +81,8 @@ export const prepareParams = (
}

/**
* For non legacy connectors the observables
* will be added in a different call.
* For connectors that do not use the old API
* the observables will be added in a different call.
* They need to be set to null when sending the fields
* to ServiceNow
*/
Expand All @@ -108,7 +108,7 @@ const pushToServiceHandler = async ({
}: PushToServiceApiHandlerArgs): Promise<PushToServiceResponse> => {
const res = await api.pushToService({
externalService,
params: prepareParams(!!config.isLegacy, params as PushToServiceApiParamsSIR),
params: prepareParams(!!config.usesTableApi, params as PushToServiceApiParamsSIR),
config,
secrets,
commentFieldKey,
Expand All @@ -130,7 +130,7 @@ const pushToServiceHandler = async ({
* through the pushToService call.
*/

if (!config.isLegacy) {
if (!config.usesTableApi) {
const sirExternalService = externalService as ExternalServiceSIR;

const obsWithType: Array<[string[], ObservableTypes]> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ExternalIncidentServiceConfigurationBase = {

export const ExternalIncidentServiceConfiguration = {
...ExternalIncidentServiceConfigurationBase,
isLegacy: schema.boolean({ defaultValue: true }),
usesTableApi: schema.boolean({ defaultValue: true }),
};

export const ExternalIncidentServiceConfigurationBaseSchema = schema.object(
Expand Down Expand Up @@ -49,7 +49,7 @@ const CommonAttributes = {
externalId: schema.nullable(schema.string()),
category: schema.nullable(schema.string()),
subcategory: schema.nullable(schema.string()),
correlation_id: schema.nullable(schema.string()),
correlation_id: schema.nullable(schema.string({ defaultValue: DEFAULT_ALERTS_GROUPING_KEY })),
correlation_display: schema.nullable(schema.string()),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const createExternalService: ServiceFactory = (
configurationUtilities: ActionsConfigurationUtilities,
{ table, importSetTable, useImportAPI, appScope }: SNProductsConfigValue
): ExternalService => {
const { apiUrl: url, isLegacy } = config as ServiceNowPublicConfigurationType;
const { apiUrl: url, usesTableApi: usesTableApiConfigValue } =
config as ServiceNowPublicConfigurationType;
const { username, password } = secrets as ServiceNowSecretConfigurationType;

if (!url || !username || !password) {
Expand All @@ -57,11 +58,11 @@ export const createExternalService: ServiceFactory = (
auth: { username, password },
});

const useOldApi = !useImportAPI || isLegacy;
const useTableApi = !useImportAPI || usesTableApiConfigValue;

const getCreateIncidentUrl = () => (useOldApi ? tableApiIncidentUrl : importSetTableUrl);
const getCreateIncidentUrl = () => (useTableApi ? tableApiIncidentUrl : importSetTableUrl);
const getUpdateIncidentUrl = (incidentId: string) =>
useOldApi ? `${tableApiIncidentUrl}/${incidentId}` : importSetTableUrl;
useTableApi ? `${tableApiIncidentUrl}/${incidentId}` : importSetTableUrl;

const getIncidentViewURL = (id: string) => {
// Based on: https://docs.servicenow.com/bundle/orlando-platform-user-interface/page/use/navigation/reference/r_NavigatingByURLExamples.html
Expand Down Expand Up @@ -105,7 +106,7 @@ export const createExternalService: ServiceFactory = (

/**
* Gets the Elastic SN Application information including the current version.
* It should not be used on legacy connectors.
* It should not be used on connectors that use the old API.
*/
const getApplicationInformation = async (): Promise<GetApplicationInfoResponse> => {
try {
Expand All @@ -129,7 +130,7 @@ export const createExternalService: ServiceFactory = (
logger.debug(`Create incident: Application scope: ${scope}: Application version${version}`);

const checkIfApplicationIsInstalled = async () => {
if (!useOldApi) {
if (!useTableApi) {
const { version, scope } = await getApplicationInformation();
logApplicationInfo(scope, version);
}
Expand Down Expand Up @@ -180,17 +181,17 @@ export const createExternalService: ServiceFactory = (
url: getCreateIncidentUrl(),
logger,
method: 'post',
data: prepareIncident(useOldApi, incident),
data: prepareIncident(useTableApi, incident),
configurationUtilities,
});

checkInstance(res);

if (!useOldApi) {
if (!useTableApi) {
throwIfImportSetApiResponseIsAnError(res.data);
}

const incidentId = useOldApi ? res.data.result.sys_id : res.data.result[0].sys_id;
const incidentId = useTableApi ? res.data.result.sys_id : res.data.result[0].sys_id;
const insertedIncident = await getIncident(incidentId);

return {
Expand All @@ -212,23 +213,23 @@ export const createExternalService: ServiceFactory = (
axios: axiosInstance,
url: getUpdateIncidentUrl(incidentId),
// Import Set API supports only POST.
method: useOldApi ? 'patch' : 'post',
method: useTableApi ? 'patch' : 'post',
logger,
data: {
...prepareIncident(useOldApi, incident),
...prepareIncident(useTableApi, incident),
// elastic_incident_id is used to update the incident when using the Import Set API.
...(useOldApi ? {} : { elastic_incident_id: incidentId }),
...(useTableApi ? {} : { elastic_incident_id: incidentId }),
},
configurationUtilities,
});

checkInstance(res);

if (!useOldApi) {
if (!useTableApi) {
throwIfImportSetApiResponseIsAnError(res.data);
}

const id = useOldApi ? res.data.result.sys_id : res.data.result[0].sys_id;
const id = useTableApi ? res.data.result.sys_id : res.data.result[0].sys_id;
const updatedIncident = await getIncident(id);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('successful migrations', () => {
expect(migratedAction).toEqual(action);
});

test('set isLegacy config property for .servicenow', () => {
test('set usesTableApi config property for .servicenow', () => {
const migration716 = getActionsMigrations(encryptedSavedObjectsSetup)['7.16.0'];
const action = getMockDataForServiceNow();
const migratedAction = migration716(action, context);
Expand All @@ -177,13 +177,13 @@ describe('successful migrations', () => {
...action.attributes,
config: {
apiUrl: 'https://example.com',
isLegacy: true,
usesTableApi: true,
},
},
});
});

test('set isLegacy config property for .servicenow-sir', () => {
test('set usesTableApi config property for .servicenow-sir', () => {
const migration716 = getActionsMigrations(encryptedSavedObjectsSetup)['7.16.0'];
const action = getMockDataForServiceNow({ actionTypeId: '.servicenow-sir' });
const migratedAction = migration716(action, context);
Expand All @@ -194,13 +194,13 @@ describe('successful migrations', () => {
...action.attributes,
config: {
apiUrl: 'https://example.com',
isLegacy: true,
usesTableApi: true,
},
},
});
});

test('it does not set isLegacy config for other connectors', () => {
test('it does not set usesTableApi config for other connectors', () => {
const migration716 = getActionsMigrations(encryptedSavedObjectsSetup)['7.16.0'];
const action = getMockData();
const migratedAction = migration716(action, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function getActionsMigrations(
doc.attributes.actionTypeId === '.servicenow' ||
doc.attributes.actionTypeId === '.servicenow-sir' ||
doc.attributes.actionTypeId === '.email',
pipeMigrations(markOldServiceNowITSMConnectorAsLegacy, setServiceConfigIfNotSet)
pipeMigrations(addUsesTableApiToServiceNowConnectors, setServiceConfigIfNotSet)
);

const migrationActions800 = createEsoMigration(
Expand Down Expand Up @@ -197,7 +197,7 @@ const addIsMissingSecretsField = (
};
};

const markOldServiceNowITSMConnectorAsLegacy = (
const addUsesTableApiToServiceNowConnectors = (
doc: SavedObjectUnsanitizedDoc<RawAction>
): SavedObjectUnsanitizedDoc<RawAction> => {
if (
Expand All @@ -213,7 +213,7 @@ const markOldServiceNowITSMConnectorAsLegacy = (
...doc.attributes,
config: {
...doc.attributes.config,
isLegacy: true,
usesTableApi: true,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ describe('Connectors', () => {
).toBe('Update My Connector');
});

test('it shows the deprecated callout when the connector is legacy', async () => {
test('it shows the deprecated callout when the connector is deprecated', async () => {
render(
<Connectors
{...props}
selectedConnector={{ id: 'servicenow-legacy', type: ConnectorTypes.serviceNowITSM }}
selectedConnector={{ id: 'servicenow-uses-table-api', type: ConnectorTypes.serviceNowITSM }}
/>,
{
// wrapper: TestProviders produces a TS error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ActionConnector, CaseConnectorMapping } from '../../containers/configur
import { Mapping } from './mapping';
import { ActionTypeConnector, ConnectorTypes } from '../../../common';
import { DeprecatedCallout } from '../connectors/deprecated_callout';
import { isLegacyConnector } from '../utils';
import { isDeprecatedConnector } from '../utils';

const EuiFormRowExtended = styled(EuiFormRow)`
.euiFormRow__labelWrapper {
Expand Down Expand Up @@ -111,7 +111,7 @@ const ConnectorsComponent: React.FC<Props> = ({
appendAddConnectorButton={true}
/>
</EuiFlexItem>
{selectedConnector.type !== ConnectorTypes.none && isLegacyConnector(connector) && (
{selectedConnector.type !== ConnectorTypes.none && isDeprecatedConnector(connector) && (
<EuiFlexItem grow={false}>
<DeprecatedCallout />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('ConnectorsDropdown', () => {
"value": "servicenow-sir",
},
Object {
"data-test-subj": "dropdown-connector-servicenow-legacy",
"data-test-subj": "dropdown-connector-servicenow-uses-table-api",
"inputDisplay": <EuiFlexGroup
alignItems="center"
gutterSize="s"
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('ConnectorsDropdown', () => {
/>
</EuiFlexItem>
</EuiFlexGroup>,
"value": "servicenow-legacy",
"value": "servicenow-uses-table-api",
},
]
`);
Expand Down Expand Up @@ -288,8 +288,8 @@ describe('ConnectorsDropdown', () => {
).not.toThrowError();
});

test('it shows the deprecated tooltip when the connector is legacy', () => {
render(<ConnectorsDropdown {...props} selectedConnector="servicenow-legacy" />, {
test('it shows the deprecated tooltip when the connector is deprecated', () => {
render(<ConnectorsDropdown {...props} selectedConnector="servicenow-uses-table-api" />, {
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ConnectorTypes } from '../../../common';
import { ActionConnector } from '../../containers/configure/types';
import * as i18n from './translations';
import { useKibana } from '../../common/lib/kibana';
import { getConnectorIcon, isLegacyConnector } from '../utils';
import { getConnectorIcon, isDeprecatedConnector } from '../utils';
import { euiStyled } from '../../../../../../src/plugins/kibana_react/common';

export interface Props {
Expand Down Expand Up @@ -95,10 +95,10 @@ const ConnectorsDropdownComponent: React.FC<Props> = ({
<EuiFlexItem grow={false}>
<span>
{connector.name}
{isLegacyConnector(connector) && ` (${i18n.DEPRECATED_TOOLTIP_TEXT})`}
{isDeprecatedConnector(connector) && ` (${i18n.DEPRECATED_TOOLTIP_TEXT})`}
</span>
</EuiFlexItem>
{isLegacyConnector(connector) && (
{isDeprecatedConnector(connector) && (
<EuiFlexItem grow={false}>
<StyledEuiIconTip
aria-label={i18n.DEPRECATED_TOOLTIP_CONTENT}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('DeprecatedCallout', () => {
render(<DeprecatedCallout />);
expect(screen.getByText('This connector type is deprecated')).toBeInTheDocument();
expect(screen.getByText('Update this connector, or create a new one.')).toBeInTheDocument();
expect(screen.getByTestId('legacy-connector-warning-callout')).toHaveClass(
expect(screen.getByTestId('deprecated-connector-warning-callout')).toHaveClass(
'euiCallOut euiCallOut--warning'
);
});

test('it renders a danger flyout correctly', () => {
render(<DeprecatedCallout type="danger" />);
expect(screen.getByTestId('legacy-connector-warning-callout')).toHaveClass(
expect(screen.getByTestId('deprecated-connector-warning-callout')).toHaveClass(
'euiCallOut euiCallOut--danger'
);
});
Expand Down
Loading

0 comments on commit 62e2038

Please sign in to comment.