Skip to content

Commit

Permalink
[Defend workflows] Establish /common/api folder in osquery plugin (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl committed Aug 1, 2023
1 parent f82ca84 commit 132139e
Show file tree
Hide file tree
Showing 63 changed files with 672 additions and 245 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-io-ts-utils/src/to_number_rt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as t from 'io-ts';

export const toNumberRt = new t.Type<number, unknown, unknown>(
export const toNumberRt = new t.Type<number, number, unknown>(
'ToNumber',
t.number.is,
(input, context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
* 2.0.
*/

export * from './create_saved_query_request_schema';
import * as t from 'io-ts';

export const getAssetsStatusRequestParamsSchema = t.unknown;

export type GetAssetsStatusRequestParamsSchema = t.OutputOf<
typeof getAssetsStatusRequestParamsSchema
>;
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

export const updateAssetsStatusRequestParamsSchema = t.unknown;

export type UpdateAssetsStatusRequestParamsSchema = t.OutputOf<
typeof updateAssetsStatusRequestParamsSchema
>;
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

export const getAgentDetailsRequestParamsSchema = t.unknown;

export type GetAgentDetailsRequestParamsSchema = t.OutputOf<
typeof getAgentDetailsRequestParamsSchema
>;
Original file line number Diff line number Diff line change
@@ -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.
*/

import * as t from 'io-ts';

export const getAgentPoliciesRequestParamsSchema = t.unknown;

export type GetAgentPoliciesRequestParamsSchema = t.OutputOf<
typeof getAgentPoliciesRequestParamsSchema
>;

export const getAgentPoliciesRequestQuerySchema = t.unknown;

export type GetAgentPoliciesRequestQuerySchema = t.OutputOf<
typeof getAgentPoliciesRequestQuerySchema
>;
Original file line number Diff line number Diff line change
@@ -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 * as t from 'io-ts';

export const getAgentPolicyRequestParamsSchema = t.type({
id: t.string,
});

export type GetAgentPolicyRequestParamsSchema = t.OutputOf<
typeof getAgentPolicyRequestParamsSchema
>;
Original file line number Diff line number Diff line change
@@ -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 * as t from 'io-ts';

export const getAgentStatusForAgentPolicyRequestParamsSchema = t.unknown;

export type GetAgentStatusForAgentPolicyRequestParamsSchema = t.OutputOf<
typeof getAgentStatusForAgentPolicyRequestParamsSchema
>;

export const getAgentStatusForAgentPolicyRequestQuerySchema = t.type({
policyId: t.string,
kuery: t.union([t.string, t.undefined]),
});

export type GetAgentStatusForAgentPolicyRequestQuerySchema = t.OutputOf<
typeof getAgentStatusForAgentPolicyRequestQuerySchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
* 2.0.
*/

export * from './utils';
import * as t from 'io-ts';

export const getAgentsRequestQuerySchema = t.unknown;

export type GetAgentsRequestQuerySchema = t.OutputOf<typeof getAgentsRequestQuerySchema>;
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

export const getPackagePoliciesRequestQuerySchema = t.unknown;

export type GetPackagePoliciesRequestQuerySchema = t.OutputOf<
typeof getPackagePoliciesRequestQuerySchema
>;
31 changes: 31 additions & 0 deletions x-pack/plugins/osquery/common/api/index.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

export * from './asset/get_assets_status_route';
export * from './asset/update_assets_status_route';
export * from './fleet_wrapper/get_agent_policies_route';
export * from './fleet_wrapper/get_agent_details_route';
export * from './fleet_wrapper/get_agent_policy_route';
export * from './fleet_wrapper/get_agent_status_for_agent_policy_route';
export * from './fleet_wrapper/get_agents_route';
export * from './fleet_wrapper/get_package_policies_route';
export * from './live_query/create_live_query_route';
export * from './live_query/find_live_query_route';
export * from './live_query/get_live_query_results_route';
export * from './live_query/get_live_query_details_route';
export * from './saved_query/create_saved_query_route';
export * from './saved_query/delete_saved_query_route';
export * from './saved_query/find_saved_query_route';
export * from './saved_query/update_saved_query_route';
export * from './saved_query/read_saved_query_route';
export * from './packs/create_pack_route';
export * from './packs/delete_packs_route';
export * from './packs/find_packs_route';
export * from './packs/read_packs_route';
export * from './packs/update_packs_route';
export * from './model/default_uuid';
export * from './model/non_empty_string';
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';

export const findLiveQueryRequestQuerySchema = t.type({
filterQuery: t.union([t.string, t.undefined]),
page: t.union([toNumberRt, t.undefined]),
pageSize: t.union([toNumberRt, t.undefined]),
sort: t.union([t.string, t.undefined]),
sortOrder: t.union([t.union([t.literal('asc'), t.literal('desc')]), t.undefined]),
});

export type FindLiveQueryRequestQuerySchema = t.OutputOf<typeof findLiveQueryRequestQuerySchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 * as t from 'io-ts';

export const getLiveQueryDetailsRequestQuerySchema = t.unknown;

export type GetLiveQueryDetailsRequestQuerySchema = t.OutputOf<
typeof getLiveQueryDetailsRequestQuerySchema
>;

export const getLiveQueryDetailsRequestParamsSchema = t.type({
id: t.string,
});

export type GetLiveQueryDetailsRequestParamsSchema = t.OutputOf<
typeof getLiveQueryDetailsRequestParamsSchema
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';

export const getLiveQueryResultsRequestQuerySchema = t.type({
filterQuery: t.union([t.string, t.undefined]),
page: t.union([toNumberRt, t.undefined]),
pageSize: t.union([toNumberRt, t.undefined]),
sort: t.union([t.string, t.undefined]),
sortOrder: t.union([t.union([t.literal('asc'), t.literal('desc')]), t.undefined]),
});

export type GetLiveQueryResultsRequestQuerySchema = t.OutputOf<
typeof getLiveQueryResultsRequestQuerySchema
>;

export const getLiveQueryResultsRequestParamsSchema = t.type({
id: t.string,
actionId: t.string,
});

export type GetLiveQueryResultsRequestParamsSchema = t.OutputOf<
typeof getLiveQueryResultsRequestParamsSchema
>;
40 changes: 40 additions & 0 deletions x-pack/plugins/osquery/common/api/packs/create_pack_route.ts
Original file line number Diff line number Diff line change
@@ -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 * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';

export const createPackRequestBodySchema = t.type({
name: t.string,
description: t.union([t.string, t.undefined]),
enabled: t.union([t.boolean, t.undefined]),
policy_ids: t.union([t.array(t.string), t.undefined]),
shards: t.record(t.string, toNumberRt),
queries: t.record(
t.string,
t.type({
query: t.string,
interval: t.union([toNumberRt, t.undefined]),
snapshot: t.union([t.boolean, t.undefined]),
removed: t.union([t.boolean, t.undefined]),
platform: t.union([t.string, t.undefined]),
version: t.union([t.string, t.undefined]),
ecs_mapping: t.union([
t.record(
t.string,
t.type({
field: t.union([t.string, t.undefined]),
value: t.union([t.string, t.array(t.string), t.undefined]),
})
),
t.undefined,
]),
})
),
});

export type CreatePackRequestBodySchema = t.OutputOf<typeof createPackRequestBodySchema>;
14 changes: 14 additions & 0 deletions x-pack/plugins/osquery/common/api/packs/delete_packs_route.ts
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

export const deletePacksRequestParamsSchema = t.type({
id: t.string,
});

export type DeletePacksRequestParamsSchema = t.OutputOf<typeof deletePacksRequestParamsSchema>;
18 changes: 18 additions & 0 deletions x-pack/plugins/osquery/common/api/packs/find_packs_route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';

export const findPacksRequestQuerySchema = t.type({
page: t.union([toNumberRt, t.undefined]),
pageSize: t.union([toNumberRt, t.undefined]),
sort: t.union([t.string, t.undefined]),
sortOrder: t.union([t.union([t.literal('asc'), t.literal('desc')]), t.undefined]),
});

export type FindPacksRequestQuerySchema = t.OutputOf<typeof findPacksRequestQuerySchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
* 2.0.
*/

export * from './create_live_query_request_body_schema';
import * as t from 'io-ts';

export const readPacksRequestParamsSchema = t.type({
id: t.string,
});

export type ReadPacksRequestParamsSchema = t.OutputOf<typeof readPacksRequestParamsSchema>;
49 changes: 49 additions & 0 deletions x-pack/plugins/osquery/common/api/packs/update_packs_route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';

export const updatePacksRequestBodySchema = t.type({
name: t.union([t.string, t.undefined]),
description: t.union([t.string, t.undefined]),
enabled: t.union([t.boolean, t.undefined]),
policy_ids: t.union([t.array(t.string), t.undefined]),
shards: t.union([t.record(t.string, toNumberRt), t.undefined]),
queries: t.union([
t.record(
t.string,
t.type({
query: t.string,
interval: t.union([toNumberRt, t.undefined]),
snapshot: t.union([t.boolean, t.undefined]),
removed: t.union([t.boolean, t.undefined]),
platform: t.union([t.string, t.undefined]),
version: t.union([t.string, t.undefined]),
ecs_mapping: t.union([
t.record(
t.string,
t.type({
field: t.union([t.string, t.undefined]),
value: t.union([t.string, t.array(t.string), t.undefined]),
})
),
t.undefined,
]),
})
),
t.undefined,
]),
});

export type UpdatePacksRequestBodySchema = t.OutputOf<typeof updatePacksRequestBodySchema>;

export const updatePacksRequestParamsSchema = t.type({
id: t.string,
});

export type UpdatePacksRequestParamsSchema = t.OutputOf<typeof updatePacksRequestParamsSchema>;
Original file line number Diff line number Diff line change
@@ -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 * as t from 'io-ts';

export const deleteSavedQueryRequestParamsSchema = t.type({
id: t.string,
});

export type DeleteSavedQueryRequestParamsSchema = t.OutputOf<
typeof deleteSavedQueryRequestParamsSchema
>;
Loading

0 comments on commit 132139e

Please sign in to comment.