Skip to content

Commit

Permalink
Merge branch 'main' into issue_180088
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 9, 2024
2 parents 1c42580 + 4b69083 commit 5816065
Show file tree
Hide file tree
Showing 41 changed files with 1,740 additions and 637 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ image::management/connectors/images/cases-webhook-connector-comments.png[Add cas

Add HTTP header::
A set of key-value pairs sent as headers with the request URLs for the create case, update case, get case, and create comment methods.
For example, set `Content-Type` to the appropriate media type for your requests.

Create case method::
The REST API HTTP request method to create a case in the third-party system: `post`(default), `put`, or `patch`.
Expand Down
4 changes: 3 additions & 1 deletion docs/management/connectors/action-types/webhook.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Authentication::
The authentication type: none, basic, or SSL.
If you choose basic authentication, you must provide a user name and password.
If you choose SSL authentication, you must provide SSL server certificate authentication data in a CRT and key file format or a PFX file format. You can also optionally provide a passphrase if the files are password-protected.
HTTP headers:: A set of key-value pairs sent as headers with the request.
HTTP headers::
A set of key-value pairs sent as headers with the request.
For example, set `Content-Type` to the appropriate media type for your requests.
Certificate authority::
A certificate authority (CA) that the connector can trust, for example to sign and validate server certificates.
This option is available for all authentication types.
Expand Down
14 changes: 14 additions & 0 deletions packages/kbn-config-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,17 @@ export const schema = {
};

export type Schema = typeof schema;

import {
META_FIELD_X_OAS_OPTIONAL,
META_FIELD_X_OAS_MAX_LENGTH,
META_FIELD_X_OAS_MIN_LENGTH,
META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES,
} from './src/oas_meta_fields';

export const metaFields = Object.freeze({
META_FIELD_X_OAS_OPTIONAL,
META_FIELD_X_OAS_MAX_LENGTH,
META_FIELD_X_OAS_MIN_LENGTH,
META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES,
});
17 changes: 17 additions & 0 deletions packages/kbn-config-schema/src/oas_meta_fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/

/**
* These fields are used in Joi meta to capture additional information used
* by OpenAPI spec generator.
*/
export const META_FIELD_X_OAS_OPTIONAL = 'x-oas-optional' as const;
export const META_FIELD_X_OAS_MIN_LENGTH = 'x-oas-min-length' as const;
export const META_FIELD_X_OAS_MAX_LENGTH = 'x-oas-max-length' as const;
export const META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES =
'x-oas-get-additional-properties' as const;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '../..';
import { META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES } from '../oas_meta_fields';

test('handles object as input', () => {
const type = schema.mapOf(schema.string(), schema.string());
Expand Down Expand Up @@ -186,6 +187,17 @@ test('error preserves full path', () => {
);
});

test('meta', () => {
const stringSchema = schema.string();
const type = schema.mapOf(schema.string(), stringSchema);
const result = type
.getSchema()
.describe()
.metas![0][META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES]();

expect(result).toBe(stringSchema.getSchema());
});

describe('#extendsDeep', () => {
describe('#keyType', () => {
const type = schema.mapOf(schema.string(), schema.object({ foo: schema.string() }));
Expand Down
8 changes: 7 additions & 1 deletion packages/kbn-config-schema/src/types/map_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typeDetect from 'type-detect';
import { SchemaTypeError, SchemaTypesError } from '../errors';
import { internals } from '../internals';
import { META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES } from '../oas_meta_fields';
import { Type, TypeOptions, ExtendsDeepOptions } from './type';

export type MapOfOptions<K, V> = TypeOptions<Map<K, V>>;
Expand All @@ -20,7 +21,12 @@ export class MapOfType<K, V> extends Type<Map<K, V>> {

constructor(keyType: Type<K>, valueType: Type<V>, options: MapOfOptions<K, V> = {}) {
const defaultValue = options.defaultValue;
const schema = internals.map().entries(keyType.getSchema(), valueType.getSchema());
const schema = internals
.map()
.entries(keyType.getSchema(), valueType.getSchema())
.meta({
[META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES]: () => valueType.getSchema(),
});

super(schema, {
...options,
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-config-schema/src/types/maybe_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '../..';
import { META_FIELD_X_OAS_OPTIONAL } from '../oas_meta_fields';

test('returns value if specified', () => {
const type = schema.maybe(schema.string());
Expand Down Expand Up @@ -96,6 +97,12 @@ describe('maybe + object', () => {
});
});

test('meta', () => {
const maybeString = schema.maybe(schema.string());
const result = maybeString.getSchema().describe().metas[0];
expect(result).toEqual({ [META_FIELD_X_OAS_OPTIONAL]: true });
});

describe('#extendsDeep', () => {
const type = schema.maybe(schema.object({ foo: schema.string() }));

Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-config-schema/src/types/maybe_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Type, ExtendsDeepOptions } from './type';

import { META_FIELD_X_OAS_OPTIONAL } from '../oas_meta_fields';
export class MaybeType<V> extends Type<V | undefined> {
private readonly maybeType: Type<V>;

Expand All @@ -16,6 +17,7 @@ export class MaybeType<V> extends Type<V | undefined> {
type
.getSchema()
.optional()
.meta({ [META_FIELD_X_OAS_OPTIONAL]: true })
.default(() => undefined)
);
this.maybeType = type;
Expand Down
12 changes: 12 additions & 0 deletions packages/kbn-config-schema/src/types/record_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '../..';
import { META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES } from '../oas_meta_fields';

test('handles object as input', () => {
const type = schema.recordOf(schema.string(), schema.string());
Expand Down Expand Up @@ -208,3 +209,14 @@ describe('#extendsDeep', () => {
).toThrowErrorMatchingInlineSnapshot(`"[key.bar]: definition for this key is missing"`);
});
});

test('meta', () => {
const stringSchema = schema.string();
const type = schema.mapOf(schema.string(), stringSchema);
const result = type
.getSchema()
.describe()
.metas![0][META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES]();

expect(result).toBe(stringSchema.getSchema());
});
8 changes: 7 additions & 1 deletion packages/kbn-config-schema/src/types/record_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import typeDetect from 'type-detect';
import { SchemaTypeError, SchemaTypesError } from '../errors';
import { internals } from '../internals';
import { Type, TypeOptions, ExtendsDeepOptions } from './type';
import { META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES } from '../oas_meta_fields';

export type RecordOfOptions<K extends string, V> = TypeOptions<Record<K, V>>;

Expand All @@ -19,7 +20,12 @@ export class RecordOfType<K extends string, V> extends Type<Record<K, V>> {
private readonly options: RecordOfOptions<K, V>;

constructor(keyType: Type<K>, valueType: Type<V>, options: RecordOfOptions<K, V> = {}) {
const schema = internals.record().entries(keyType.getSchema(), valueType.getSchema());
const schema = internals
.record()
.entries(keyType.getSchema(), valueType.getSchema())
.meta({
[META_FIELD_X_OAS_GET_ADDITIONAL_PROPERTIES]: () => valueType.getSchema(),
});

super(schema, options);
this.keyType = keyType;
Expand Down
12 changes: 12 additions & 0 deletions packages/kbn-config-schema/src/types/string_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '../..';
import { META_FIELD_X_OAS_MAX_LENGTH, META_FIELD_X_OAS_MIN_LENGTH } from '../oas_meta_fields';

test('returns value is string and defined', () => {
expect(schema.string().validate('test')).toBe('test');
Expand Down Expand Up @@ -166,6 +167,17 @@ describe('#defaultValue', () => {
});
});

test('meta', () => {
const string = schema.string({ minLength: 1, maxLength: 3 });
const [meta1, meta2] = string.getSchema().describe().metas;
expect(meta1).toEqual({
[META_FIELD_X_OAS_MIN_LENGTH]: 1,
});
expect(meta2).toEqual({
[META_FIELD_X_OAS_MAX_LENGTH]: 3,
});
});

describe('#validate', () => {
test('is called with input value', () => {
let calledWith;
Expand Down
35 changes: 21 additions & 14 deletions packages/kbn-config-schema/src/types/string_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import typeDetect from 'type-detect';
import { internals } from '../internals';
import { Type, TypeOptions, convertValidationFunction } from './type';

import { META_FIELD_X_OAS_MIN_LENGTH, META_FIELD_X_OAS_MAX_LENGTH } from '../oas_meta_fields';

export type StringOptions = TypeOptions<string> & {
minLength?: number;
maxLength?: number;
Expand Down Expand Up @@ -37,24 +39,29 @@ export class StringType extends Type<string> {
}
return value;
});

if (options.minLength !== undefined) {
schema = schema.custom(
convertValidationFunction((value) => {
if (value.length < options.minLength!) {
return `value has length [${value.length}] but it must have a minimum length of [${options.minLength}].`;
}
})
);
schema = schema
.custom(
convertValidationFunction((value) => {
if (value.length < options.minLength!) {
return `value has length [${value.length}] but it must have a minimum length of [${options.minLength}].`;
}
})
)
.meta({ [META_FIELD_X_OAS_MIN_LENGTH]: options.minLength });
}

if (options.maxLength !== undefined) {
schema = schema.custom(
convertValidationFunction((value) => {
if (value.length > options.maxLength!) {
return `value has length [${value.length}] but it must have a maximum length of [${options.maxLength}].`;
}
})
);
schema = schema
.custom(
convertValidationFunction((value) => {
if (value.length > options.maxLength!) {
return `value has length [${value.length}] but it must have a maximum length of [${options.maxLength}].`;
}
})
)
.meta({ [META_FIELD_X_OAS_MAX_LENGTH]: options.maxLength });
}

schema.type = 'string';
Expand Down
23 changes: 23 additions & 0 deletions packages/kbn-config-schema/src/types/type.test.ts
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 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 { get } from 'lodash';
import { internals } from '../internals';
import { Type, TypeOptions } from './type';

class MyType extends Type<any> {
constructor(opts: TypeOptions<any> = {}) {
super(internals.any(), opts);
}
}

test('describe', () => {
const type = new MyType({ description: 'my description' });
const meta = type.getSchema().describe();
expect(get(meta, 'flags.description')).toBe('my description');
});
6 changes: 6 additions & 0 deletions packages/kbn-config-schema/src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Reference } from '../references';
export interface TypeOptions<T> {
defaultValue?: T | Reference<T> | (() => T);
validate?: (value: T) => string | void;
/** A human-friendly description of this type to be used in documentation */
description?: string;
}

export interface SchemaStructureEntry {
Expand Down Expand Up @@ -86,6 +88,10 @@ export abstract class Type<V> {
schema = schema.custom(convertValidationFunction(options.validate));
}

if (options.description) {
schema = schema.description(options.description);
}

// Attach generic error handler only if it hasn't been attached yet since
// only the last error handler is counted.
if (schema.$_getFlag('error') === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { DiscoverHistogramLayout } from './discover_histogram_layout';
import { ErrorCallout } from '../../../../components/common/error_callout';
import { addLog } from '../../../../utils/add_log';
import { DiscoverResizableLayout } from './discover_resizable_layout';
import { ESQLTechPreviewCallout } from './esql_tech_preview_callout';
import { PanelsToggle, PanelsToggleProps } from '../../../../components/panels_toggle';
import { sendErrorMsg } from '../../hooks/use_saved_search_messages';

Expand All @@ -72,7 +71,6 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) {
filterManager,
history,
spaces,
docLinks,
} = useDiscoverServices();
const pageBackgroundColor = useEuiBackgroundColor('plain');
const globalQueryState = data.query.getState();
Expand Down Expand Up @@ -219,8 +217,6 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) {

return (
<>
{/* Temporarily display a tech preview callout for ES|QL*/}
{isPlainRecord && <ESQLTechPreviewCallout docLinks={docLinks} />}
<DiscoverHistogramLayout
isPlainRecord={isPlainRecord}
dataView={dataView}
Expand All @@ -239,7 +235,6 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) {
}, [
currentColumns,
dataView,
docLinks,
isPlainRecord,
mainContainer,
onAddFilter,
Expand Down

This file was deleted.

Loading

0 comments on commit 5816065

Please sign in to comment.