-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/56-uptime-adjust-data-types-for-has-ru…
…m-data-api-call
- Loading branch information
Showing
299 changed files
with
18,482 additions
and
3,259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
packages/kbn-securitysolution-io-ts-utils/src/actions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
24 changes: 24 additions & 0 deletions
24
packages/kbn-securitysolution-io-ts-utils/src/constants/index.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
packages/kbn-securitysolution-io-ts-utils/src/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
packages/kbn-securitysolution-io-ts-utils/src/created_at/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
packages/kbn-securitysolution-io-ts-utils/src/created_by/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
65 changes: 65 additions & 0 deletions
65
packages/kbn-securitysolution-io-ts-utils/src/deafult_version_number/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/kbn-securitysolution-io-ts-utils/src/deafult_version_number/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
19 changes: 19 additions & 0 deletions
19
packages/kbn-securitysolution-io-ts-utils/src/default_actions_array/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
Oops, something went wrong.