Skip to content

Commit

Permalink
feat(AWS API Gateway): Remove API specific settings from provider
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Support for `usagePlan`, `resourcePolicy` and `apiKeys` on
`provider` level is removed. Use `provider.apiGateway` level instead to set
them.
  • Loading branch information
pgrzesik authored and medikoo committed Jan 27, 2022
1 parent a9edd06 commit 99941f0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 63 deletions.
21 changes: 11 additions & 10 deletions docs/providers/aws/events/apigateway.md
Expand Up @@ -1654,16 +1654,17 @@ provider:
name: aws
runtime: nodejs12.x

resourcePolicy:
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource:
- execute-api:/*/*/*
Condition:
IpAddress:
aws:SourceIp:
- '123.123.123.123'
apiGateway:
resourcePolicy:
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource:
- execute-api:/*/*/*
Condition:
IpAddress:
aws:SourceIp:
- '123.123.123.123'
```

## Compression
Expand Down
14 changes: 0 additions & 14 deletions lib/plugins/aws/package/compile/events/apiGateway/index.js
Expand Up @@ -238,20 +238,6 @@ class AwsCompileApigEvents {

this.hooks = {
'initialize': () => {
if (
this.serverless.service.provider.name === 'aws' &&
(this.serverless.service.provider.apiKeys ||
this.serverless.service.provider.resourcePolicy ||
this.serverless.service.provider.usagePlan)
) {
this.serverless._logDeprecation(
'AWS_API_GATEWAY_SPECIFIC_KEYS',
'Starting with next major version, API Gateway-specific configuration keys ' +
'"apiKeys", "resourcePolicy" and "usagePlan" will be relocated from "provider" ' +
'to "provider.apiGateway"'
);
}

if (
this.serverless.service.provider.name === 'aws' &&
Object.values(this.serverless.service.functions).some(({ events }) =>
Expand Down
Expand Up @@ -32,18 +32,14 @@ function createApiKeyResource(that, apiKey) {

module.exports = {
compileApiKeys() {
const apiKeys =
_.get(this.serverless.service.provider.apiGateway, 'apiKeys') ||
this.serverless.service.provider.apiKeys;
const apiKeys = _.get(this.serverless.service.provider.apiGateway, 'apiKeys');
if (apiKeys) {
const resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
let keyNumber = 0;
apiKeys.forEach((apiKeyDefinition) => {
// if multiple API key types are used
const name = Object.keys(apiKeyDefinition)[0];
const usagePlan =
_.get(this.serverless.service.provider.apiGateway, 'usagePlan') ||
this.serverless.service.provider.usagePlan;
const usagePlan = _.get(this.serverless.service.provider.apiGateway, 'usagePlan');
if (
_.isObject(apiKeyDefinition) &&
Array.isArray(usagePlan) &&
Expand Down
Expand Up @@ -6,9 +6,7 @@ const { legacy, log } = require('@serverless/utils/log');

module.exports = {
async disassociateUsagePlan() {
const apiKeys =
_.get(this.serverless.service.provider.apiGateway, 'apiKeys') ||
this.serverless.service.provider.apiKeys;
const apiKeys = _.get(this.serverless.service.provider.apiGateway, 'apiKeys');

if (apiKeys && apiKeys.length) {
legacy.log('Removing usage plan association...');
Expand Down
Expand Up @@ -59,9 +59,7 @@ module.exports = {
},
});

const resourcePolicy =
_.get(this.serverless.service.provider.apiGateway, 'resourcePolicy') ||
this.serverless.service.provider.resourcePolicy;
const resourcePolicy = _.get(this.serverless.service.provider.apiGateway, 'resourcePolicy');
if (resourcePolicy && Object.keys(resourcePolicy).length) {
const policy = {
Version: '2012-10-17',
Expand Down
Expand Up @@ -20,9 +20,7 @@ function createUsagePlanResource(that, name) {
},
};
const template = _.cloneDeep(resourceTemplate);
const usagePlan =
_.get(that.serverless.service.provider.apiGateway, 'usagePlan') ||
that.serverless.service.provider.usagePlan;
const usagePlan = _.get(that.serverless.service.provider.apiGateway, 'usagePlan');
// this is done for backward compatibility
if (name === 'default') {
// create old legacy resources
Expand Down Expand Up @@ -97,12 +95,8 @@ function createUsagePlanResource(that, name) {

module.exports = {
compileUsagePlan() {
const apiKeys =
_.get(this.serverless.service.provider.apiGateway, 'apiKeys') ||
this.serverless.service.provider.apiKeys;
const usagePlan =
_.get(this.serverless.service.provider.apiGateway, 'usagePlan') ||
this.serverless.service.provider.usagePlan;
const apiKeys = _.get(this.serverless.service.provider.apiGateway, 'apiKeys');
const usagePlan = _.get(this.serverless.service.provider.apiGateway, 'usagePlan');
if (usagePlan || apiKeys) {
const resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
this.apiGatewayUsagePlanNames = [];
Expand Down
Expand Up @@ -24,9 +24,7 @@ function createUsagePlanKeyResource(that, usagePlanLogicalId, keyNumber, keyName

module.exports = {
compileUsagePlanKeys() {
const apiKeys =
_.get(this.serverless.service.provider.apiGateway, 'apiKeys') ||
this.serverless.service.provider.apiKeys;
const apiKeys = _.get(this.serverless.service.provider.apiGateway, 'apiKeys');
if (apiKeys) {
const resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
let keyNumber = 0;
Expand Down
15 changes: 0 additions & 15 deletions lib/plugins/aws/provider.js
Expand Up @@ -759,7 +759,6 @@ class AwsProvider {
},
additionalProperties: false,
},
apiKeys: { $ref: '#/definitions/awsApiGatewayApiKeys' },
apiName: { type: 'string' },
architecture: { $ref: '#/definitions/awsLambdaArchitecture' },
cfnRole: { $ref: '#/definitions/awsArn' },
Expand Down Expand Up @@ -1112,7 +1111,6 @@ class AwsProvider {
'sa-east-1',
],
},
resourcePolicy: { $ref: '#/definitions/awsResourcePolicyStatements' },
role: { $ref: '#/definitions/awsLambdaRole' },
rolePermissionsBoundary: { $ref: '#/definitions/awsArnString' },
rollbackConfiguration: {
Expand Down Expand Up @@ -1170,19 +1168,6 @@ class AwsProvider {
},
additionalProperties: false,
},
usagePlan: {
anyOf: [
apiGatewayUsagePlan,
{
type: 'array',
items: {
type: 'object',
additionalProperties: apiGatewayUsagePlan,
maxProperties: 1,
},
},
],
},
vpc: { $ref: '#/definitions/awsLambdaVpcConfig' },
vpcEndpointIds: { $ref: '#/definitions/awsCfArrayInstruction' },
versionFunctions: { $ref: '#/definitions/awsLambdaVersioning' },
Expand Down

0 comments on commit 99941f0

Please sign in to comment.