From f7393c54807d0d74bcf5f6771fbdb25c47daaf19 Mon Sep 17 00:00:00 2001 From: Tomasz Ciecierski Date: Fri, 3 Nov 2023 16:39:05 +0100 Subject: [PATCH] [EDR Workflows] Include Osquery openApi schemas in codegen (#170389) --- .buildkite/scripts/steps/checks.sh | 1 + .../steps/code_generation/osquery_codegen.sh | 10 + .../common/api/asset/assets_status.gen.ts | 19 ++ .../fleet_wrapper/get_agent_details.gen.ts | 19 ++ .../fleet_wrapper/get_agent_policies.gen.ts | 19 ++ .../api/fleet_wrapper/get_agent_policy.gen.ts | 23 +++ .../api/fleet_wrapper/get_agent_status.gen.ts | 27 +++ .../api/fleet_wrapper/get_agents.gen.ts | 19 ++ .../fleet_wrapper/get_package_policies.gen.ts | 19 ++ .../api/live_query/create_live_query.gen.ts | 41 ++++ .../api/live_query/find_live_query.gen.ts | 33 ++++ .../live_query/get_live_query_details.gen.ts | 16 ++ .../live_query/get_live_query_results.gen.ts | 40 ++++ .../api/model/schema/common_attributes.gen.ts | 176 ++++++++++++++++++ .../common/api/packs/create_pack.gen.ts | 35 ++++ .../common/api/packs/delete_packs.gen.ts | 23 +++ .../common/api/packs/find_packs.gen.ts | 31 +++ .../common/api/packs/read_packs.gen.ts | 23 +++ .../common/api/packs/update_packs.gen.ts | 40 ++++ .../api/saved_query/create_saved_query.gen.ts | 40 ++++ .../api/saved_query/delete_saved_query.gen.ts | 23 +++ .../api/saved_query/find_saved_query.gen.ts | 31 +++ .../api/saved_query/read_saved_query.gen.ts | 23 +++ .../api/saved_query/update_saved_query.gen.ts | 45 +++++ x-pack/plugins/osquery/package.json | 3 +- .../osquery/scripts/openapi/generate.js | 20 ++ x-pack/plugins/osquery/tsconfig.json | 3 +- 27 files changed, 800 insertions(+), 2 deletions(-) create mode 100755 .buildkite/scripts/steps/code_generation/osquery_codegen.sh create mode 100644 x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/live_query/create_live_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/live_query/find_live_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/live_query/get_live_query_details.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/live_query/get_live_query_results.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/model/schema/common_attributes.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/packs/create_pack.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/packs/delete_packs.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/packs/find_packs.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/packs/read_packs.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/packs/update_packs.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/saved_query/create_saved_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/saved_query/delete_saved_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/saved_query/find_saved_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/saved_query/read_saved_query.gen.ts create mode 100644 x-pack/plugins/osquery/common/api/saved_query/update_saved_query.gen.ts create mode 100644 x-pack/plugins/osquery/scripts/openapi/generate.js diff --git a/.buildkite/scripts/steps/checks.sh b/.buildkite/scripts/steps/checks.sh index 639e3f02ef1df..4d9461a6a2bff 100755 --- a/.buildkite/scripts/steps/checks.sh +++ b/.buildkite/scripts/steps/checks.sh @@ -24,4 +24,5 @@ export DISABLE_BOOTSTRAP_VALIDATION=false .buildkite/scripts/steps/checks/saved_objects_compat_changes.sh .buildkite/scripts/steps/checks/saved_objects_definition_change.sh .buildkite/scripts/steps/code_generation/security_solution_codegen.sh +.buildkite/scripts/steps/code_generation/osquery_codegen.sh .buildkite/scripts/steps/checks/yarn_deduplicate.sh diff --git a/.buildkite/scripts/steps/code_generation/osquery_codegen.sh b/.buildkite/scripts/steps/code_generation/osquery_codegen.sh new file mode 100755 index 0000000000000..7c04f4aecd442 --- /dev/null +++ b/.buildkite/scripts/steps/code_generation/osquery_codegen.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source .buildkite/scripts/common/util.sh + +echo --- Osquery OpenAPI Code Generation + +(cd x-pack/plugins/osquery && yarn openapi:generate) +check_for_changed_files "yarn openapi:generate" true diff --git a/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts b/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts new file mode 100644 index 0000000000000..5874e8146f5c0 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/asset/assets_status.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type AssetsRequestQuery = z.infer; +export const AssetsRequestQuery = z.object({}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts new file mode 100644 index 0000000000000..9fa827aa002f0 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_details.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type GetAgentDetailsRequestParams = z.infer; +export const GetAgentDetailsRequestParams = z.object({}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts new file mode 100644 index 0000000000000..603351f7efd72 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policies.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type GetAgentPoliciesRequestParams = z.infer; +export const GetAgentPoliciesRequestParams = z.object({}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts new file mode 100644 index 0000000000000..a1969fa271067 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_policy.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { Id } from '../model/schema/common_attributes.gen'; + +export type GetAgentPolicyRequestParams = z.infer; +export const GetAgentPolicyRequestParams = z.object({ + id: Id.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts new file mode 100644 index 0000000000000..1869dadbbe6b1 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agent_status.gen.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { KueryOrUndefined, Id } from '../model/schema/common_attributes.gen'; + +export type GetAgentStatusRequestParams = z.infer; +export const GetAgentStatusRequestParams = z.object({}); + +export type GetAgentStatusRequestQueryParams = z.infer; +export const GetAgentStatusRequestQueryParams = z.object({ + kuery: KueryOrUndefined.optional(), + policyId: Id.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts new file mode 100644 index 0000000000000..549e5f3ddfe56 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_agents.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type GetAgentsRequestParams = z.infer; +export const GetAgentsRequestParams = z.object({}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts new file mode 100644 index 0000000000000..d4def39d3fea3 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/fleet_wrapper/get_package_policies.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type GetPackagePoliciesRequestParams = z.infer; +export const GetPackagePoliciesRequestParams = z.object({}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/live_query/create_live_query.gen.ts b/x-pack/plugins/osquery/common/api/live_query/create_live_query.gen.ts new file mode 100644 index 0000000000000..566dd638b0ea1 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/live_query/create_live_query.gen.ts @@ -0,0 +1,41 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + QueryOrUndefined, + ArrayQueries, + SavedQueryIdOrUndefined, + ECSMappingOrUndefined, + PackIdOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type CreateLiveQueryRequestBody = z.infer; +export const CreateLiveQueryRequestBody = z.object({ + agent_ids: z.array(z.string()).optional(), + agent_all: z.boolean().optional(), + agent_platforms: z.array(z.string()).optional(), + agent_policy_ids: z.array(z.string()).optional(), + query: QueryOrUndefined.optional(), + queries: ArrayQueries.optional(), + saved_query_id: SavedQueryIdOrUndefined.optional(), + ecs_mapping: ECSMappingOrUndefined.optional(), + pack_id: PackIdOrUndefined.optional(), + alert_ids: z.array(z.string()).optional(), + case_ids: z.array(z.string()).optional(), + event_ids: z.array(z.string()).optional(), + metadata: z.object({}).nullable().optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/live_query/find_live_query.gen.ts b/x-pack/plugins/osquery/common/api/live_query/find_live_query.gen.ts new file mode 100644 index 0000000000000..872cca6515745 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/live_query/find_live_query.gen.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + KueryOrUndefined, + PageOrUndefined, + PageSizeOrUndefined, + SortOrUndefined, + SortOrderOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type FindLiveQueryRequestQuery = z.infer; +export const FindLiveQueryRequestQuery = z.object({ + kuery: KueryOrUndefined.optional(), + page: PageOrUndefined.optional(), + pageSize: PageSizeOrUndefined.optional(), + sort: SortOrUndefined.optional(), + sortOrder: SortOrderOrUndefined.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/live_query/get_live_query_details.gen.ts b/x-pack/plugins/osquery/common/api/live_query/get_live_query_details.gen.ts new file mode 100644 index 0000000000000..cd6447ac1ab43 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/live_query/get_live_query_details.gen.ts @@ -0,0 +1,16 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/live_query/get_live_query_results.gen.ts b/x-pack/plugins/osquery/common/api/live_query/get_live_query_results.gen.ts new file mode 100644 index 0000000000000..c3b1eb0378407 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/live_query/get_live_query_results.gen.ts @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + KueryOrUndefined, + PageOrUndefined, + PageSizeOrUndefined, + SortOrUndefined, + SortOrderOrUndefined, + Id, +} from '../model/schema/common_attributes.gen'; + +export type GetLiveQueryResultsRequestQuery = z.infer; +export const GetLiveQueryResultsRequestQuery = z.object({ + kuery: KueryOrUndefined.optional(), + page: PageOrUndefined.optional(), + pageSize: PageSizeOrUndefined.optional(), + sort: SortOrUndefined.optional(), + sortOrder: SortOrderOrUndefined.optional(), +}); + +export type GetLiveQueryResultsRequestParams = z.infer; +export const GetLiveQueryResultsRequestParams = z.object({ + id: Id.optional(), + actionId: Id.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/model/schema/common_attributes.gen.ts b/x-pack/plugins/osquery/common/api/model/schema/common_attributes.gen.ts new file mode 100644 index 0000000000000..bd7d0fd8063fe --- /dev/null +++ b/x-pack/plugins/osquery/common/api/model/schema/common_attributes.gen.ts @@ -0,0 +1,176 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +export type Id = z.infer; +export const Id = z.string(); + +export type IdOrUndefined = z.infer; +export const IdOrUndefined = Id.nullable(); + +export type AgentSelection = z.infer; +export const AgentSelection = z.object({ + agents: z.array(z.string()).optional(), + allAgentsSelected: z.boolean().optional(), + platformsSelected: z.array(z.string()).optional(), + policiesSelected: z.array(z.string()).optional(), +}); + +export type AgentSelectionOrUndefined = z.infer; +export const AgentSelectionOrUndefined = AgentSelection.nullable(); + +export type Description = z.infer; +export const Description = z.string(); + +export type DescriptionOrUndefined = z.infer; +export const DescriptionOrUndefined = Description.nullable(); + +export type Platform = z.infer; +export const Platform = z.string(); + +export type PlatformOrUndefined = z.infer; +export const PlatformOrUndefined = Platform.nullable(); + +export type Query = z.infer; +export const Query = z.string(); + +export type QueryOrUndefined = z.infer; +export const QueryOrUndefined = Query.nullable(); + +export type Version = z.infer; +export const Version = z.string(); + +export type VersionOrUndefined = z.infer; +export const VersionOrUndefined = Version.nullable(); + +export type Interval = z.infer; +export const Interval = z.string(); + +export type IntervalOrUndefined = z.infer; +export const IntervalOrUndefined = Interval.nullable(); + +export type Snapshot = z.infer; +export const Snapshot = z.boolean(); + +export type SnapshotOrUndefined = z.infer; +export const SnapshotOrUndefined = Snapshot.nullable(); + +export type Removed = z.infer; +export const Removed = z.boolean(); + +export type RemovedOrUndefined = z.infer; +export const RemovedOrUndefined = Removed.nullable(); + +export type PackName = z.infer; +export const PackName = z.string(); + +export type SavedQueryId = z.infer; +export const SavedQueryId = z.string(); + +export type SavedQueryIdOrUndefined = z.infer; +export const SavedQueryIdOrUndefined = SavedQueryId.nullable(); + +export type PackId = z.infer; +export const PackId = z.string(); + +export type PackIdOrUndefined = z.infer; +export const PackIdOrUndefined = PackId.nullable(); + +export type Enabled = z.infer; +export const Enabled = z.boolean(); + +export type EnabledOrUndefined = z.infer; +export const EnabledOrUndefined = Enabled.nullable(); + +export type PolicyIds = z.infer; +export const PolicyIds = z.array(z.string()); + +export type PolicyIdsOrUndefined = z.infer; +export const PolicyIdsOrUndefined = PolicyIds.nullable(); + +export type ExecutionContext = z.infer; +export const ExecutionContext = z.object({ + name: z.string().nullable().optional(), + url: z.string().nullable().optional(), +}); + +export type ExecutionContextOrUndefined = z.infer; +export const ExecutionContextOrUndefined = ExecutionContext.nullable(); + +export type ECSMappingItem = z.infer; +export const ECSMappingItem = z.object({ + field: z.string().optional(), + value: z.union([z.string(), z.array(z.string())]).optional(), +}); + +export type ECSMapping = z.infer; +export const ECSMapping = z.object({}).catchall(ECSMappingItem); + +export type ECSMappingOrUndefined = z.infer; +export const ECSMappingOrUndefined = ECSMapping.nullable(); + +export type StringArrayOrUndefined = z.infer; +export const StringArrayOrUndefined = z.array(z.string().nullable()); + +export type ArrayQueriesItem = z.infer; +export const ArrayQueriesItem = z.object({ + id: Id.optional(), + query: Query.optional(), + ecs_mapping: ECSMappingOrUndefined.optional(), + version: VersionOrUndefined.optional(), + platform: PlatformOrUndefined.optional(), + removed: RemovedOrUndefined.optional(), + snapshot: SnapshotOrUndefined.optional(), +}); + +export type ArrayQueries = z.infer; +export const ArrayQueries = z.array(ArrayQueriesItem); + +export type ObjectQueriesItem = z.infer; +export const ObjectQueriesItem = z.object({ + query: Query.optional(), + id: Id.optional(), + ecs_mapping: ECSMappingOrUndefined.optional(), + version: VersionOrUndefined.optional(), + platform: PlatformOrUndefined.optional(), + saved_query_id: SavedQueryIdOrUndefined.optional(), + removed: RemovedOrUndefined.optional(), + snapshot: SnapshotOrUndefined.optional(), +}); + +export type ObjectQueries = z.infer; +export const ObjectQueries = z.object({}).catchall(ObjectQueriesItem); + +export type Queries = z.infer; +export const Queries = z.union([ArrayQueries, ObjectQueries]); + +export type QueriesOrUndefined = z.infer; +export const QueriesOrUndefined = Queries.nullable(); + +export type KueryOrUndefined = z.infer; +export const KueryOrUndefined = z.string().nullable(); + +export type PageOrUndefined = z.infer; +export const PageOrUndefined = z.number().int().nullable(); + +export type PageSizeOrUndefined = z.infer; +export const PageSizeOrUndefined = z.number().int().nullable(); + +export type SortOrUndefined = z.infer; +export const SortOrUndefined = z.string().nullable(); + +export type SortOrderOrUndefined = z.infer; +export const SortOrderOrUndefined = z.union([z.string().nullable(), z.unknown()]); + +export type Shards = z.infer; +export const Shards = z.object({}).catchall(z.number()); diff --git a/x-pack/plugins/osquery/common/api/packs/create_pack.gen.ts b/x-pack/plugins/osquery/common/api/packs/create_pack.gen.ts new file mode 100644 index 0000000000000..4c811fdf5941a --- /dev/null +++ b/x-pack/plugins/osquery/common/api/packs/create_pack.gen.ts @@ -0,0 +1,35 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + PackName, + DescriptionOrUndefined, + EnabledOrUndefined, + PolicyIdsOrUndefined, + Shards, + ObjectQueries, +} from '../model/schema/common_attributes.gen'; + +export type CreatePacksRequestBody = z.infer; +export const CreatePacksRequestBody = z.object({ + name: PackName.optional(), + description: DescriptionOrUndefined.optional(), + enabled: EnabledOrUndefined.optional(), + policy_ids: PolicyIdsOrUndefined.optional(), + shards: Shards.optional(), + queries: ObjectQueries.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/packs/delete_packs.gen.ts b/x-pack/plugins/osquery/common/api/packs/delete_packs.gen.ts new file mode 100644 index 0000000000000..76cccaa169868 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/packs/delete_packs.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { PackId } from '../model/schema/common_attributes.gen'; + +export type DeletePacksRequestQuery = z.infer; +export const DeletePacksRequestQuery = z.object({ + id: PackId.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/packs/find_packs.gen.ts b/x-pack/plugins/osquery/common/api/packs/find_packs.gen.ts new file mode 100644 index 0000000000000..c85d9e324e3d3 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/packs/find_packs.gen.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + PageOrUndefined, + PageSizeOrUndefined, + SortOrUndefined, + SortOrderOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type FindPacksRequestQuery = z.infer; +export const FindPacksRequestQuery = z.object({ + page: PageOrUndefined.optional(), + pageSize: PageSizeOrUndefined.optional(), + sort: SortOrUndefined.optional(), + sortOrder: SortOrderOrUndefined.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/packs/read_packs.gen.ts b/x-pack/plugins/osquery/common/api/packs/read_packs.gen.ts new file mode 100644 index 0000000000000..a16e7e7029b43 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/packs/read_packs.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { PackId } from '../model/schema/common_attributes.gen'; + +export type ReadPacksRequestQuery = z.infer; +export const ReadPacksRequestQuery = z.object({ + id: PackId.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/packs/update_packs.gen.ts b/x-pack/plugins/osquery/common/api/packs/update_packs.gen.ts new file mode 100644 index 0000000000000..bbeb77100da1b --- /dev/null +++ b/x-pack/plugins/osquery/common/api/packs/update_packs.gen.ts @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + PackId, + DescriptionOrUndefined, + EnabledOrUndefined, + PolicyIdsOrUndefined, + Shards, + ObjectQueries, +} from '../model/schema/common_attributes.gen'; + +export type UpdatePacksRequestParams = z.infer; +export const UpdatePacksRequestParams = z.object({ + id: PackId.optional(), +}); + +export type UpdatePacksRequestBody = z.infer; +export const UpdatePacksRequestBody = z.object({ + id: PackId.optional(), + description: DescriptionOrUndefined.optional(), + enabled: EnabledOrUndefined.optional(), + policy_ids: PolicyIdsOrUndefined.optional(), + shards: Shards.optional(), + queries: ObjectQueries.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/saved_query/create_saved_query.gen.ts b/x-pack/plugins/osquery/common/api/saved_query/create_saved_query.gen.ts new file mode 100644 index 0000000000000..cc881049a5cbf --- /dev/null +++ b/x-pack/plugins/osquery/common/api/saved_query/create_saved_query.gen.ts @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + SavedQueryId, + DescriptionOrUndefined, + QueryOrUndefined, + ECSMappingOrUndefined, + VersionOrUndefined, + Interval, + SnapshotOrUndefined, + RemovedOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type CreateSavedQueryRequestBody = z.infer; +export const CreateSavedQueryRequestBody = z.object({ + id: SavedQueryId.optional(), + description: DescriptionOrUndefined.optional(), + query: QueryOrUndefined.optional(), + ecs_mapping: ECSMappingOrUndefined.optional(), + version: VersionOrUndefined.optional(), + platform: DescriptionOrUndefined.optional(), + interval: Interval.optional(), + snapshot: SnapshotOrUndefined.optional(), + removed: RemovedOrUndefined.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/saved_query/delete_saved_query.gen.ts b/x-pack/plugins/osquery/common/api/saved_query/delete_saved_query.gen.ts new file mode 100644 index 0000000000000..da915ad32da1a --- /dev/null +++ b/x-pack/plugins/osquery/common/api/saved_query/delete_saved_query.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { SavedQueryId } from '../model/schema/common_attributes.gen'; + +export type DeleteSavedQueryRequestQuery = z.infer; +export const DeleteSavedQueryRequestQuery = z.object({ + id: SavedQueryId.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/saved_query/find_saved_query.gen.ts b/x-pack/plugins/osquery/common/api/saved_query/find_saved_query.gen.ts new file mode 100644 index 0000000000000..43ab5c93a6549 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/saved_query/find_saved_query.gen.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + PageOrUndefined, + PageSizeOrUndefined, + SortOrUndefined, + SortOrderOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type FindSavedQueryRequestQuery = z.infer; +export const FindSavedQueryRequestQuery = z.object({ + page: PageOrUndefined.optional(), + pageSize: PageSizeOrUndefined.optional(), + sort: SortOrUndefined.optional(), + sortOrder: SortOrderOrUndefined.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/saved_query/read_saved_query.gen.ts b/x-pack/plugins/osquery/common/api/saved_query/read_saved_query.gen.ts new file mode 100644 index 0000000000000..e6d76e1dd7bd2 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/saved_query/read_saved_query.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { SavedQueryId } from '../model/schema/common_attributes.gen'; + +export type ReadSavedQueryRequestQuery = z.infer; +export const ReadSavedQueryRequestQuery = z.object({ + id: SavedQueryId.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/common/api/saved_query/update_saved_query.gen.ts b/x-pack/plugins/osquery/common/api/saved_query/update_saved_query.gen.ts new file mode 100644 index 0000000000000..b6eddccae6fa3 --- /dev/null +++ b/x-pack/plugins/osquery/common/api/saved_query/update_saved_query.gen.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { z } from 'zod'; + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + */ + +import { + SavedQueryId, + DescriptionOrUndefined, + QueryOrUndefined, + ECSMappingOrUndefined, + VersionOrUndefined, + IntervalOrUndefined, + SnapshotOrUndefined, + RemovedOrUndefined, +} from '../model/schema/common_attributes.gen'; + +export type UpdateSavedQueryRequestParams = z.infer; +export const UpdateSavedQueryRequestParams = z.object({ + id: SavedQueryId.optional(), +}); + +export type UpdateSavedQueryRequestBody = z.infer; +export const UpdateSavedQueryRequestBody = z.object({ + id: SavedQueryId.optional(), + description: DescriptionOrUndefined.optional(), + query: QueryOrUndefined.optional(), + ecs_mapping: ECSMappingOrUndefined.optional(), + version: VersionOrUndefined.optional(), + platform: DescriptionOrUndefined.optional(), + interval: IntervalOrUndefined.optional(), + snapshot: SnapshotOrUndefined.optional(), + removed: RemovedOrUndefined.optional(), +}); + +export type SuccessResponse = z.infer; +export const SuccessResponse = z.object({}); diff --git a/x-pack/plugins/osquery/package.json b/x-pack/plugins/osquery/package.json index e9ab128dd45fb..4e9070d780d28 100644 --- a/x-pack/plugins/osquery/package.json +++ b/x-pack/plugins/osquery/package.json @@ -15,6 +15,7 @@ "cypress:serverless:run": "yarn cypress:serverless run", "nyc": "../../../node_modules/.bin/nyc report --reporter=text-summary", "junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-osquery/cypress/results/mochawesome*.json > ../../../target/kibana-osquery/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-osquery/cypress/results/output.json --reportDir ../../../target/kibana-osquery/cypress/results && yarn junit:transform && mkdir -p ../../../target/junit && cp ../../../target/kibana-osquery/cypress/results/*.xml ../../../target/junit/", - "junit:transform": "node ../security_solution/scripts/junit_transformer --pathPattern '../../../target/kibana-osquery/cypress/results/*.xml' --rootDirectory ../../../ --reportName 'Osquery Cypress' --writeInPlace" + "junit:transform": "node ../security_solution/scripts/junit_transformer --pathPattern '../../../target/kibana-osquery/cypress/results/*.xml' --rootDirectory ../../../ --reportName 'Osquery Cypress' --writeInPlace", + "openapi:generate": "node scripts/openapi/generate" } } diff --git a/x-pack/plugins/osquery/scripts/openapi/generate.js b/x-pack/plugins/osquery/scripts/openapi/generate.js new file mode 100644 index 0000000000000..018a965702c3e --- /dev/null +++ b/x-pack/plugins/osquery/scripts/openapi/generate.js @@ -0,0 +1,20 @@ +/* + * 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. + */ + +require('../../../../../src/setup_node_env'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { generate } = require('@kbn/openapi-generator'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { resolve } = require('path'); + +const OSQUERY_ROOT = resolve(__dirname, '../..'); + +generate({ + rootDir: OSQUERY_ROOT, + sourceGlob: './**/*.schema.yaml', + templateName: 'zod_operation_schema', +}); diff --git a/x-pack/plugins/osquery/tsconfig.json b/x-pack/plugins/osquery/tsconfig.json index 6516c4241f0df..dbf926d5fae68 100644 --- a/x-pack/plugins/osquery/tsconfig.json +++ b/x-pack/plugins/osquery/tsconfig.json @@ -73,6 +73,7 @@ "@kbn/core-saved-objects-server", "@kbn/monaco", "@kbn/io-ts-utils", - "@kbn/shared-ux-page-kibana-template" + "@kbn/shared-ux-page-kibana-template", + "@kbn/openapi-generator" ] }