From dd9a011f6073d33db9043f102e0cce84743a8a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barthelet?= Date: Wed, 30 Sep 2020 18:55:08 +0200 Subject: [PATCH] feat(Config Schema): Schema for `provider.logs.restApi` (#8309) --- .../events/apiGateway/lib/hack/updateStage.js | 9 --------- .../apiGateway/lib/hack/updateStage.test.js | 18 ++---------------- lib/plugins/aws/provider/awsProvider.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js index 862693ab0bd..0ca5917f79b 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js @@ -17,7 +17,6 @@ const defaultApiGatewayLogFormat = [ 'responseLength: $context.responseLength', ].join(', '); const defaultApiGatewayLogLevel = 'INFO'; -const apiGatewayValidLogLevels = new Set(['INFO', 'ERROR']); // NOTE --> Keep this file in sync with ../stage.js @@ -26,7 +25,6 @@ const apiGatewayValidLogLevels = new Set(['INFO', 'ERROR']); module.exports = { defaultApiGatewayLogLevel, - apiGatewayValidLogLevels, updateStage() { return BbPromise.try(() => { const provider = this.state.service.provider; @@ -277,13 +275,6 @@ function handleLogs() { level = 'OFF'; } else if (logs.level) { level = logs.level; - if (!apiGatewayValidLogLevels.has(level)) { - throw new ServerlessError( - `provider.logs.restApi.level is set to an invalid value. Support values are ${Array.from( - apiGatewayValidLogLevels - ).join(', ')}, got ${level}.` - ); - } } const accessLogging = logs.accessLogging == null ? true : logs.accessLogging; diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js index c28cd71eaca..85a2864d46e 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js @@ -8,11 +8,7 @@ const sinon = require('sinon'); const _ = require('lodash'); const Serverless = require('../../../../../../../../Serverless'); const AwsProvider = require('../../../../../../provider/awsProvider'); -const { - updateStage, - apiGatewayValidLogLevels, - defaultApiGatewayLogLevel, -} = require('./updateStage'); +const { updateStage, defaultApiGatewayLogLevel } = require('./updateStage'); chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); @@ -677,7 +673,7 @@ describe('#updateStage()', () => { return checkLogLevel(null, defaultApiGatewayLogLevel); }); - apiGatewayValidLogLevels.forEach(logLevel => { + ['INFO', 'ERROR'].forEach(logLevel => { it(`should update the stage with a custom APIGW log level if given ${logLevel}`, () => { return checkLogLevel(logLevel, logLevel); }); @@ -695,16 +691,6 @@ describe('#updateStage()', () => { }); }); - it('should reject a custom APIGW log level if value is invalid', () => { - context.state.service.provider.logs = { - restApi: { - level: 'INVALID', - }, - }; - - return expect(updateStage.call(context)).to.be.rejectedWith('invalid value'); - }); - it('should disable existing access log settings when accessLogging is set to false', () => { context.state.service.provider.logs = { restApi: { diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js index f4eb5921d06..73148fe2e15 100644 --- a/lib/plugins/aws/provider/awsProvider.js +++ b/lib/plugins/aws/provider/awsProvider.js @@ -465,6 +465,24 @@ class AwsProvider { }, ], }, + restApi: { + type: 'object', + properties: { + accessLogging: { type: 'boolean' }, + executionLogging: { type: 'boolean' }, + format: { type: 'string' }, + fullExecutionData: { type: 'boolean' }, + level: { enum: ['INFO', 'ERROR'] }, + role: { $ref: '#/definitions/awsArn' }, + roleManagedExternally: { type: 'boolean' }, + }, + oneOf: [ + { required: [] }, + { required: ['role'] }, + { required: ['roleManagedExternally'] }, + ], + additionalProperties: false, + }, websocket: { oneOf: [ { type: 'boolean' },