Skip to content

Commit

Permalink
feat(Config Schema): Schema for provider.logs.restApi (#8309)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Sep 30, 2020
1 parent 8293cc4 commit dd9a011
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Expand Up @@ -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

Expand All @@ -26,7 +25,6 @@ const apiGatewayValidLogLevels = new Set(['INFO', 'ERROR']);

module.exports = {
defaultApiGatewayLogLevel,
apiGatewayValidLogLevels,
updateStage() {
return BbPromise.try(() => {
const provider = this.state.service.provider;
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
});
Expand All @@ -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: {
Expand Down
18 changes: 18 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Expand Up @@ -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' },
Expand Down

0 comments on commit dd9a011

Please sign in to comment.