Skip to content

Commit 6c3203f

Browse files
authored
Merge branch 'master' into merge-back/1.146.0
2 parents c0164a7 + 4a44a65 commit 6c3203f

17 files changed

+144
-31
lines changed

packages/@aws-cdk-containers/ecs-service-extensions/test/integ.assign-public-ip.expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,8 @@
766766
"dynamodb:BatchWriteItem",
767767
"dynamodb:PutItem",
768768
"dynamodb:UpdateItem",
769-
"dynamodb:DeleteItem"
769+
"dynamodb:DeleteItem",
770+
"dynamodb:DescribeTable"
770771
],
771772
"Effect": "Allow",
772773
"Resource": [

packages/@aws-cdk/aws-apigateway/lib/resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ export abstract class ResourceBase extends ResourceConstruct implements IResourc
311311

312312
const template = new Array<string>();
313313

314-
template.push('#set($origin = $input.params("Origin"))');
315-
template.push('#if($origin == "") #set($origin = $input.params("origin")) #end');
314+
template.push('#set($origin = $input.params().header.get("Origin"))');
315+
template.push('#if($origin == "") #set($origin = $input.params().header.get("origin")) #end');
316316

317317
const condition = origins.map(o => `$origin.matches("${o}")`).join(' || ');
318318

packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CfnUsagePlan, CfnUsagePlanKey } from './apigateway.generated';
66
import { Method } from './method';
77
import { IRestApi } from './restapi';
88
import { Stage } from './stage';
9-
import { validateInteger } from './util';
9+
import { validateDouble, validateInteger } from './util';
1010

1111
/**
1212
* Container for defining throttling parameters to API stages or methods.
@@ -316,7 +316,7 @@ export class UsagePlan extends UsagePlanBase {
316316
const burstLimit = props.burstLimit;
317317
validateInteger(burstLimit, 'Throttle burst limit');
318318
const rateLimit = props.rateLimit;
319-
validateInteger(rateLimit, 'Throttle rate limit');
319+
validateDouble(rateLimit, 'Throttle rate limit');
320320

321321
ret = {
322322
burstLimit: burstLimit,

packages/@aws-cdk/aws-apigateway/lib/util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export function validateInteger(property: number | undefined, messagePrefix: str
7878
}
7979
}
8080

81+
export function validateDouble(property: number | undefined, messagePrefix: string) {
82+
if (property && isNaN(property) && isNaN(parseFloat(property.toString()))) {
83+
throw new Error(`${messagePrefix} should be an double`);
84+
}
85+
}
86+
8187
export class JsonSchemaMapper {
8288
/**
8389
* Transforms naming of some properties to prefix with a $, where needed

packages/@aws-cdk/aws-apigateway/test/cors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('cors', () => {
290290
'method.response.header.Access-Control-Allow-Methods': "'OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD'",
291291
},
292292
ResponseTemplates: {
293-
'application/json': '#set($origin = $input.params("Origin"))\n#if($origin == "") #set($origin = $input.params("origin")) #end\n#if($origin.matches("https://amazon.com") || $origin.matches("https://aws.amazon.com"))\n #set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)\n#end',
293+
'application/json': '#set($origin = $input.params().header.get("Origin"))\n#if($origin == "") #set($origin = $input.params().header.get("origin")) #end\n#if($origin.matches("https://amazon.com") || $origin.matches("https://aws.amazon.com"))\n #set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)\n#end',
294294
},
295295
StatusCode: '204',
296296
},

packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"corsapitest8682546E"
5252
]
5353
},
54-
"corsapitestDeployment2BF1633A228079ea05e5799220dd4ca13512b92d": {
54+
"corsapitestDeployment2BF1633A51392cbce1ac2785bd0e53063423e203": {
5555
"Type": "AWS::ApiGateway::Deployment",
5656
"Properties": {
5757
"RestApiId": {
@@ -74,7 +74,7 @@
7474
"Ref": "corsapitest8682546E"
7575
},
7676
"DeploymentId": {
77-
"Ref": "corsapitestDeployment2BF1633A228079ea05e5799220dd4ca13512b92d"
77+
"Ref": "corsapitestDeployment2BF1633A51392cbce1ac2785bd0e53063423e203"
7878
},
7979
"StageName": "prod"
8080
},
@@ -472,7 +472,7 @@
472472
"method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD'"
473473
},
474474
"ResponseTemplates": {
475-
"application/json": "#set($origin = $input.params(\"Origin\"))\n#if($origin == \"\") #set($origin = $input.params(\"origin\")) #end\n#if($origin.matches(\"https://www.test-cors.org\"))\n #set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)\n#end"
475+
"application/json": "#set($origin = $input.params().header.get(\"Origin\"))\n#if($origin == \"\") #set($origin = $input.params().header.get(\"origin\")) #end\n#if($origin.matches(\"https://www.test-cors.org\"))\n #set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)\n#end"
476476
},
477477
"StatusCode": "204"
478478
}

packages/@aws-cdk/aws-apigateway/test/usage-plan.test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ describe('usage plan', () => {
2727
});
2828
});
2929

30-
test('usage plan with throttling limits', () => {
30+
test('usage plan with integer throttling limits', () => {
3131
// GIVEN
3232
const stack = new cdk.Stack();
3333
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
3434
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
3535
const usagePlanName = 'Basic';
36-
const usagePlanDescription = 'Basic Usage Plan with throttling limits';
36+
const usagePlanDescription = 'Basic Usage Plan with integer throttling limits';
3737

3838
// WHEN
3939
new apigateway.UsagePlan(stack, 'my-usage-plan', {
@@ -78,6 +78,57 @@ describe('usage plan', () => {
7878
});
7979
});
8080

81+
test('usage plan with integer and float throttling limits', () => {
82+
// GIVEN
83+
const stack = new cdk.Stack();
84+
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
85+
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
86+
const usagePlanName = 'Basic';
87+
const usagePlanDescription = 'Basic Usage Plan with integer and float throttling limits';
88+
89+
// WHEN
90+
new apigateway.UsagePlan(stack, 'my-usage-plan', {
91+
name: usagePlanName,
92+
description: usagePlanDescription,
93+
apiStages: [
94+
{
95+
stage: api.deploymentStage,
96+
throttle: [
97+
{
98+
method,
99+
throttle: {
100+
burstLimit: 20,
101+
rateLimit: 10.5,
102+
},
103+
},
104+
],
105+
},
106+
],
107+
});
108+
109+
// THEN
110+
Template.fromStack(stack).hasResourceProperties(RESOURCE_TYPE, {
111+
UsagePlanName: usagePlanName,
112+
Description: usagePlanDescription,
113+
ApiStages: [
114+
{
115+
ApiId: {
116+
Ref: 'myapi4C7BF186',
117+
},
118+
Stage: {
119+
Ref: 'myapiDeploymentStagetest4A4AB65E',
120+
},
121+
Throttle: {
122+
'//GET': {
123+
BurstLimit: 20,
124+
RateLimit: 10.5,
125+
},
126+
},
127+
},
128+
],
129+
});
130+
});
131+
81132
test('usage plan with blocked methods', () => {
82133
// GIVEN
83134
const stack = new cdk.Stack();

packages/@aws-cdk/aws-appsync/test/integ.api-import.expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"dynamodb:BatchWriteItem",
8686
"dynamodb:PutItem",
8787
"dynamodb:UpdateItem",
88-
"dynamodb:DeleteItem"
88+
"dynamodb:DeleteItem",
89+
"dynamodb:DescribeTable"
8990
],
9091
"Effect": "Allow",
9192
"Resource": [

packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"dynamodb:BatchWriteItem",
6969
"dynamodb:PutItem",
7070
"dynamodb:UpdateItem",
71-
"dynamodb:DeleteItem"
71+
"dynamodb:DeleteItem",
72+
"dynamodb:DescribeTable"
7273
],
7374
"Effect": "Allow",
7475
"Resource": [

packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
"dynamodb:BatchWriteItem",
100100
"dynamodb:PutItem",
101101
"dynamodb:UpdateItem",
102-
"dynamodb:DeleteItem"
102+
"dynamodb:DeleteItem",
103+
"dynamodb:DescribeTable"
103104
],
104105
"Effect": "Allow",
105106
"Resource": [

packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"dynamodb:BatchWriteItem",
6868
"dynamodb:PutItem",
6969
"dynamodb:UpdateItem",
70-
"dynamodb:DeleteItem"
70+
"dynamodb:DeleteItem",
71+
"dynamodb:DescribeTable"
7172
],
7273
"Effect": "Allow",
7374
"Resource": [

packages/@aws-cdk/aws-appsync/test/integ.graphql.expected.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
"dynamodb:BatchWriteItem",
148148
"dynamodb:PutItem",
149149
"dynamodb:UpdateItem",
150-
"dynamodb:DeleteItem"
150+
"dynamodb:DeleteItem",
151+
"dynamodb:DescribeTable"
151152
],
152153
"Effect": "Allow",
153154
"Resource": [
@@ -360,7 +361,8 @@
360361
"dynamodb:BatchWriteItem",
361362
"dynamodb:PutItem",
362363
"dynamodb:UpdateItem",
363-
"dynamodb:DeleteItem"
364+
"dynamodb:DeleteItem",
365+
"dynamodb:DescribeTable"
364366
],
365367
"Effect": "Allow",
366368
"Resource": [
@@ -752,7 +754,8 @@
752754
"dynamodb:BatchWriteItem",
753755
"dynamodb:PutItem",
754756
"dynamodb:UpdateItem",
755-
"dynamodb:DeleteItem"
757+
"dynamodb:DeleteItem",
758+
"dynamodb:DescribeTable"
756759
],
757760
"Effect": "Allow",
758761
"Resource": [

packages/@aws-cdk/aws-dynamodb/lib/perms.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ export const READ_STREAM_DATA_ACTIONS = [
2929
'dynamodb:GetRecords',
3030
'dynamodb:GetShardIterator',
3131
];
32+
33+
export const DESCRIBE_TABLE = 'dynamodb:DescribeTable';

packages/@aws-cdk/aws-dynamodb/lib/table.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,15 +679,16 @@ abstract class TableBase extends Resource implements ITable {
679679

680680
/**
681681
* Permits an IAM principal all data read operations from this table:
682-
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan.
682+
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, DescribeTable.
683683
*
684684
* Appropriate grants will also be added to the customer-managed KMS key
685685
* if one was configured.
686686
*
687687
* @param grantee The principal to grant access to
688688
*/
689689
public grantReadData(grantee: iam.IGrantable): iam.Grant {
690-
return this.combinedGrant(grantee, { keyActions: perms.KEY_READ_ACTIONS, tableActions: perms.READ_DATA_ACTIONS });
690+
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.DESCRIBE_TABLE);
691+
return this.combinedGrant(grantee, { keyActions: perms.KEY_READ_ACTIONS, tableActions });
691692
}
692693

693694
/**
@@ -724,29 +725,31 @@ abstract class TableBase extends Resource implements ITable {
724725

725726
/**
726727
* Permits an IAM principal all data write operations to this table:
727-
* BatchWriteItem, PutItem, UpdateItem, DeleteItem.
728+
* BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable.
728729
*
729730
* Appropriate grants will also be added to the customer-managed KMS key
730731
* if one was configured.
731732
*
732733
* @param grantee The principal to grant access to
733734
*/
734735
public grantWriteData(grantee: iam.IGrantable): iam.Grant {
735-
return this.combinedGrant(grantee, { keyActions: perms.KEY_WRITE_ACTIONS, tableActions: perms.WRITE_DATA_ACTIONS });
736+
const tableActions = perms.WRITE_DATA_ACTIONS.concat(perms.DESCRIBE_TABLE);
737+
const keyActions = perms.KEY_READ_ACTIONS.concat(perms.KEY_WRITE_ACTIONS);
738+
return this.combinedGrant(grantee, { keyActions, tableActions });
736739
}
737740

738741
/**
739742
* Permits an IAM principal to all data read/write operations to this table.
740743
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan,
741-
* BatchWriteItem, PutItem, UpdateItem, DeleteItem
744+
* BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable
742745
*
743746
* Appropriate grants will also be added to the customer-managed KMS key
744747
* if one was configured.
745748
*
746749
* @param grantee The principal to grant access to
747750
*/
748751
public grantReadWriteData(grantee: iam.IGrantable): iam.Grant {
749-
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.WRITE_DATA_ACTIONS);
752+
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.WRITE_DATA_ACTIONS).concat(perms.DESCRIBE_TABLE);
750753
const keyActions = perms.KEY_READ_ACTIONS.concat(perms.KEY_WRITE_ACTIONS);
751754
return this.combinedGrant(grantee, { keyActions, tableActions });
752755
}

0 commit comments

Comments
 (0)