Skip to content

Commit

Permalink
[Security Solutions] Re-arranges and adds more packages to remove cop…
Browse files Browse the repository at this point in the history
…ied code (#100310) (#100369)

## Summary

* Creates a `securitysolution-list-utils` packaged and moves the first set of utilities into there
* Fixes a slight bug with `kbn-securitysolution-io-ts-list-types` where the wrong name was used
* Moves _all_ of the lists schemas and types into the package `kbn-securitysolution-io-ts-list-types`
* Removes copied code found in a few places

## Tech debt
* Some spots I have to use an `any` in the package as Kibana kbn packages don't have the types I need
* Some spots I copy constants until we can straighten out those pieces.
* I keep copied mock files until we figure out how to share mocks from these packages without adding weight or we create dedicated mock packages for all of this. 


### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios

Co-authored-by: Frank Hassanabad <[email protected]>
  • Loading branch information
kibanamachine and FrankHassanabad authored May 19, 2021
1 parent 05fc567 commit 7d0deec
Show file tree
Hide file tree
Showing 531 changed files with 3,374 additions and 2,300 deletions.
15 changes: 4 additions & 11 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"interpreter": "src/legacy/core_plugins/interpreter",
"kbn": "src/legacy/core_plugins/kibana",
"kbnDocViews": "src/legacy/core_plugins/kbn_doc_views",
"management": [
"src/legacy/core_plugins/management",
"src/plugins/management"
],
"lists": "packages/kbn-securitysolution-list-utils/src",
"management": ["src/legacy/core_plugins/management", "src/plugins/management"],
"maps_legacy": "src/plugins/maps_legacy",
"monaco": "packages/kbn-monaco/src",
"presentationUtil": "src/plugins/presentation_util",
Expand All @@ -45,10 +43,7 @@
"security": "src/plugins/security_oss",
"server": "src/legacy/server",
"statusPage": "src/legacy/core_plugins/status_page",
"telemetry": [
"src/plugins/telemetry",
"src/plugins/telemetry_management_section"
],
"telemetry": ["src/plugins/telemetry", "src/plugins/telemetry_management_section"],
"tileMap": "src/plugins/tile_map",
"timelion": ["src/plugins/timelion", "src/plugins/vis_type_timelion"],
"uiActions": "src/plugins/ui_actions",
Expand All @@ -66,8 +61,6 @@
"apmOss": "src/plugins/apm_oss",
"usageCollection": "src/plugins/usage_collection"
},
"exclude": [
"src/legacy/ui/ui_render/ui_render_mixin.js"
],
"exclude": ["src/legacy/ui/ui_render/ui_render_mixin.js"],
"translations": []
}
1 change: 1 addition & 0 deletions docs/developer/getting-started/monorepo-packages.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ yarn kbn watch-bazel
- kbn/securitysolution-io-ts-list-types
- kbn/securitysolution-io-ts-types
- @kbn/securitysolution-io-ts-utils
- @kbn/securitysolution-list-utils
- @kbn/securitysolution-utils
- @kbn/server-http-tools
- @kbn/std
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"@kbn/securitysolution-io-ts-alerting-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-alerting-types/npm_module",
"@kbn/securitysolution-io-ts-list-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-list-types/npm_module",
"@kbn/securitysolution-io-ts-utils": "link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module",
"@kbn/securitysolution-list-utils": "link:bazel-bin/packages/kbn-securitysolution-list-utils/npm_module",
"@kbn/securitysolution-utils": "link:bazel-bin/packages/kbn-securitysolution-utils/npm_module",
"@kbn/server-http-tools": "link:bazel-bin/packages/kbn-server-http-tools/npm_module",
"@kbn/server-route-repository": "link:packages/kbn-server-route-repository",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ filegroup(
"//packages/kbn-logging:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-securitysolution-constants:build",
"//packages/kbn-securitysolution-list-utils:build",
"//packages/kbn-securitysolution-io-ts-types:build",
"//packages/kbn-securitysolution-io-ts-alerting-types:build",
"//packages/kbn-securitysolution-io-ts-list-types:build",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-securitysolution-io-ts-list-types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-securitysolution-io-ts-list-types"
PKG_REQUIRE_NAME = "@kbn/securitysolution-io-list-types"
PKG_REQUIRE_NAME = "@kbn/securitysolution-io-ts-list-types"

SOURCE_FILES = glob(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Comment, CommentsArray } from '.';
import { DATE_NOW, ID, USER } from '../constants/index.mock';
import { DATE_NOW, ID, USER } from '../../constants/index.mock';

export const getCommentsMock = (): Comment => ({
comment: 'some old comment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
commentsArrayOrUndefined,
} from '.';
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { DATE_NOW } from '../constants/index.mock';
import { DATE_NOW } from '../../constants/index.mock';

describe('Comment', () => {
describe('comment', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import * as t from 'io-ts';

export const cursor = t.string;
export type Cursor = t.TypeOf<typeof cursor>;
export const cursorOrUndefined = t.union([cursor, t.undefined]);
export type CursorOrUndefined = t.TypeOf<typeof cursorOrUndefined>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';

export const deserializer = t.string;
export type Deserializer = t.TypeOf<typeof deserializer>;
export const deserializerOrUndefined = t.union([deserializer, t.undefined]);
export type DeserializerOrUndefined = t.TypeOf<typeof deserializerOrUndefined>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EndpointEntryMatch } from '.';
import { ENTRY_VALUE, FIELD, MATCH, OPERATOR } from '../../constants/index.mock';
import { ENTRY_VALUE, FIELD, MATCH, OPERATOR } from '../../../constants/index.mock';

export const getEndpointEntryMatchMock = (): EndpointEntryMatch => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ENTRY_VALUE, FIELD, MATCH_ANY, OPERATOR } from '../../constants/index.mock';
import { ENTRY_VALUE, FIELD, MATCH_ANY, OPERATOR } from '../../../constants/index.mock';
import { EndpointEntryMatchAny } from '.';

export const getEndpointEntryMatchAnyMock = (): EndpointEntryMatchAny => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EndpointEntryNested } from '.';
import { FIELD, NESTED } from '../../constants/index.mock';
import { FIELD, NESTED } from '../../../constants/index.mock';
import { getEndpointEntryMatchMock } from '../entry_match/index.mock';
import { getEndpointEntryMatchAnyMock } from '../entry_match_any/index.mock';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
* Side Public License, v 1.
*/
export * from './entries';
export * from './entry_match';
export * from './entry_match_any';
export * from './entry_match_wildcard';
export * from './entry_nested';
export * from './non_empty_nested_entries_array';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryExists } from '.';
import { EXISTS, FIELD, OPERATOR } from '../constants/index.mock';
import { EXISTS, FIELD, OPERATOR } from '../../constants/index.mock';

export const getEntryExistsMock = (): EntryExists => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryList } from '.';
import { FIELD, LIST, LIST_ID, OPERATOR, TYPE } from '../constants/index.mock';
import { FIELD, LIST, LIST_ID, OPERATOR, TYPE } from '../../constants/index.mock';

export const getEntryListMock = (): EntryList => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryMatch } from '.';
import { ENTRY_VALUE, FIELD, MATCH, OPERATOR } from '../constants/index.mock';
import { ENTRY_VALUE, FIELD, MATCH, OPERATOR } from '../../constants/index.mock';

export const getEntryMatchMock = (): EntryMatch => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryMatchAny } from '.';
import { ENTRY_VALUE, FIELD, MATCH_ANY, OPERATOR } from '../constants/index.mock';
import { ENTRY_VALUE, FIELD, MATCH_ANY, OPERATOR } from '../../constants/index.mock';

export const getEntryMatchAnyMock = (): EntryMatchAny => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryMatchWildcard } from '.';
import { ENTRY_VALUE, FIELD, OPERATOR, WILDCARD } from '../constants/index.mock';
import { ENTRY_VALUE, FIELD, OPERATOR, WILDCARD } from '../../constants/index.mock';

export const getEntryMatchWildcardMock = (): EntryMatchWildcard => ({
field: FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { EntryNested } from '.';
import { NESTED, NESTED_FIELD } from '../constants/index.mock';
import { NESTED, NESTED_FIELD } from '../../constants/index.mock';
import { getEntryExistsMock } from '../entries_exist/index.mock';
import { getEntryMatchExcludeMock, getEntryMatchMock } from '../entry_match/index.mock';
import { getEntryMatchAnyExcludeMock, getEntryMatchAnyMock } from '../entry_match_any/index.mock';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { exceptionListType, ExceptionListTypeEnum } from '.';

import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';

describe('exceptionListType', () => {
test('it should validate for "detection"', () => {
const payload = 'detection';
const decoded = exceptionListType.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('it should validate for "endpoint"', () => {
const payload = 'endpoint';
const decoded = exceptionListType.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('it should contain same amount of keys as enum', () => {
// Might seem like a weird test, but its meant to
// ensure that if exceptionListType is updated, you
// also update the ExceptionListTypeEnum, a workaround
// for io-ts not yet supporting enums
// https://github.com/gcanti/io-ts/issues/67
const keys = Object.keys(exceptionListType.keys).sort().join(',').toLowerCase();
const enumKeys = Object.keys(ExceptionListTypeEnum).sort().join(',').toLowerCase();

expect(keys).toEqual(enumKeys);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import * as t from 'io-ts';

export const file = t.object;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';

export const filter = t.string;
export type Filter = t.TypeOf<typeof filter>;
export const filterOrUndefined = t.union([filter, t.undefined]);
export type FilterOrUndefined = t.TypeOf<typeof filterOrUndefined>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';

export const immutable = t.boolean;
export type Immutable = t.TypeOf<typeof immutable>;
export const immutableOrUndefined = t.union([immutable, t.undefined]);
export type ImmutableOrUndefined = t.TypeOf<typeof immutableOrUndefined>;
62 changes: 62 additions & 0 deletions packages/kbn-securitysolution-io-ts-list-types/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './comment';
export * from './create_comment';
export * from './created_at';
export * from './created_by';
export * from './cursor';
export * from './default_namespace';
export * from './default_namespace_array';
export * from './description';
export * from './deserializer';
export * from './endpoint';
export * from './entries';
export * from './entries_exist';
export * from './entries_list';
export * from './entry_match';
export * from './entry_match_any';
export * from './entry_match_wildcard';
export * from './entry_nested';
export * from './exception_list';
export * from './exception_list_item_type';
export * from './filter';
export * from './id';
export * from './immutable';
export * from './item_id';
export * from './list_id';
export * from './list_operator';
export * from './list_type';
export * from './lists';
export * from './lists_default_array';
export * from './meta';
export * from './name';
export * from './non_empty_entries_array';
export * from './non_empty_nested_entries_array';
export * from './os_type';
export * from './page';
export * from './per_page';
export * from './serializer';
export * from './sort_field';
export * from './sort_order';
export * from './tags';
export * from './tie_breaker_id';
export * from './total';
export * from './type';
export * from './underscore_version';
export * from './update_comment';
export * from './updated_at';
export * from './updated_by';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';

export const item = t.string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

/* eslint-disable @typescript-eslint/naming-convention */

import * as t from 'io-ts';
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types';

export const list_id = NonEmptyString;
export type ListId = t.TypeOf<typeof list_id>;
export const list_idOrUndefined = t.union([list_id, t.undefined]);
export type ListIdOrUndefined = t.TypeOf<typeof list_idOrUndefined>;
Loading

0 comments on commit 7d0deec

Please sign in to comment.