Skip to content

Commit

Permalink
Merge branch 'master' into fix/56-uptime-adjust-data-types-for-has-ru…
Browse files Browse the repository at this point in the history
…m-data-api-call
  • Loading branch information
kibanamachine authored May 4, 2021
2 parents fe8d8d5 + f2693ed commit 5b58e20
Show file tree
Hide file tree
Showing 299 changed files with 18,482 additions and 3,259 deletions.
2 changes: 1 addition & 1 deletion .ci/es-snapshots/Jenkinsfile_verify_es
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ kibanaPipeline(timeoutMinutes: 210) {
}

task {
kibanaPipeline.buildXpack(10)
kibanaPipeline.buildXpack(10, true)
tasks.xpackCiGroups()
tasks.xpackCiGroupDocker()
}
Expand Down
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 @@ -76,6 +76,7 @@ yarn kbn watch-bazel
- @kbn/expect
- @kbn/legacy-logging
- @kbn/logging
- @kbn/securitysolution-io-ts-utils
- @kbn/std
- @kbn/tinymath
- @kbn/utility-types
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"@kbn/legacy-logging": "link:bazel-bin/packages/kbn-legacy-logging/npm_module",
"@kbn/logging": "link:bazel-bin/packages/kbn-logging/npm_module",
"@kbn/monaco": "link:packages/kbn-monaco",
"@kbn/securitysolution-io-ts-utils": "link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module",
"@kbn/server-http-tools": "link:packages/kbn-server-http-tools",
"@kbn/server-route-repository": "link:packages/kbn-server-route-repository",
"@kbn/std": "link:bazel-bin/packages/kbn-std/npm_module",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ filegroup(
"//packages/kbn-expect:build",
"//packages/kbn-legacy-logging:build",
"//packages/kbn-logging:build",
"//packages/kbn-securitysolution-io-ts-utils:build",
"//packages/kbn-std:build",
"//packages/kbn-tinymath:build",
"//packages/kbn-utility-types:build",
Expand Down
92 changes: 92 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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-utils"
PKG_REQUIRE_NAME = "@kbn/securitysolution-io-ts-utils"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
"**/*.mock.*"
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md",
]

SRC_DEPS = [
"//packages/elastic-datemath",
"@npm//fp-ts",
"@npm//io-ts",
"@npm//lodash",
"@npm//moment",
"@npm//tslib",
"@npm//uuid",
]

TYPES_DEPS = [
"@npm//@types/flot",
"@npm//@types/jest",
"@npm//@types/lodash",
"@npm//@types/node",
"@npm//@types/uuid"
]

DEPS = SRC_DEPS + TYPES_DEPS

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = [":tsc"] + DEPS,
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
10 changes: 10 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# kbn-securitysolution-io-ts-utils

Temporary location for all the io-ts-utils from security solutions. This is a lift-and-shift, where
we are moving them here for phase 1.

Phase 2 is deprecating across plugins any copied code or sharing of io-ts utils that are now in here.

Phase 3 is replacing those deprecated types with the ones in here.

Phase 4+ is (potentially) consolidating any duplication or everything altogether with the `kbn-io-ts-utils` project
13 changes: 13 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/jest.config.js
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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-securitysolution-io-ts-utils'],
};
9 changes: 9 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/securitysolution-io-ts-utils",
"version": "1.0.0",
"description": "io ts utilities and types to be shared with plugins from the security solution project",
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"private": true
}
45 changes: 45 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/src/actions/index.ts
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.
*/

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

import * as t from 'io-ts';
import { saved_object_attributes } from '../saved_object_attributes';

/**
* Params is an "object", since it is a type of AlertActionParams which is action templates.
* @see x-pack/plugins/alerting/common/alert.ts
*/
export const action_group = t.string;
export const action_id = t.string;
export const action_action_type_id = t.string;
export const action_params = saved_object_attributes;

export const action = t.exact(
t.type({
group: action_group,
id: action_id,
action_type_id: action_action_type_id,
params: action_params,
})
);

export const actions = t.array(action);
export type Actions = t.TypeOf<typeof actions>;

export const actionsCamel = t.array(
t.exact(
t.type({
group: action_group,
id: action_id,
actionTypeId: action_action_type_id,
params: action_params,
})
)
);
export type ActionsCamel = t.TypeOf<typeof actions>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 const ENTRY_VALUE = 'some host name';
export const FIELD = 'host.name';
export const MATCH = 'match';
export const MATCH_ANY = 'match_any';
export const OPERATOR = 'included';
export const NESTED = 'nested';
export const NESTED_FIELD = 'parent.field';
export const LIST_ID = 'some-list-id';
export const LIST = 'list';
export const TYPE = 'ip';
export const EXISTS = 'exists';
export const WILDCARD = 'wildcard';
export const USER = 'some user';
export const DATE_NOW = '2020-04-20T15:25:31.830Z';

// Exception List specific
export const ID = 'uuid_here';
21 changes: 21 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

/**
* This ID is used for _both_ the Saved Object ID and for the list_id
* for the single global space agnostic endpoint list
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_LIST_ID = 'endpoint_list';

/**
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the DEFAULT_MAX_SIGNALS from the kbn-securitysolution-constants.
*/
export const DEFAULT_MAX_SIGNALS = 100;
13 changes: 13 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/src/created_at/index.ts
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.
*/

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

import * as t from 'io-ts';

export const created_at = t.string; // TODO: Make this into an ISO Date string check
13 changes: 13 additions & 0 deletions packages/kbn-securitysolution-io-ts-utils/src/created_by/index.ts
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.
*/

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

import * as t from 'io-ts';

export const created_by = t.string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import { DefaultVersionNumber } from '../default_version_number';
import { foldLeftRight, getPaths } from '../test_utils';

describe('default_version_number', () => {
test('it should validate a version number', () => {
const payload = 5;
const decoded = DefaultVersionNumber.decode(payload);
const message = pipe(decoded, foldLeftRight);

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

test('it should not validate a 0', () => {
const payload = 0;
const decoded = DefaultVersionNumber.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "0" supplied to "DefaultVersionNumber"',
]);
expect(message.schema).toEqual({});
});

test('it should not validate a -1', () => {
const payload = -1;
const decoded = DefaultVersionNumber.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "-1" supplied to "DefaultVersionNumber"',
]);
expect(message.schema).toEqual({});
});

test('it should not validate a string', () => {
const payload = '5';
const decoded = DefaultVersionNumber.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "5" supplied to "DefaultVersionNumber"',
]);
expect(message.schema).toEqual({});
});

test('it should return a default of 1', () => {
const payload = null;
const decoded = DefaultVersionNumber.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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';
import { Either } from 'fp-ts/lib/Either';
import { version, Version } from '../version';

/**
* Types the DefaultVersionNumber as:
* - If null or undefined, then a default of the number 1 will be used
*/
export const DefaultVersionNumber = new t.Type<Version, Version | undefined, unknown>(
'DefaultVersionNumber',
version.is,
(input, context): Either<t.Errors, Version> =>
input == null ? t.success(1) : version.validate(input, context),
t.identity
);

export type DefaultVersionNumberDecoded = t.TypeOf<typeof DefaultVersionNumber>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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';
import { Either } from 'fp-ts/lib/Either';
import { actions, Actions } from '../actions';

export const DefaultActionsArray = new t.Type<Actions, Actions | undefined, unknown>(
'DefaultActionsArray',
actions.is,
(input, context): Either<t.Errors, Actions> =>
input == null ? t.success([]) : actions.validate(input, context),
t.identity
);
Loading

0 comments on commit 5b58e20

Please sign in to comment.