-
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.
[SecuritySolution] Revamp entity analytics Open API schemas (#182666)
## Summary * Declare all API types using Open API Schema (OAS). * Generate TS types from schemas * Update the code to use the generated types * Validate requests with `buildRouteValidationWithZod ` * Delete `x-pack/plugins/security_solution/common/api/entity_analytics/risk_engine/common.schema.yaml`. There were 2 common files. * Auto format `yaml` files for consistency. * Rename `yaml` files from `{name}_schema.yml` to `{name}.schema.yml`. Otherwise, they don't work with the generator. * Rename `RiskScore` to `EntityRiskScoreRecord` (requested by Maxim) * Update yaml version to '1'
- Loading branch information
Showing
115 changed files
with
1,542 additions
and
2,066 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
2 changes: 1 addition & 1 deletion
2
...lution/common/api/entity_analytics/asset_criticality/create_asset_criticality.schema.yaml
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
2 changes: 1 addition & 1 deletion
2
...lution/common/api/entity_analytics/asset_criticality/delete_asset_criticality.schema.yaml
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
2 changes: 1 addition & 1 deletion
2
..._solution/common/api/entity_analytics/asset_criticality/get_asset_criticality.schema.yaml
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
43 changes: 43 additions & 0 deletions
43
...ion/common/api/entity_analytics/asset_criticality/get_asset_criticality_privileges.gen.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,43 @@ | ||
/* | ||
* 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. | ||
* | ||
* info: | ||
* title: Get Asset Criticality Privileges Schema | ||
* version: 1 | ||
*/ | ||
|
||
export type EntityAnalyticsPrivileges = z.infer<typeof EntityAnalyticsPrivileges>; | ||
export const EntityAnalyticsPrivileges = z.object({ | ||
has_all_required: z.boolean(), | ||
has_read_permissions: z.boolean().optional(), | ||
has_write_permissions: z.boolean().optional(), | ||
privileges: z.object({ | ||
elasticsearch: z.object({ | ||
cluster: z | ||
.object({ | ||
manage_index_templates: z.boolean().optional(), | ||
manage_transform: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
index: z | ||
.object({}) | ||
.catchall( | ||
z.object({ | ||
read: z.boolean().optional(), | ||
write: z.boolean().optional(), | ||
}) | ||
) | ||
.optional(), | ||
}), | ||
}), | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
...on/common/api/entity_analytics/asset_criticality/get_asset_criticality_status.schema.yaml
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
2 changes: 1 addition & 1 deletion
2
...on/common/api/entity_analytics/asset_criticality/upload_asset_criticality_csv.schema.yaml
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
52 changes: 52 additions & 0 deletions
52
...ck/plugins/security_solution/common/api/entity_analytics/common/after_keys.schema.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,52 @@ | ||
/* | ||
* 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 { AfterKeys } from '.'; | ||
import type { SafeParseSuccess } from 'zod'; | ||
|
||
describe('after_keys schema', () => { | ||
it('allows an empty object', () => { | ||
const payload = {}; | ||
const decoded = AfterKeys.safeParse(payload) as SafeParseSuccess<object>; | ||
|
||
expect(decoded.success).toBeTruthy(); | ||
expect(decoded.data).toEqual(payload); | ||
}); | ||
|
||
it('allows a valid host key', () => { | ||
const payload = { host: { 'host.name': 'hello' } }; | ||
const decoded = AfterKeys.safeParse(payload) as SafeParseSuccess<object>; | ||
|
||
expect(decoded.success).toBeTruthy(); | ||
expect(decoded.data).toEqual(payload); | ||
}); | ||
|
||
it('allows a valid user key', () => { | ||
const payload = { user: { 'user.name': 'hello' } }; | ||
const decoded = AfterKeys.safeParse(payload) as SafeParseSuccess<object>; | ||
|
||
expect(decoded.success).toBeTruthy(); | ||
expect(decoded.data).toEqual(payload); | ||
}); | ||
|
||
it('allows both valid host and user keys', () => { | ||
const payload = { user: { 'user.name': 'hello' }, host: { 'host.name': 'hello' } }; | ||
const decoded = AfterKeys.safeParse(payload) as SafeParseSuccess<object>; | ||
|
||
expect(decoded.success).toBeTruthy(); | ||
expect(decoded.data).toEqual(payload); | ||
}); | ||
|
||
it('removes an unknown identifier key if used', () => { | ||
const payload = { bad: 'key' }; | ||
|
||
const decoded = AfterKeys.safeParse(payload) as SafeParseSuccess<object>; | ||
|
||
expect(decoded.success).toBeTruthy(); | ||
expect(decoded.data).toEqual({}); | ||
}); | ||
}); |
Oops, something went wrong.