File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
cdk/src/main/java/airhacks/apigateway/control Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ package airhacks .apigateway .control ;
2
+
3
+ import java .util .List ;
4
+ import java .util .Map ;
5
+
6
+ import software .amazon .awscdk .services .ec2 .IVpc ;
7
+ import software .amazon .awscdk .services .iam .AnyPrincipal ;
8
+ import software .amazon .awscdk .services .iam .Effect ;
9
+ import software .amazon .awscdk .services .iam .PolicyDocument ;
10
+ import software .amazon .awscdk .services .iam .PolicyStatement ;
11
+
12
+ public interface IAMPolicy {
13
+
14
+ static PolicyDocument restAPI (IVpc vpc ){
15
+ return PolicyDocument .Builder
16
+ .create ()
17
+ .statements (List .of (allowStatement (),denyNotFrom (vpc .getVpcId ())))
18
+ .build ();
19
+
20
+ }
21
+
22
+ static PolicyStatement allowStatement () {
23
+ return PolicyStatement .Builder .create ()
24
+ .effect (Effect .ALLOW )
25
+ .principals (List .of (new AnyPrincipal ()))
26
+ .actions (List .of ("execute-api:Invoke" ))
27
+ .resources (List .of ("execute-api:/*" ))
28
+ .build ();
29
+ }
30
+
31
+ static PolicyStatement denyNotFrom (String vpcId ) {
32
+ return PolicyStatement .Builder
33
+ .create ()
34
+ .effect (Effect .DENY )
35
+ .principals (List .of (new AnyPrincipal ()))
36
+ .actions (List .of ("execute-api:Invoke" ))
37
+ .resources (List .of ("execute-api:/*" ))
38
+ .conditions (Map .of ("StringNotEquals" ,
39
+ Map .of ("aws:SourceVpc" , vpcId )))
40
+ .build ();
41
+ }
42
+
43
+ }
You can’t perform that action at this time.
0 commit comments