From 0e98dae05f341c83aeb059d21cc4a9a62fd9d756 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Mon, 10 Feb 2020 12:32:48 -0600 Subject: [PATCH] Return the 'default' space even when spaces are disabled This will allow users with spaces disabled to enable spaces without losing data. The tradeoff is that they may be surprised when signals don't exist within their configured xpack.siem.signalsIndex. --- .../server/lib/detection_engine/routes/utils.test.ts | 9 +-------- .../siem/server/lib/detection_engine/routes/utils.ts | 9 +++------ x-pack/legacy/plugins/siem/server/services/clients.ts | 6 ++++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.test.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.test.ts index f2f44a378d76b..899419b8fa5e6 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.test.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.test.ts @@ -287,14 +287,7 @@ describe('utils', () => { }); }); - it('returns the configured index if spaces are disabled', () => { - const getSpaceId = jest.fn(() => undefined); - const index = getIndex(getSpaceId, mockConfig); - - expect(index).toEqual('mockSignalsIndex'); - }); - - it('appends the space id to the configured index if spaces are enabled', () => { + it('appends the space id to the configured index', () => { const getSpaceId = jest.fn(() => 'myspace'); const index = getIndex(getSpaceId, mockConfig); diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.ts index bc7e36397d67c..db24256b6afd7 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/utils.ts @@ -157,12 +157,9 @@ export const transformBulkError = ( } }; -export const getIndex = ( - getSpaceId: () => string | undefined, - config: LegacyServices['config'] -): string => { - const spaceId = getSpaceId(); +export const getIndex = (getSpaceId: () => string, config: LegacyServices['config']): string => { const signalsIndex = config().get(`xpack.${APP_ID}.${SIGNALS_INDEX_KEY}`); + const spaceId = getSpaceId(); - return spaceId ? `${signalsIndex}-${spaceId}` : signalsIndex; + return `${signalsIndex}-${spaceId}`; }; diff --git a/x-pack/legacy/plugins/siem/server/services/clients.ts b/x-pack/legacy/plugins/siem/server/services/clients.ts index d76f8e4b68021..cb78f6e5c7838 100644 --- a/x-pack/legacy/plugins/siem/server/services/clients.ts +++ b/x-pack/legacy/plugins/siem/server/services/clients.ts @@ -18,7 +18,7 @@ import { CoreStart, StartPlugins, SetupPlugins } from '../plugin'; export interface Clients { actionsClient?: ActionsClient; clusterClient: IScopedClusterClient; - spacesClient: { getSpaceId: () => string | undefined }; + spacesClient: { getSpaceId: () => string }; savedObjectsClient: SavedObjectsClientContract; } interface LegacyClients { @@ -58,7 +58,9 @@ export class ClientsService { actionsClient: await this.actions?.getActionsClientWithRequest?.(kibanaRequest), clusterClient: this.clusterClient!.asScoped(kibanaRequest), savedObjectsClient: this.savedObjects!.getScopedClient(kibanaRequest), - spacesClient: { getSpaceId: () => this.spacesService?.getSpaceId?.(kibanaRequest) }, + spacesClient: { + getSpaceId: () => this.spacesService?.getSpaceId?.(kibanaRequest) ?? 'default', + }, }; }; }