Merge pull request #7034 from serverless/limit-sdk-updates-to-local-apigw

Do not apply APIGW wide settings on externally referenced APIGW
This commit is contained in:
Mariusz Nowak 2019-12-03 14:02:22 +01:00 committed by GitHub
commit cd76e7eb8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 15 deletions

View File

@ -4,7 +4,6 @@ const _ = require('lodash');
const BbPromise = require('bluebird');
const ServerlessError = require('../../../../../../../../classes/Error').ServerlessError;
const isRestApiId = RegExp.prototype.test.bind(/^[a-z0-9]{3,}$/);
const defaultApiGatewayLogFormat = [
'requestId: $context.requestId',
'ip: $context.identity.sourceIp',
@ -52,6 +51,8 @@ module.exports = {
.call(this)
.then(resolveRestApiId.bind(this))
.then(() => {
// Do not update APIGW-wide settings, in case external APIGW is referenced
if (this.isExternalRestApi) return null;
if (!this.apiGatewayRestApiId) {
// Could not resolve REST API id automatically
@ -110,7 +111,8 @@ function resolveRestApiId() {
const provider = this.state.service.provider;
const externalRestApiId = provider.apiGateway && provider.apiGateway.restApiId;
if (externalRestApiId) {
resolve(isRestApiId(externalRestApiId) ? externalRestApiId : null);
this.isExternalRestApi = true;
resolve(null);
return;
}
const apiGatewayResource = resolveApiGatewayResource(

View File

@ -438,21 +438,12 @@ describe('#updateStage()', () => {
});
});
it('should resolve custom restApiId', () => {
context.state.service.provider.tracing = { apiGateway: false };
providerRequestStub
.withArgs('APIGateway', 'getStage', {
restApiId: 'foobarfoo1',
stageName: 'dev',
})
.resolves({
variables: {
old: 'tag',
},
});
it('should ignore external api gateway', () => {
context.state.service.provider.apiGateway = { restApiId: 'foobarfoo1' };
context.state.service.provider.tracing = { apiGateway: false };
return updateStage.call(context).then(() => {
expect(context.apiGatewayRestApiId).to.equal('foobarfoo1');
expect(context.isExternalRestApi).to.equal(true);
expect(context.apiGatewayRestApiId).to.equal(null);
});
});