Skip to content

Commit ecb59fd

Browse files
authored
feat(apigateway): add grantExecute to API Methods (#25630)
To grant permission to a user: ```ts const books = api.root.addResource('books'); books.grantExecute(user); ``` Closes #5198. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0643020 commit ecb59fd

File tree

12 files changed

+863
-0
lines changed

12 files changed

+863
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "31.0.0",
3+
"files": {
4+
"454874b4674a38a5eb7ede0bc79fe77dcbf5062acaeb3b4424c7919758ae5191": {
5+
"source": {
6+
"path": "GrantExecute.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "454874b4674a38a5eb7ede0bc79fe77dcbf5062acaeb3b4424c7919758ae5191.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"Resources": {
3+
"user2C2B57AE": {
4+
"Type": "AWS::IAM::User"
5+
},
6+
"userDefaultPolicy083DF682": {
7+
"Type": "AWS::IAM::Policy",
8+
"Properties": {
9+
"PolicyDocument": {
10+
"Statement": [
11+
{
12+
"Action": "execute-api:Invoke",
13+
"Effect": "Allow",
14+
"Resource": {
15+
"Fn::Join": [
16+
"",
17+
[
18+
"arn:",
19+
{
20+
"Ref": "AWS::Partition"
21+
},
22+
":execute-api:",
23+
{
24+
"Ref": "AWS::Region"
25+
},
26+
":",
27+
{
28+
"Ref": "AWS::AccountId"
29+
},
30+
":",
31+
{
32+
"Ref": "testapiD6451F70"
33+
},
34+
"/",
35+
{
36+
"Ref": "testapiDeploymentStageprod5C9E92A4"
37+
},
38+
"/GET/pets"
39+
]
40+
]
41+
}
42+
}
43+
],
44+
"Version": "2012-10-17"
45+
},
46+
"PolicyName": "userDefaultPolicy083DF682",
47+
"Users": [
48+
{
49+
"Ref": "user2C2B57AE"
50+
}
51+
]
52+
}
53+
},
54+
"testapiD6451F70": {
55+
"Type": "AWS::ApiGateway::RestApi",
56+
"Properties": {
57+
"Name": "test-api"
58+
}
59+
},
60+
"testapiDeployment356D2C358af14d7f8fefbad1c57a65ea01cc6136": {
61+
"Type": "AWS::ApiGateway::Deployment",
62+
"Properties": {
63+
"RestApiId": {
64+
"Ref": "testapiD6451F70"
65+
},
66+
"Description": "Automatically created by the RestApi construct"
67+
},
68+
"DependsOn": [
69+
"testapipetsGET25A78130",
70+
"testapipets981F319E"
71+
]
72+
},
73+
"testapiDeploymentStageprod5C9E92A4": {
74+
"Type": "AWS::ApiGateway::Stage",
75+
"Properties": {
76+
"RestApiId": {
77+
"Ref": "testapiD6451F70"
78+
},
79+
"DeploymentId": {
80+
"Ref": "testapiDeployment356D2C358af14d7f8fefbad1c57a65ea01cc6136"
81+
},
82+
"StageName": "prod"
83+
}
84+
},
85+
"testapipets981F319E": {
86+
"Type": "AWS::ApiGateway::Resource",
87+
"Properties": {
88+
"ParentId": {
89+
"Fn::GetAtt": [
90+
"testapiD6451F70",
91+
"RootResourceId"
92+
]
93+
},
94+
"PathPart": "pets",
95+
"RestApiId": {
96+
"Ref": "testapiD6451F70"
97+
}
98+
}
99+
},
100+
"testapipetsGET25A78130": {
101+
"Type": "AWS::ApiGateway::Method",
102+
"Properties": {
103+
"HttpMethod": "GET",
104+
"ResourceId": {
105+
"Ref": "testapipets981F319E"
106+
},
107+
"RestApiId": {
108+
"Ref": "testapiD6451F70"
109+
},
110+
"AuthorizationType": "NONE",
111+
"Integration": {
112+
"Type": "MOCK"
113+
}
114+
}
115+
}
116+
},
117+
"Outputs": {
118+
"testapiEndpoint4AE34D29": {
119+
"Value": {
120+
"Fn::Join": [
121+
"",
122+
[
123+
"https://",
124+
{
125+
"Ref": "testapiD6451F70"
126+
},
127+
".execute-api.",
128+
{
129+
"Ref": "AWS::Region"
130+
},
131+
".",
132+
{
133+
"Ref": "AWS::URLSuffix"
134+
},
135+
"/",
136+
{
137+
"Ref": "testapiDeploymentStageprod5C9E92A4"
138+
},
139+
"/"
140+
]
141+
]
142+
}
143+
}
144+
},
145+
"Parameters": {
146+
"BootstrapVersion": {
147+
"Type": "AWS::SSM::Parameter::Value<String>",
148+
"Default": "/cdk-bootstrap/hnb659fds/version",
149+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
150+
}
151+
},
152+
"Rules": {
153+
"CheckBootstrapVersion": {
154+
"Assertions": [
155+
{
156+
"Assert": {
157+
"Fn::Not": [
158+
{
159+
"Fn::Contains": [
160+
[
161+
"1",
162+
"2",
163+
"3",
164+
"4",
165+
"5"
166+
],
167+
{
168+
"Ref": "BootstrapVersion"
169+
}
170+
]
171+
}
172+
]
173+
},
174+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
175+
}
176+
]
177+
}
178+
}
179+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "31.0.0",
3+
"files": {
4+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "GrantExecuteTestDefaultTestDeployAssertA66B6F20.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Parameters": {
3+
"BootstrapVersion": {
4+
"Type": "AWS::SSM::Parameter::Value<String>",
5+
"Default": "/cdk-bootstrap/hnb659fds/version",
6+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
7+
}
8+
},
9+
"Rules": {
10+
"CheckBootstrapVersion": {
11+
"Assertions": [
12+
{
13+
"Assert": {
14+
"Fn::Not": [
15+
{
16+
"Fn::Contains": [
17+
[
18+
"1",
19+
"2",
20+
"3",
21+
"4",
22+
"5"
23+
],
24+
{
25+
"Ref": "BootstrapVersion"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"31.0.0"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "31.0.0",
3+
"testCases": {
4+
"GrantExecuteTest/DefaultTest": {
5+
"stacks": [
6+
"GrantExecute"
7+
],
8+
"assertionStack": "GrantExecuteTest/DefaultTest/DeployAssert",
9+
"assertionStackName": "GrantExecuteTestDefaultTestDeployAssertA66B6F20"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)