Skip to content

Commit

Permalink
Merge branch 'master' into dashboard-share-capable
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 25, 2021
2 parents 2164bf6 + 504896d commit 1998c83
Show file tree
Hide file tree
Showing 58 changed files with 645 additions and 304 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.21",
"@elastic/ems-client": "7.16.0",
"@elastic/eui": "39.1.1",
"@elastic/eui": "40.0.0",
"@elastic/filesaver": "1.1.2",
"@elastic/maki": "6.3.0",
"@elastic/node-crypto": "1.2.1",
Expand Down

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/core/public/chrome/ui/header/collapsible_nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ function expectNavIsClosed(component: ReactWrapper) {
}

function clickGroup(component: ReactWrapper, group: string) {
component.find(`[data-test-subj="collapsibleNavGroup-${group}"] button`).simulate('click');
component
.find(`[data-test-subj="collapsibleNavGroup-${group}"] button`)
.first()
.simulate('click');
}

describe('CollapsibleNav', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/dev/license_checker/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export const LICENSE_OVERRIDES = {
'[email protected]': ['Eclipse Distribution License - v 1.0'], // cf. https://github.com/bjornharrtell/jsts
'@mapbox/[email protected]': ['MIT'], // license in readme https://github.com/tmcw/jsonlint
'@elastic/[email protected]': ['Elastic License 2.0'],
'@elastic/eui@39.1.1': ['SSPL-1.0 OR Elastic License 2.0'],
'@elastic/eui@40.0.0': ['SSPL-1.0 OR Elastic License 2.0'],
'[email protected]': ['CC-BY-4.0'], // retired ODC‑By license https://github.com/mattcg/language-subtag-registry
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Loading

0 comments on commit 1998c83

Please sign in to comment.