From 4a1607c73770387fc3174b9cf59588fbb787d983 Mon Sep 17 00:00:00 2001 From: Josh Dover <1813008+joshdover@users.noreply.github.com> Date: Wed, 16 Jun 2021 17:09:40 +0200 Subject: [PATCH 1/2] Add xpack.cloud.full_story configuration --- x-pack/plugins/cloud/server/config.test.ts | 37 ++++++++++++++++++++++ x-pack/plugins/cloud/server/config.ts | 12 +++++++ 2 files changed, 49 insertions(+) create mode 100644 x-pack/plugins/cloud/server/config.test.ts diff --git a/x-pack/plugins/cloud/server/config.test.ts b/x-pack/plugins/cloud/server/config.test.ts new file mode 100644 index 00000000000000..446075da4a40cc --- /dev/null +++ b/x-pack/plugins/cloud/server/config.test.ts @@ -0,0 +1,37 @@ +/* + * 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 { config } from './config'; + +describe('xpack.cloud config', () => { + describe('full_story', () => { + it('allows orgId when enabled: false', () => { + expect(() => + config.schema.validate({ full_story: { enabled: false, orgId: 'asdf' } }) + ).not.toThrow(); + }); + + it('rejects undefined or empty orgId when enabled: true', () => { + expect(() => + config.schema.validate({ full_story: { enabled: true } }) + ).toThrowErrorMatchingInlineSnapshot( + `"[full_story.orgId]: expected value of type [string] but got [undefined]"` + ); + expect(() => + config.schema.validate({ full_story: { enabled: true, orgId: '' } }) + ).toThrowErrorMatchingInlineSnapshot( + `"[full_story.orgId]: value has length [0] but it must have a minimum length of [1]."` + ); + }); + + it('accepts orgId when enabled: true', () => { + expect(() => + config.schema.validate({ full_story: { enabled: true, orgId: 'asdf' } }) + ).not.toThrow(); + }); + }); +}); diff --git a/x-pack/plugins/cloud/server/config.ts b/x-pack/plugins/cloud/server/config.ts index 0e73d596671314..de0cfc2f3411d2 100644 --- a/x-pack/plugins/cloud/server/config.ts +++ b/x-pack/plugins/cloud/server/config.ts @@ -18,6 +18,16 @@ const apmConfigSchema = schema.object({ ), }); +const fullStoryConfigSchema = schema.object({ + enabled: schema.boolean({ defaultValue: false }), + orgId: schema.conditional( + schema.siblingRef('enabled'), + true, + schema.string({ minLength: 1 }), + schema.maybe(schema.string()) + ), +}); + const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), id: schema.maybe(schema.string()), @@ -27,6 +37,7 @@ const configSchema = schema.object({ profile_url: schema.maybe(schema.string()), deployment_url: schema.maybe(schema.string()), organization_url: schema.maybe(schema.string()), + full_story: fullStoryConfigSchema, }); export type CloudConfigType = TypeOf; @@ -39,6 +50,7 @@ export const config: PluginConfigDescriptor = { profile_url: true, deployment_url: true, organization_url: true, + full_story: true, }, schema: configSchema, }; From ef8a12c94f12722a2e6e245ae1f38e113bd7d9a8 Mon Sep 17 00:00:00 2001 From: Josh Dover <1813008+joshdover@users.noreply.github.com> Date: Thu, 17 Jun 2021 14:20:21 +0200 Subject: [PATCH 2/2] Use snake_case org_id --- x-pack/plugins/cloud/server/config.test.ts | 10 +++++----- x-pack/plugins/cloud/server/config.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/cloud/server/config.test.ts b/x-pack/plugins/cloud/server/config.test.ts index 446075da4a40cc..7cd3b712234237 100644 --- a/x-pack/plugins/cloud/server/config.test.ts +++ b/x-pack/plugins/cloud/server/config.test.ts @@ -11,7 +11,7 @@ describe('xpack.cloud config', () => { describe('full_story', () => { it('allows orgId when enabled: false', () => { expect(() => - config.schema.validate({ full_story: { enabled: false, orgId: 'asdf' } }) + config.schema.validate({ full_story: { enabled: false, org_id: 'asdf' } }) ).not.toThrow(); }); @@ -19,18 +19,18 @@ describe('xpack.cloud config', () => { expect(() => config.schema.validate({ full_story: { enabled: true } }) ).toThrowErrorMatchingInlineSnapshot( - `"[full_story.orgId]: expected value of type [string] but got [undefined]"` + `"[full_story.org_id]: expected value of type [string] but got [undefined]"` ); expect(() => - config.schema.validate({ full_story: { enabled: true, orgId: '' } }) + config.schema.validate({ full_story: { enabled: true, org_id: '' } }) ).toThrowErrorMatchingInlineSnapshot( - `"[full_story.orgId]: value has length [0] but it must have a minimum length of [1]."` + `"[full_story.org_id]: value has length [0] but it must have a minimum length of [1]."` ); }); it('accepts orgId when enabled: true', () => { expect(() => - config.schema.validate({ full_story: { enabled: true, orgId: 'asdf' } }) + config.schema.validate({ full_story: { enabled: true, org_id: 'asdf' } }) ).not.toThrow(); }); }); diff --git a/x-pack/plugins/cloud/server/config.ts b/x-pack/plugins/cloud/server/config.ts index de0cfc2f3411d2..4b83071bf473ab 100644 --- a/x-pack/plugins/cloud/server/config.ts +++ b/x-pack/plugins/cloud/server/config.ts @@ -20,7 +20,7 @@ const apmConfigSchema = schema.object({ const fullStoryConfigSchema = schema.object({ enabled: schema.boolean({ defaultValue: false }), - orgId: schema.conditional( + org_id: schema.conditional( schema.siblingRef('enabled'), true, schema.string({ minLength: 1 }),