[Connectors][ServiceNow] Default isLegacy to true for API consumers (#115367)

This commit is contained in:
Christos Nasikas 2021-10-21 12:41:56 +03:00 committed by GitHub
parent 800cfb504c
commit 43e0043fcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 6 deletions

View file

@ -37,6 +37,7 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
actionTypeId: .servicenow-sir
config:
apiUrl: https://example.service-now.com/
isLegacy: false
secrets:
username: testuser
password: passwordkeystorevalue
@ -45,6 +46,9 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
Config defines information for the connector type.
`apiUrl`:: An address that corresponds to *URL*.
`isLegacy`:: A boolean that indicates if the connector should use the Table API (legacy) or the Import Set API.
Note: If `isLegacy` is set to false the Elastic application should be installed in ServiceNow.
Secrets defines sensitive information for the connector type.

View file

@ -37,6 +37,7 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
actionTypeId: .servicenow
config:
apiUrl: https://example.service-now.com/
isLegacy: false
secrets:
username: testuser
password: passwordkeystorevalue
@ -45,6 +46,9 @@ Use the <<action-settings, Action configuration settings>> to customize connecto
Config defines information for the connector type.
`apiUrl`:: An address that corresponds to *URL*.
`isLegacy`:: A boolean that indicates if the connector should use the Table API (legacy) or the Import Set API.
Note: If `isLegacy` is set to false the Elastic application should be installed in ServiceNow.
Secrets defines sensitive information for the connector type.

View file

@ -14,7 +14,7 @@ export const ExternalIncidentServiceConfigurationBase = {
export const ExternalIncidentServiceConfiguration = {
...ExternalIncidentServiceConfigurationBase,
isLegacy: schema.boolean({ defaultValue: false }),
isLegacy: schema.boolean({ defaultValue: true }),
};
export const ExternalIncidentServiceConfigurationBaseSchema = schema.object(

View file

@ -414,5 +414,43 @@ describe('ServiceNowActionConnectorFields renders', () => {
.includes(errorMessage)
).toBeTruthy();
});
test('should set the isLegacy to false when creating a connector', async () => {
const newConnector = { ...usesTableApiConnector, config: {}, secrets: {} };
const editActionConfig = jest.fn();
mountWithIntl(
<ServiceNowConnectorFields
// @ts-expect-error
action={newConnector}
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={editActionConfig}
editActionSecrets={() => {}}
readOnly={false}
setCallbacks={setCallbacks}
isEdit={false}
/>
);
expect(editActionConfig).toHaveBeenCalledWith('isLegacy', false);
});
test('it should set the legacy attribute if it is not undefined', async () => {
const editActionConfig = jest.fn();
mountWithIntl(
<ServiceNowConnectorFields
action={usesTableApiConnector}
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={editActionConfig}
editActionSecrets={() => {}}
readOnly={false}
setCallbacks={setCallbacks}
isEdit={false}
/>
);
expect(editActionConfig).not.toHaveBeenCalled();
});
});
});

View file

@ -36,7 +36,7 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<ServiceNowA
http,
notifications: { toasts },
} = useKibana().services;
const { apiUrl } = action.config;
const { apiUrl, isLegacy } = action.config;
const { username, password } = action.secrets;
const isOldConnector = isLegacyConnector(action);
@ -123,6 +123,18 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<ServiceNowA
toasts,
]);
/**
* Defaults the isLegacy attribute to false
* if it is not defined. The isLegacy attribute
* will be undefined only at the creation of
* the connector.
*/
useEffect(() => {
if (isLegacy == null) {
editActionConfig('isLegacy', false);
}
});
return (
<>
{showUpdateConnector && (

View file

@ -91,6 +91,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
connector_type_id: '.servicenow',
config: {
apiUrl: serviceNowSimulatorURL,
isLegacy: false,
},
secrets: mockServiceNow.secrets,
})
@ -125,7 +126,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
});
});
it('should set the isLegacy to false when not provided', async () => {
it('should set the isLegacy to true when not provided', async () => {
const { body: createdAction } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'foo')
@ -143,7 +144,7 @@ export default function serviceNowITSMTest({ getService }: FtrProviderContext) {
.get(`/api/actions/connector/${createdAction.id}`)
.expect(200);
expect(fetchedAction.config.isLegacy).to.be(false);
expect(fetchedAction.config.isLegacy).to.be(true);
});
it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => {

View file

@ -95,6 +95,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
connector_type_id: '.servicenow-sir',
config: {
apiUrl: serviceNowSimulatorURL,
isLegacy: false,
},
secrets: mockServiceNow.secrets,
})
@ -129,7 +130,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
});
});
it('should set the isLegacy to false when not provided', async () => {
it('should set the isLegacy to true when not provided', async () => {
const { body: createdAction } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'foo')
@ -147,7 +148,7 @@ export default function serviceNowSIRTest({ getService }: FtrProviderContext) {
.get(`/api/actions/connector/${createdAction.id}`)
.expect(200);
expect(fetchedAction.config.isLegacy).to.be(false);
expect(fetchedAction.config.isLegacy).to.be(true);
});
it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => {

View file

@ -329,6 +329,7 @@ export const getServiceNowConnector = () => ({
},
config: {
apiUrl: 'http://some.non.existent.com',
isLegacy: false,
},
});
@ -385,6 +386,7 @@ export const getServiceNowSIRConnector = () => ({
},
config: {
apiUrl: 'http://some.non.existent.com',
isLegacy: false,
},
});