Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starts converting Joi validation into kbn-config-schema terminology #11

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 93 additions & 56 deletions src/plugins/home/server/lib/tutorial_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import Joi from 'joi';
import { schema } from '@kbn/config-schema';

const PARAM_TYPES = {
NUMBER: 'number',
Expand All @@ -31,65 +32,101 @@ const TUTORIAL_CATEGORY = {
OTHER: 'other',
};

const dashboardSchema = Joi.object({
id: Joi.string().required(), // Dashboard saved object id
linkLabel: Joi.string().when('isOverview', {
is: true,
then: Joi.required(),
}),
// Is this an Overview / Entry Point dashboard?
isOverview: Joi.boolean().required(),
});

const artifactsSchema = Joi.object({
// const dashboardSchema = schema.object({
// id: schema.string(), // Dashboard saved object id
// linkLabel: Joi.string().when('isOverview', {
// is: true,
// then: Joi.required(),
// }),
// // Is this an Overview / Entry Point dashboard?
// isOverview: schema.boolean(),
// });

const artifactsSchema = schema.object({
// Fields present in Elasticsearch documents created by this product.
exportedFields: Joi.object({
documentationUrl: Joi.string().required(),
exportedFields: schema.object({
documentationUrl: schema.string(),
}),
// Kibana dashboards created by this product.
dashboards: Joi.array()
.items(dashboardSchema)
.required(),
application: Joi.object({
path: Joi.string().required(),
label: Joi.string().required(),
dashboards: schema.arrayOf(
schema.object({
id: schema.string(), // Dashboard saved object id
linkLabel: schema.conditional(
// linkLabel is required and must be a string when 'isOverview' has a value of true
schema.siblingRef('isOverview'),
true,
schema.string(),
schema.boolean()
),
isOverview: schema.boolean(),
})
),
application: schema.object({
path: schema.string(),
label: schema.string(),
}),
});

const statusCheckSchema = Joi.object({
title: Joi.string(),
text: Joi.string(),
btnLabel: Joi.string(),
success: Joi.string(),
error: Joi.string(),
esHitsCheck: Joi.object({
index: Joi.alternatives()
.try(Joi.string(), Joi.array().items(Joi.string()))
.required(),
query: Joi.object().required(),
}).required(),
const statusCheckSchema = schema.object({
title: schema.string(),
text: schema.string(),
btnLabel: schema.string(),
success: schema.string(),
error: schema.string(),
esHitsCheck: schema.object({
// index: either a string or an array of strings
index: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]),
// .try(Joi.string(), Joi.array().items(Joi.string()))
// .required(),
query: joi.object(),
}),
});

const instructionSchema = Joi.object({
title: Joi.string(),
textPre: Joi.string(),
commands: Joi.array().items(Joi.string().allow('')),
textPost: Joi.string(),
/*
One of:

query: {
match_all: {},
},

query: {
bool: {
filter: {
term: {
'agent.type': 'auditbeat',
},
},
},
},
query: {
bool: {
filter: [
{ term: { 'processor.event': 'onboarding' } },
{ range: { 'observer.version_major': { gte: 7 } } },
],
},
},
*/

const instructionSchema = schema.object({
title: schema.string(),
textPre: schema.string(),
commands: schema.arrayOf(schema.maybe(schema.oneOf([schema.maybe(schema.string())]))),
textPost: schema.string(),
});

const instructionVariantSchema = Joi.object({
id: Joi.string().required(),
const instructionVariantSchema = schema.object({
id: schema.string(),
instructions: Joi.array()
.items(instructionSchema)
.required(),
});

const instructionSetSchema = Joi.object({
title: Joi.string(),
callOut: Joi.object({
title: Joi.string().required(),
message: Joi.string(),
iconType: Joi.string(),
const instructionSetSchema = schema.object({
title: schema.string(),
callOut: schema.object({
title: schema.string(),
message: schema.string(),
iconType: schema.string(),
}),
// Variants (OSes, languages, etc.) for which tutorial instructions are specified.
instructionVariants: Joi.array()
Expand All @@ -98,18 +135,18 @@ const instructionSetSchema = Joi.object({
statusCheck: statusCheckSchema,
});

const paramSchema = Joi.object({
const paramSchema = schema.object({
defaultValue: Joi.required(),
id: Joi.string()
.regex(/^[a-zA-Z_]+$/)
.required(),
label: Joi.string().required(),
label: schema.string(),
type: Joi.string()
.valid(Object.values(PARAM_TYPES))
.required(),
});

const instructionsSchema = Joi.object({
const instructionsSchema = schema.object({
instructionSets: Joi.array()
.items(instructionSetSchema)
.required(),
Expand All @@ -123,13 +160,13 @@ export const tutorialSchema = {
category: Joi.string()
.valid(Object.values(TUTORIAL_CATEGORY))
.required(),
name: Joi.string().required(),
isBeta: Joi.boolean().default(false),
shortDescription: Joi.string().required(),
euiIconType: Joi.string(), // EUI icon type string, one of https://elastic.github.io/eui/#/icons
longDescription: Joi.string().required(),
completionTimeMinutes: Joi.number().integer(),
previewImagePath: Joi.string(),
name: schema.string(),
isBeta: schema.boolean({ defaultValue: false }),
shortDescription: schema.string(),
euiIconType: schema.string(), // EUI icon type string, one of https://elastic.github.io/eui/#/icons
longDescription: schema.string(),
completionTimeMinutes: schema.number(),
previewImagePath: schema.string(),

// kibana and elastic cluster running on prem
onPrem: instructionsSchema.required(),
Expand All @@ -145,5 +182,5 @@ export const tutorialSchema = {

// saved objects used by data module.
savedObjects: Joi.array().items(),
savedObjectsInstallMsg: Joi.string(),
savedObjectsInstallMsg: schema.string(),
};