Skip to content

Commit ff5971a

Browse files
authored
[SIEM] Server NP Followup (#64010)
* Remove unused file This was moved to a constant in common/constants. * Remove unused types Omit is now part of Typescript, and Pick3 is unused. * Define and export SIEM's plugin contracts They're empty for now. * Import config type from config file Instead of our plugin index, which could only cause circular dependencies. * SiemClient API uses getter function instead of direct property access * Add public mock for SiemClient * Fix typo in extract-mitre-attacks script We were backgrounding the process (&) instead of ANDing it with the linting. Whoops! * Remove missed instance of old siemClient API I missed this one when grepping, but typescript and CI saved me. * Use our client mock in our test suite This was causing some test failures as I forgot to update the client mock * Update script following updates to the output's usage This was changed in #55883 but the script was not updated accordingly.
1 parent 5a55c9a commit ff5971a

29 files changed

+61
-51
lines changed

x-pack/plugins/siem/common/default_index_pattern.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

x-pack/plugins/siem/common/utility_types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
import { ReactNode } from 'react';
88

9-
export type Pick3<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]> = {
10-
[P1 in K1]: { [P2 in K2]: { [P3 in K3]: T[K1][K2][P3] } };
11-
};
12-
13-
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
14-
159
// This type is for typing EuiDescriptionList
1610
export interface DescriptionList {
1711
title: NonNullable<ReactNode>;

x-pack/plugins/siem/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"license": "Elastic-License",
77
"scripts": {
8-
"extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js & node ../../../scripts/eslint ../../legacy/plugins/siem/public/pages/detection_engine/mitre/mitre_tactics_techniques.ts --fix",
8+
"extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js && node ../../../scripts/eslint ../../legacy/plugins/siem/public/pages/detection_engine/mitre/mitre_tactics_techniques.ts --fix",
99
"build-graphql-types": "node scripts/generate_types_from_graphql.js",
1010
"cypress:open": "cypress open --config-file ./cypress/cypress.json",
1111
"cypress:run": "cypress run --spec ./cypress/integration/**/*.spec.ts --config-file ./cypress/cypress.json --reporter ../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json; status=$?; ../../node_modules/.bin/mochawesome-merge --reportDir ../../../target/kibana-siem/cypress/results > ../../../target/kibana-siem/cypress/results/output.json; ../../../node_modules/.bin/marge ../../../target/kibana-siem/cypress/results/output.json --reportDir ../../../target/kibana-siem/cypress/results; mkdir -p ../../../target/junit && cp ../../../target/kibana-siem/cypress/results/*.xml ../../../target/junit/ && exit $status;",

x-pack/plugins/siem/scripts/extract_tactics_techniques_mitre.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async function main() {
123123
.replace(/}"/g, '}')
124124
.replace(/"{/g, '{')};
125125
126-
export const techniques = ${JSON.stringify(techniques, null, 2)};
126+
export const technique = ${JSON.stringify(techniques, null, 2)};
127127
128128
export const techniquesOptions: MitreTechniquesOptions[] =
129129
${JSON.stringify(getTechniquesOptions(techniques), null, 2)

x-pack/plugins/siem/server/client/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createMockConfig } from '../lib/detection_engine/routes/__mocks__';
99
import { SiemClient } from './client';
1010

1111
describe('SiemClient', () => {
12-
describe('#signalsIndex', () => {
12+
describe('#getSignalsIndex', () => {
1313
it('returns the index scoped to the specified spaceId', () => {
1414
const mockConfig = {
1515
...createMockConfig(),
@@ -18,7 +18,7 @@ describe('SiemClient', () => {
1818
const spaceId = 'fooSpace';
1919
const client = new SiemClient(spaceId, mockConfig);
2020

21-
expect(client.signalsIndex).toEqual('mockSignalsIndex-fooSpace');
21+
expect(client.getSignalsIndex()).toEqual('mockSignalsIndex-fooSpace');
2222
});
2323
});
2424
});

x-pack/plugins/siem/server/client/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { ConfigType } from '..';
7+
import { ConfigType } from '../config';
88

99
export class SiemClient {
10-
public readonly signalsIndex: string;
10+
private readonly signalsIndex: string;
1111

1212
constructor(private spaceId: string, private config: ConfigType) {
1313
const configuredSignalsIndex = this.config.signalsIndex;
1414

1515
this.signalsIndex = `${configuredSignalsIndex}-${this.spaceId}`;
1616
}
17+
18+
public getSignalsIndex = (): string => this.signalsIndex;
1719
}

x-pack/plugins/siem/server/client/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { KibanaRequest } from '../../../../../src/core/server';
88
import { SiemClient } from './client';
9-
import { ConfigType } from '..';
9+
import { ConfigType } from '../config';
1010

1111
interface SetupDependencies {
1212
getSpaceId?: (request: KibanaRequest) => string | undefined;

x-pack/plugins/siem/server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { PluginInitializerContext } from '../../../../src/core/server';
8-
import { Plugin } from './plugin';
8+
import { Plugin, PluginSetup, PluginStart } from './plugin';
99
import { configSchema, ConfigType } from './config';
1010

1111
export const plugin = (context: PluginInitializerContext) => {
@@ -14,4 +14,4 @@ export const plugin = (context: PluginInitializerContext) => {
1414

1515
export const config = { schema: configSchema };
1616

17-
export { ConfigType };
17+
export { ConfigType, Plugin, PluginSetup, PluginStart };

x-pack/plugins/siem/server/lib/detection_engine/routes/__mocks__/request_context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import {
1313
import { alertsClientMock } from '../../../../../../alerting/server/mocks';
1414
import { actionsClientMock } from '../../../../../../actions/server/mocks';
1515
import { licensingMock } from '../../../../../../licensing/server/mocks';
16+
import { siemMock } from '../../../../mocks';
1617

1718
const createMockClients = () => ({
1819
actionsClient: actionsClientMock.create(),
1920
alertsClient: alertsClientMock.create(),
2021
clusterClient: elasticsearchServiceMock.createScopedClusterClient(),
2122
licensing: { license: licensingMock.createLicenseMock() },
2223
savedObjectsClient: savedObjectsClientMock.create(),
23-
siemClient: { signalsIndex: 'mockSignalsIndex' },
24+
siemClient: siemMock.createClient(),
2425
});
2526

2627
const createRequestContextMock = (

x-pack/plugins/siem/server/lib/detection_engine/routes/index/create_index_route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const createIndexRoute = (router: IRouter) => {
3737
return siemResponse.error({ statusCode: 404 });
3838
}
3939

40-
const index = siemClient.signalsIndex;
40+
const index = siemClient.getSignalsIndex();
4141
const indexExists = await getIndexExists(callCluster, index);
4242
if (indexExists) {
4343
return siemResponse.error({

0 commit comments

Comments
 (0)