[Config Service] Expose serverless contextRef (#156837)

This commit is contained in:
Alejandro Fernández Haro 2023-05-08 17:39:12 +02:00 committed by GitHub
parent 1506cb2aef
commit ff6943376d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 207 additions and 9 deletions

View file

@ -147,3 +147,64 @@ export const config: PluginConfigDescriptor<ConfigType> = {
],
};
----
[[validating-your-configuration-based-on-context-references]]
=== Validating your configuration based on context references
Some features require special configuration when running in different modes (dev/prod/dist, or even serverless). For purpose, core injects the following _references_ in the validation's context:
[cols="^1,^1,3"]
|===
|Context Reference |Potential values |Description
|`dev`
|`true`\|`false`
|Is Kibana running in Dev mode?
|`prod`
|`true`\|`false`
|Is Kibana running in Production mode (running from binary)?
|`dist`
|`true`\|`false`
|Is Kibana running from a distributable build (not running from source)?
|`serverless`
|`true`\|`false`
|Is Kibana running in Serverless offering?
|`version`
|`8.9.0`
|The current version of Kibana
|`buildNum`
|`12345`
|The build number
|`branch`
|`main`
|The current branch running
|`buildSha`
|`12345`
|The build SHA (typically refers to the last commit's SHA)
|===
To use any of the references listed above in a config validation schema, they can be accessed via `schema.contextRef('{CONTEXT_REFERENCE}')`:
[source,js]
----
export const config = {
schema: schema.object({
// Enabled by default in Dev mode
enabled: schema.boolean({ defaultValue: schema.contextRef('dev') }),
// Setting only allowed in the Serverless offering
plansForWorldPeace: schema.conditional(
schema.contextRef('serverless'),
true,
schema.string({ defaultValue: 'Free hugs' }),
schema.never()
),
}),
};
----