Skip to content

Commit

Permalink
Merge branch 'main' into fleet/2022-09-23-fix-policy-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Sep 23, 2022
2 parents adfad25 + e50db36 commit 58da656
Show file tree
Hide file tree
Showing 52 changed files with 517 additions and 199 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ packages/kbn-mapbox-gl @elastic/kibana-gis
packages/kbn-monaco @elastic/kibana-app-services
packages/kbn-optimizer @elastic/kibana-operations
packages/kbn-optimizer-webpack-helpers @elastic/kibana-operations
packages/kbn-osquery-io-ts-types @elastic/security-asset-management
packages/kbn-performance-testing-dataset-extractor @elastic/kibana-performance-testing
packages/kbn-plugin-discovery @elastic/kibana-operations
packages/kbn-plugin-generator @elastic/kibana-operations
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
"@kbn/ml-is-populated-object": "link:bazel-bin/x-pack/packages/ml/is_populated_object",
"@kbn/ml-string-hash": "link:bazel-bin/x-pack/packages/ml/string_hash",
"@kbn/monaco": "link:bazel-bin/packages/kbn-monaco",
"@kbn/osquery-io-ts-types": "link:bazel-bin/packages/kbn-osquery-io-ts-types",
"@kbn/plugin-discovery": "link:bazel-bin/packages/kbn-plugin-discovery",
"@kbn/react-field": "link:bazel-bin/packages/kbn-react-field",
"@kbn/rule-data-utils": "link:bazel-bin/packages/kbn-rule-data-utils",
Expand Down Expand Up @@ -1068,6 +1069,7 @@
"@types/kbn__monaco": "link:bazel-bin/packages/kbn-monaco/npm_module_types",
"@types/kbn__optimizer": "link:bazel-bin/packages/kbn-optimizer/npm_module_types",
"@types/kbn__optimizer-webpack-helpers": "link:bazel-bin/packages/kbn-optimizer-webpack-helpers/npm_module_types",
"@types/kbn__osquery-io-ts-types": "link:bazel-bin/packages/kbn-osquery-io-ts-types/npm_module_types",
"@types/kbn__performance-testing-dataset-extractor": "link:bazel-bin/packages/kbn-performance-testing-dataset-extractor/npm_module_types",
"@types/kbn__plugin-discovery": "link:bazel-bin/packages/kbn-plugin-discovery/npm_module_types",
"@types/kbn__plugin-generator": "link:bazel-bin/packages/kbn-plugin-generator/npm_module_types",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ filegroup(
"//packages/kbn-monaco:build",
"//packages/kbn-optimizer:build",
"//packages/kbn-optimizer-webpack-helpers:build",
"//packages/kbn-osquery-io-ts-types:build",
"//packages/kbn-performance-testing-dataset-extractor:build",
"//packages/kbn-plugin-discovery:build",
"//packages/kbn-plugin-generator:build",
Expand Down Expand Up @@ -555,6 +556,7 @@ filegroup(
"//packages/kbn-monaco:build_types",
"//packages/kbn-optimizer:build_types",
"//packages/kbn-optimizer-webpack-helpers:build_types",
"//packages/kbn-osquery-io-ts-types:build_types",
"//packages/kbn-performance-testing-dataset-extractor:build_types",
"//packages/kbn-plugin-discovery:build_types",
"//packages/kbn-plugin-generator:build_types",
Expand Down
127 changes: 127 additions & 0 deletions packages/kbn-osquery-io-ts-types/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "kbn-osquery-io-ts-types"
PKG_REQUIRE_NAME = "@kbn/osquery-io-ts-types"

SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
"@npm//io-ts",
]

# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//tslib",
"@npm//io-ts",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

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

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions packages/kbn-osquery-io-ts-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# kbn-osquery-io-ts-types

Types that are specific to the osquery plugin to be shared among plugins.
9 changes: 9 additions & 0 deletions packages/kbn-osquery-io-ts-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 './src/live_query';
13 changes: 13 additions & 0 deletions packages/kbn-osquery-io-ts-types/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/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-osquery-io-ts-types'],
};
7 changes: 7 additions & 0 deletions packages/kbn-osquery-io-ts-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/osquery-io-ts-types",
"owner": "@elastic/security-asset-management",
"runtimeDeps": [],
"typeDeps": [],
}
9 changes: 9 additions & 0 deletions packages/kbn-osquery-io-ts-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/osquery-io-ts-types",
"private": true,
"version": "1.0.0",
"description": "io ts utilities and types to be shared with plugins from the osquery project",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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';
Expand Down Expand Up @@ -95,9 +96,9 @@ export const arrayQueries = t.array(
t.type({
id,
query,
ecs_mapping: ecsMapping,
version,
platform,
ecs_mapping: ecsMappingOrUndefined,
version: versionOrUndefined,
platform: platformOrUndefined,
})
);
export type ArrayQueries = t.TypeOf<typeof arrayQueries>;
Expand Down
16 changes: 16 additions & 0 deletions packages/kbn-osquery-io-ts-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}
1 change: 0 additions & 1 deletion x-pack/plugins/osquery/common/schemas/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
* 2.0.
*/

export * from './schemas';
export * from './utils';
4 changes: 1 addition & 3 deletions x-pack/plugins/osquery/common/schemas/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import { isEmpty, reduce } from 'lodash';
import type { DefaultValues } from 'react-hook-form';
import type { ECSMapping } from './schemas';

export type { ECSMapping };
import type { ECSMapping } from '@kbn/osquery-io-ts-types';

export type ECSMappingArray = Array<{
key: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
packIdOrUndefined,
queryOrUndefined,
queriesOrUndefined,
} from '../../common/schemas';
} from '@kbn/osquery-io-ts-types';

export const createLiveQueryRequestBodySchema = t.partial({
agent_ids: t.array(t.string),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as t from 'io-ts';

import type { Description } from '../../common/schemas';
import type { Description } from '@kbn/osquery-io-ts-types';
import {
id,
descriptionOrUndefined,
Expand All @@ -18,7 +18,7 @@ import {
snapshotOrUndefined,
removedOrUndefined,
ecsMappingOrUndefined,
} from '../../common/schemas';
} from '@kbn/osquery-io-ts-types';
import type { RequiredKeepUndefined } from '../../../types';

export const createSavedQueryRequestSchema = t.type({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useQuery } from '@tanstack/react-query';

import { i18n } from '@kbn/i18n';
import { filter } from 'lodash';
import type { ECSMapping } from '../../common/schemas/common';
import type { ECSMapping } from '@kbn/osquery-io-ts-types';
import { useKibana } from '../common/lib/kibana';
import type { ESTermQuery } from '../../common/typed_json';
import { useErrorToast } from '../common/hooks/use_error_toast';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/public/live_queries/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import type { ECSMapping } from '@kbn/osquery-io-ts-types';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useForm as useHookForm, FormProvider } from 'react-hook-form';
import { isEmpty, find, pickBy } from 'lodash';

import type { AddToTimelinePayload } from '../../timelines/get_add_to_timeline';
import { QueryPackSelectable } from './query_pack_selectable';
import type { SavedQuerySOFormData } from '../../saved_queries/form/use_saved_query_form';
import type { ECSMapping } from '../../../common/schemas/common/utils';
import { useKibana } from '../../common/lib/kibana';
import { ResultTabs } from '../../routes/saved_queries/edit/tabs';
import { SavedQueryFlyout } from '../../saved_queries';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ const LiveQueryQueryFieldComponent: React.FC<LiveQueryQueryFieldProps> = ({
[permissions.writeLiveQueries]
);

const isAdvancedToggleHidden = useMemo(
() =>
!(
permissions.writeLiveQueries ||
permissions.runSavedQueries ||
permissions.readSavedQueries
),
[permissions.readSavedQueries, permissions.runSavedQueries, permissions.writeLiveQueries]
);
const isSavedQueryDisabled = useMemo(
() => !permissions.runSavedQueries || !permissions.readSavedQueries,
[permissions.readSavedQueries, permissions.runSavedQueries]
Expand Down Expand Up @@ -143,15 +152,17 @@ const LiveQueryQueryFieldComponent: React.FC<LiveQueryQueryFieldProps> = ({

<EuiSpacer size="m" />

<StyledEuiAccordion
id="advanced"
forceState={advancedContentState}
onToggle={handleToggle}
buttonContent="Advanced"
>
<EuiSpacer size="xs" />
<ECSMappingEditorField euiFieldProps={ecsFieldProps} />
</StyledEuiAccordion>
{!isAdvancedToggleHidden && (
<StyledEuiAccordion
id="advanced"
forceState={advancedContentState}
onToggle={handleToggle}
buttonContent="Advanced"
>
<EuiSpacer size="xs" />
<ECSMappingEditorField euiFieldProps={ecsFieldProps} />
</StyledEuiAccordion>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type {
import { DOCUMENT_FIELD_NAME as RECORDS_FIELD } from '@kbn/lens-plugin/common/constants';
import { FilterStateStore } from '@kbn/es-query';
import styled from 'styled-components';
import type { ECSMapping } from '../../../common/schemas/common';
import type { ECSMapping } from '@kbn/osquery-io-ts-types';
import { SECURITY_APP_NAME } from '../../timelines/get_add_to_timeline';
import type { AddToTimelinePayload } from '../../timelines/get_add_to_timeline';
import { PackResultsHeader } from './pack_results_header';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/public/live_queries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiCode, EuiLoadingContent, EuiEmptyPrompt } from '@elastic/eui';
import React, { useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';

import type { ECSMapping } from '../../common/schemas/common';
import type { ECSMapping } from '@kbn/osquery-io-ts-types';
import type { AddToTimelinePayload } from '../timelines/get_add_to_timeline';
import { LiveQueryForm } from './form';
import { useActionResultsPrivileges } from '../action_results/use_action_privileges';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useMutation } from '@tanstack/react-query';
import type { AgentSelection } from '../../common/schemas/common';
import type { AgentSelection } from '@kbn/osquery-io-ts-types';
import type { CreateLiveQueryRequestBodySchema } from '../../common/schemas/routes/live_query';
import { useKibana } from '../common/lib/kibana';
import { useErrorToast } from '../common/hooks/use_error_toast';
Expand Down
Loading

0 comments on commit 58da656

Please sign in to comment.