Skip to content

Commit

Permalink
add unknowns: ignore for serverless config
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 13, 2023
1 parent 317aa2c commit 44efdcc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 23 additions & 0 deletions x-pack/plugins/cloud/server/config.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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { config } from './config';

describe('Cloud plugin config', () => {
it('evicts unknown properties under the `serverless` structure', () => {
const output = config.schema.validate({
serverless: {
project_id: 'project_id',
unknown_prop: 'some unknown prop',
},
});

expect(output.serverless).toEqual({
project_id: 'project_id',
});
});
});
12 changes: 8 additions & 4 deletions x-pack/plugins/cloud/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ const configSchema = schema.object({
trial_end_date: schema.maybe(schema.string()),
is_elastic_staff_owned: schema.maybe(schema.boolean()),
serverless: schema.maybe(
schema.object({
project_id: schema.string(),
project_name: schema.maybe(schema.string()),
})
schema.object(
{
project_id: schema.string(),
project_name: schema.maybe(schema.string()),
},
// avoid future chicken-and-egg situation with the component populating the config
{ unknowns: 'ignore' }
)
),
});

Expand Down

0 comments on commit 44efdcc

Please sign in to comment.