Skip to content

Commit 43e0043

Browse files
authored
[Connectors][ServiceNow] Default isLegacy to true for API consumers (elastic#115367)
1 parent 800cfb5 commit 43e0043

File tree

8 files changed

+68
-6
lines changed

8 files changed

+68
-6
lines changed

docs/management/connectors/action-types/servicenow-sir.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
3737
actionTypeId: .servicenow-sir
3838
config:
3939
apiUrl: https://example.service-now.com/
40+
isLegacy: false
4041
secrets:
4142
username: testuser
4243
password: passwordkeystorevalue
@@ -45,6 +46,9 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
4546
Config defines information for the connector type.
4647

4748
`apiUrl`:: An address that corresponds to *URL*.
49+
`isLegacy`:: A boolean that indicates if the connector should use the Table API (legacy) or the Import Set API.
50+
51+
Note: If `isLegacy` is set to false the Elastic application should be installed in ServiceNow.
4852

4953
Secrets defines sensitive information for the connector type.
5054

docs/management/connectors/action-types/servicenow.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
3737
actionTypeId: .servicenow
3838
config:
3939
apiUrl: https://example.service-now.com/
40+
isLegacy: false
4041
secrets:
4142
username: testuser
4243
password: passwordkeystorevalue
@@ -45,6 +46,9 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
4546
Config defines information for the connector type.
4647

4748
`apiUrl`:: An address that corresponds to *URL*.
49+
`isLegacy`:: A boolean that indicates if the connector should use the Table API (legacy) or the Import Set API.
50+
51+
Note: If `isLegacy` is set to false the Elastic application should be installed in ServiceNow.
4852

4953
Secrets defines sensitive information for the connector type.
5054

x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const ExternalIncidentServiceConfigurationBase = {
1414

1515
export const ExternalIncidentServiceConfiguration = {
1616
...ExternalIncidentServiceConfigurationBase,
17-
isLegacy: schema.boolean({ defaultValue: false }),
17+
isLegacy: schema.boolean({ defaultValue: true }),
1818
};
1919

2020
export const ExternalIncidentServiceConfigurationBaseSchema = schema.object(

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.test.tsx

+38
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,43 @@ describe('ServiceNowActionConnectorFields renders', () => {
414414
.includes(errorMessage)
415415
).toBeTruthy();
416416
});
417+
418+
test('should set the isLegacy to false when creating a connector', async () => {
419+
const newConnector = { ...usesTableApiConnector, config: {}, secrets: {} };
420+
const editActionConfig = jest.fn();
421+
422+
mountWithIntl(
423+
<ServiceNowConnectorFields
424+
// @ts-expect-error
425+
action={newConnector}
426+
errors={{ apiUrl: [], username: [], password: [] }}
427+
editActionConfig={editActionConfig}
428+
editActionSecrets={() => {}}
429+
readOnly={false}
430+
setCallbacks={setCallbacks}
431+
isEdit={false}
432+
/>
433+
);
434+
435+
expect(editActionConfig).toHaveBeenCalledWith('isLegacy', false);
436+
});
437+
438+
test('it should set the legacy attribute if it is not undefined', async () => {
439+
const editActionConfig = jest.fn();
440+
441+
mountWithIntl(
442+
<ServiceNowConnectorFields
443+
action={usesTableApiConnector}
444+
errors={{ apiUrl: [], username: [], password: [] }}
445+
editActionConfig={editActionConfig}
446+
editActionSecrets={() => {}}
447+
readOnly={false}
448+
setCallbacks={setCallbacks}
449+
isEdit={false}
450+
/>
451+
);
452+
453+
expect(editActionConfig).not.toHaveBeenCalled();
454+
});
417455
});
418456
});

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/servicenow/servicenow_connectors.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<ServiceNowA
3636
http,
3737
notifications: { toasts },
3838
} = useKibana().services;
39-
const { apiUrl } = action.config;
39+
const { apiUrl, isLegacy } = action.config;
4040
const { username, password } = action.secrets;
4141
const isOldConnector = isLegacyConnector(action);
4242

@@ -123,6 +123,18 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<ServiceNowA
123123
toasts,
124124
]);
125125

126+
/**
127+
* Defaults the isLegacy attribute to false
128+
* if it is not defined. The isLegacy attribute
129+
* will be undefined only at the creation of
130+
* the connector.
131+
*/
132+
useEffect(() => {
133+
if (isLegacy == null) {
134+
editActionConfig('isLegacy', false);
135+
}
136+
});
137+
126138
return (
127139
<>
128140
{showUpdateConnector && (

x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow_itsm.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
9191
connector_type_id: '.servicenow',
9292
config: {
9393
apiUrl: serviceNowSimulatorURL,
94+
isLegacy: false,
9495
},
9596
secrets: mockServiceNow.secrets,
9697
})
@@ -125,7 +126,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
125126
});
126127
});
127128

128-
it('should set the isLegacy to false when not provided', async () => {
129+
it('should set the isLegacy to true when not provided', async () => {
129130
const { body: createdAction } = await supertest
130131
.post('/api/actions/connector')
131132
.set('kbn-xsrf', 'foo')
@@ -143,7 +144,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
143144
.get(`/api/actions/connector/${createdAction.id}`)
144145
.expect(200);
145146

146-
expect(fetchedAction.config.isLegacy).to.be(false);
147+
expect(fetchedAction.config.isLegacy).to.be(true);
147148
});
148149

149150
it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => {

x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow_sir.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
9595
connector_type_id: '.servicenow-sir',
9696
config: {
9797
apiUrl: serviceNowSimulatorURL,
98+
isLegacy: false,
9899
},
99100
secrets: mockServiceNow.secrets,
100101
})
@@ -129,7 +130,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
129130
});
130131
});
131132

132-
it('should set the isLegacy to false when not provided', async () => {
133+
it('should set the isLegacy to true when not provided', async () => {
133134
const { body: createdAction } = await supertest
134135
.post('/api/actions/connector')
135136
.set('kbn-xsrf', 'foo')
@@ -147,7 +148,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
147148
.get(`/api/actions/connector/${createdAction.id}`)
148149
.expect(200);
149150

150-
expect(fetchedAction.config.isLegacy).to.be(false);
151+
expect(fetchedAction.config.isLegacy).to.be(true);
151152
});
152153

153154
it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => {

x-pack/test/case_api_integration/common/lib/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ export const getServiceNowConnector = () => ({
329329
},
330330
config: {
331331
apiUrl: 'http://some.non.existent.com',
332+
isLegacy: false,
332333
},
333334
});
334335

@@ -385,6 +386,7 @@ export const getServiceNowSIRConnector = () => ({
385386
},
386387
config: {
387388
apiUrl: 'http://some.non.existent.com',
389+
isLegacy: false,
388390
},
389391
});
390392

0 commit comments

Comments
 (0)