Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Final Shimming/Prep for Server NP Migration #56814

Merged
merged 43 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
38dbce7
Route all our server setup through the plugin
rylnd Feb 3, 2020
b8a7000
Clean up server plugin exports
rylnd Feb 3, 2020
3d23690
Move DE Routes to to conventional location
rylnd Feb 3, 2020
2e284c5
Loosen up our RequestFacade
rylnd Feb 4, 2020
7a35eac
Remove uses of 'src' alias
rylnd Feb 4, 2020
5360a87
Fix types of our GraphQL requests
rylnd Feb 4, 2020
e41d618
Initialize our routes with SetupServices
rylnd Feb 4, 2020
faf8f77
Swap legacy spaces plugin for NP
rylnd Feb 4, 2020
9418447
Remove unneeded typing
rylnd Feb 4, 2020
80c5826
WIP: Converting our DE routes to use consolidated services
rylnd Feb 4, 2020
b0a7f93
Fix DE routing tests following refactor
rylnd Feb 4, 2020
aa7ae34
Fix incompatible request types
rylnd Feb 4, 2020
b54235d
Move our use of encryptedSavedObjects to NP
rylnd Feb 5, 2020
3742670
Use NP elasticsearch client
rylnd Feb 5, 2020
8ccaf4b
Update DE mocks with NP elasticsearch
rylnd Feb 5, 2020
98d56b8
Remove savedObjects dependency from our legacy dependencies
rylnd Feb 5, 2020
00d089d
WIP: Convert services to stateful object
rylnd Feb 6, 2020
35bfc0b
WIP: Converting routes to use Services factory
rylnd Feb 6, 2020
7e7cd30
WIP: Qualifying our Service to ClientsService
rylnd Feb 6, 2020
c97f190
Fix types on getIndex function
rylnd Feb 6, 2020
101993f
Our ClientsService is a clients ... service
rylnd Feb 7, 2020
f7bb2fb
Clean up our server types
rylnd Feb 7, 2020
2502698
Refactor mocks for new architecture
rylnd Feb 7, 2020
36398bc
Simplify our routing mocks
rylnd Feb 7, 2020
1e6f106
Loosen graphQL endpoint validations
rylnd Feb 7, 2020
bcff5e1
Remove unused graphql endpoint
rylnd Feb 7, 2020
f84a3d7
Reduce our dependence on PluginInitializerContext
rylnd Feb 7, 2020
930b89a
Fix FrameworkAdapter type
rylnd Feb 7, 2020
c3c67f1
Update detections route tests
rylnd Feb 8, 2020
79171ff
Remove unnecessary null checks
rylnd Feb 8, 2020
156dd77
Remove unused type
rylnd Feb 8, 2020
e309001
Remove unused savedObjects client
rylnd Feb 10, 2020
0816e62
Handle case where spaces is disabled
rylnd Feb 10, 2020
dfd81cd
Return default signals index if spaces are disabled
rylnd Feb 10, 2020
11f3581
Remove unnecessary casting of our alerts client mock
rylnd Feb 10, 2020
0e98dae
Return the 'default' space even when spaces are disabled
rylnd Feb 10, 2020
8dc5622
Merge branch 'master' into final_backend_prep
rylnd Feb 12, 2020
4e9f8d8
Merge branch 'master' into final_backend_prep
rylnd Feb 13, 2020
f53e6f7
Account for spaces being disabled in ClientsService
rylnd Feb 13, 2020
cb5d729
Merge branch 'master' into final_backend_prep
rylnd Feb 13, 2020
668702b
Merge branch 'master' into final_backend_prep
rylnd Feb 13, 2020
56fc3f5
Fix false positives in query signals routes tests
rylnd Feb 13, 2020
7162528
style: Prefer null coalescing over ternary
rylnd Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions x-pack/legacy/plugins/siem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
*/

import { i18n } from '@kbn/i18n';
import { get } from 'lodash/fp';
import { resolve } from 'path';
import { Server } from 'hapi';
import { Root } from 'joi';

import { PluginInitializerContext } from '../../../../src/core/server';
import { plugin } from './server';
import { savedObjectMappings } from './server/saved_objects';

Expand All @@ -32,7 +30,6 @@ import {
SIGNALS_INDEX_KEY,
} from './common/constants';
import { defaultIndexPattern } from './default_index_pattern';
import { initServerWithKibana } from './server/kibana.index';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -151,27 +148,20 @@ export const siem = (kibana: any) => {
mappings: savedObjectMappings,
},
init(server: Server) {
const { config, newPlatform, plugins, route } = server;
const { coreContext, env, setup } = newPlatform;
const initializerContext = { ...coreContext, env } as PluginInitializerContext;
const serverFacade = {
config,
usingEphemeralEncryptionKey:
get('usingEphemeralEncryptionKey', newPlatform.setup.plugins.encryptedSavedObjects) ??
false,
plugins: {
alerting: plugins.alerting,
actions: newPlatform.start.plugins.actions,
elasticsearch: plugins.elasticsearch,
spaces: plugins.spaces,
savedObjects: server.savedObjects.SavedObjectsClient,
},
route: route.bind(server),
const { coreContext, env, setup, start } = server.newPlatform;
const initializerContext = { ...coreContext, env };
const __legacy = {
config: server.config,
alerting: server.plugins.alerting,
route: server.route.bind(server),
};
// @ts-ignore-next-line: setup.plugins is too loosely typed
plugin(initializerContext).setup(setup.core, setup.plugins);

initServerWithKibana(initializerContext, serverFacade);
// @ts-ignore-next-line: NewPlatform shim is too loosely typed
const pluginInstance = plugin(initializerContext);
// @ts-ignore-next-line: NewPlatform shim is too loosely typed
pluginInstance.setup(setup.core, setup.plugins, __legacy);
// @ts-ignore-next-line: NewPlatform shim is too loosely typed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch on having to do ts-ignore-next-line. If we have to, we have to. Just some ouch. Any open tickets or other information about when and how these can be removed or is this is just temporary for a shim that will be altogether removed once we are out of the legacy folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specific to the shim; this entire file will be removed on new platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few of these (CoreStart, CoreSetup) are properly typed, but because of the dynamic DI the plugins types are understandably loose. We could make this better, but we'd still have to cast parts of it, and this is all temporary code.

pluginInstance.start(start.core, start.plugins);
},
config(Joi: Root) {
// See x-pack/plugins/siem/server/config.ts if you're adding another
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from 'src/core/server';
import { PluginInitializerContext } from '../../../../../src/core/server';
import { Plugin } from './plugin';

export const plugin = (context: PluginInitializerContext) => {
Expand Down
86 changes: 0 additions & 86 deletions x-pack/legacy/plugins/siem/server/kibana.index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('alerts elasticsearch_adapter', () => {
return mockAlertsHistogramDataResponse;
});
const mockFramework: FrameworkAdapter = {
version: 'mock',
callWithRequest: mockCallWithRequest,
registerGraphQLEndpoint: jest.fn(),
getIndexPatternsService: jest.fn(),
Expand Down
9 changes: 4 additions & 5 deletions x-pack/legacy/plugins/siem/server/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup, PluginInitializerContext } from '../../../../../../../src/core/server';
import { PluginsSetup } from '../../plugin';
import { CoreSetup, SetupPlugins } from '../../plugin';

import { Anomalies } from '../anomalies';
import { ElasticsearchAnomaliesAdapter } from '../anomalies/elasticsearch_adapter';
Expand Down Expand Up @@ -37,10 +36,10 @@ import { Alerts, ElasticsearchAlertsAdapter } from '../alerts';

export function compose(
core: CoreSetup,
plugins: PluginsSetup,
env: PluginInitializerContext['env']
plugins: SetupPlugins,
isProductionMode: boolean
rylnd marked this conversation as resolved.
Show resolved Hide resolved
): AppBackendLibs {
const framework = new KibanaBackendFrameworkAdapter(core, plugins, env);
const framework = new KibanaBackendFrameworkAdapter(core, plugins, isProductionMode);
const sources = new Sources(new ConfigurationSourcesAdapter());
const sourceStatus = new SourceStatus(new ElasticsearchSourceStatusAdapter(framework));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

// See the reference(s) below on explanations about why -000001 was chosen and
// why the is_write_index is true as well as the bootstrapping step which is needed.
// Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/applying-policy-to-template.html
export const createBootstrapIndex = async (
callWithRequest: CallWithRequest<
{ path: string; method: 'PUT'; body: unknown },
CallClusterOptions,
boolean
>,
callWithRequest: CallWithRequest<{ path: string; method: 'PUT'; body: unknown }, boolean>,
index: string
): Promise<unknown> => {
return callWithRequest('transport.request', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IndicesDeleteParams } from 'elasticsearch';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

export const deleteAllIndex = async (
callWithRequest: CallWithRequest<IndicesDeleteParams, CallClusterOptions, boolean>,
callWithRequest: CallWithRequest<IndicesDeleteParams, boolean>,
index: string
): Promise<boolean> => {
return callWithRequest('indices.delete', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CallWithRequest } from '../types';

export const deletePolicy = async (
callWithRequest: CallWithRequest<{ path: string; method: 'DELETE' }, {}, unknown>,
callWithRequest: CallWithRequest<{ path: string; method: 'DELETE' }, unknown>,
policy: string
): Promise<unknown> => {
return callWithRequest('transport.request', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IndicesDeleteTemplateParams } from 'elasticsearch';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

export const deleteTemplate = async (
callWithRequest: CallWithRequest<IndicesDeleteTemplateParams, CallClusterOptions, unknown>,
callWithRequest: CallWithRequest<IndicesDeleteTemplateParams, unknown>,
name: string
): Promise<unknown> => {
return callWithRequest('indices.deleteTemplate', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CallWithRequest } from '../types';
export const getIndexExists = async (
callWithRequest: CallWithRequest<
{ index: string; size: number; terminate_after: number; allow_no_indices: boolean },
{},
{ _shards: { total: number } }
>,
index: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CallWithRequest } from '../types';

export const getPolicyExists = async (
callWithRequest: CallWithRequest<{ path: string; method: 'GET' }, {}, unknown>,
callWithRequest: CallWithRequest<{ path: string; method: 'GET' }, unknown>,
policy: string
): Promise<boolean> => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IndicesExistsTemplateParams } from 'elasticsearch';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

export const getTemplateExists = async (
callWithRequest: CallWithRequest<IndicesExistsTemplateParams, CallClusterOptions, boolean>,
callWithRequest: CallWithRequest<IndicesExistsTemplateParams, boolean>,
template: string
): Promise<boolean> => {
return callWithRequest('indices.existsTemplate', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IndicesGetSettingsParams } from 'elasticsearch';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

export const readIndex = async (
callWithRequest: CallWithRequest<IndicesGetSettingsParams, CallClusterOptions, unknown>,
callWithRequest: CallWithRequest<IndicesGetSettingsParams, unknown>,
index: string
): Promise<unknown> => {
return callWithRequest('indices.get', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CallWithRequest } from '../types';

export const setPolicy = async (
callWithRequest: CallWithRequest<{ path: string; method: 'PUT'; body: unknown }, {}, unknown>,
callWithRequest: CallWithRequest<{ path: string; method: 'PUT'; body: unknown }, unknown>,
policy: string,
body: unknown
): Promise<unknown> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IndicesPutTemplateParams } from 'elasticsearch';
import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch';
import { CallWithRequest } from '../types';

export const setTemplate = async (
callWithRequest: CallWithRequest<IndicesPutTemplateParams, CallClusterOptions, unknown>,
callWithRequest: CallWithRequest<IndicesPutTemplateParams, unknown>,
name: string,
body: unknown
): Promise<unknown> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CallWithRequest } from '../types';

export const readPrivileges = async (
callWithRequest: CallWithRequest<unknown, unknown, unknown>,
callWithRequest: CallWithRequest<{}, unknown>,
index: string
): Promise<unknown> => {
return callWithRequest('transport.request', {
Expand Down
Loading