Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AJV): Add Rest api logs definition #8309

Merged
merged 4 commits into from Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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' },
fredericbarthelet marked this conversation as resolved.
Show resolved Hide resolved
},
oneOf: [
{ required: [] },
{ required: ['role'] },
{ required: ['roleManagedExternally'] },
],
additionalProperties: false,
},
websocket: {
oneOf: [
{ type: 'boolean' },
Expand Down