Skip to content

Commit

Permalink
Return the 'default' space even when spaces are disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rylnd committed Feb 10, 2020
1 parent 11f3581 commit 0e98dae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(`xpack.${APP_ID}.${SIGNALS_INDEX_KEY}`);
const spaceId = getSpaceId();

return spaceId ? `${signalsIndex}-${spaceId}` : signalsIndex;
return `${signalsIndex}-${spaceId}`;
};
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/siem/server/services/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
},
};
};
}
Expand Down

0 comments on commit 0e98dae

Please sign in to comment.