Skip to content

Commit

Permalink
[Discover][Saved Query] Add schema for Saved Query SO (#154230)
Browse files Browse the repository at this point in the history
## Summary

A follow up for #153131
This PR adds schema for Saved Query SO type.
  • Loading branch information
jughosta authored Apr 18, 2023
1 parent 970de91 commit 682f12e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"osquery-pack": "edd84b2c59ef36214ece0676706da8f22175c660",
"osquery-pack-asset": "18e08979d46ee7e5538f54c080aec4d8c58516ca",
"osquery-saved-query": "f5e4e303f65c7607248ea8b2672f1ee30e4fb15e",
"query": "ec6000b775f06f81470df42d23f7a88cb31d64ba",
"query": "cfc049e1f0574fb4fdb2d653d7c10bdc970a2610",
"rules-settings": "9854495c3b54b16a6625fb250c35e5504da72266",
"sample-data-telemetry": "c38daf1a49ed24f2a4fb091e6e1e833fccf19935",
"search": "ed3a9b1681b57d69560909d51933fdf17576ea68",
Expand Down
16 changes: 5 additions & 11 deletions src/plugins/data/server/saved_objects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { SavedObjectsType } from '@kbn/core/server';
import { savedQueryMigrations } from './migrations/query';
import { SCHEMA_QUERY_V8_8_0 } from './schemas/query';

export const querySavedObjectType: SavedObjectsType = {
name: 'query',
Expand All @@ -29,21 +30,14 @@ export const querySavedObjectType: SavedObjectsType = {
},
},
mappings: {
dynamic: false,
properties: {
title: { type: 'text' },
description: { type: 'text' },
query: {
dynamic: false,
properties: {
language: { type: 'keyword' },
},
},
filters: {
dynamic: false,
properties: {},
},
timefilter: { dynamic: false, properties: {} },
},
},
migrations: savedQueryMigrations,
schemas: {
'8.8.0': SCHEMA_QUERY_V8_8_0,
},
};
32 changes: 32 additions & 0 deletions src/plugins/data/server/saved_objects/schemas/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { schema } from '@kbn/config-schema';

// As per `SavedQueryAttributes`
export const SCHEMA_QUERY_V8_8_0 = schema.object({
title: schema.string(),
description: schema.string({ defaultValue: '' }),
query: schema.object({
language: schema.string(),
query: schema.oneOf([schema.string(), schema.object({}, { unknowns: 'allow' })]),
}),
filters: schema.maybe(schema.arrayOf(schema.object({}, { unknowns: 'allow' }))),
timefilter: schema.maybe(
schema.object({
from: schema.string(),
to: schema.string(),
refreshInterval: schema.maybe(
schema.object({
value: schema.number(),
pause: schema.boolean(),
})
),
})
),
});

0 comments on commit 682f12e

Please sign in to comment.