Skip to content

Commit 8f58edd

Browse files
committed
Extract guard-lang so guard can be used as a library
1 parent 11b2880 commit 8f58edd

56 files changed

Lines changed: 1589 additions & 956 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "2"
33
members = [
44
"guard",
5+
"guard-lang",
56
"guard-lambda",
67
"guard-ffi",
78
"guard-examples/library"

guard-lang/Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "guard-lang"
3+
version = "1.0.0"
4+
edition = "2018"
5+
description = "Parser, AST, and evaluation types for the AWS CloudFormation Guard DSL"
6+
license = "Apache-2.0"
7+
8+
[dependencies]
9+
nom = "7.0.0"
10+
nom_locate = "4.0.0"
11+
indexmap = { version = "1.6.0", features = ["serde-1"] }
12+
serde = { version = "1.0", features = ["derive", "rc"] }
13+
serde_json = { version = "1.0.85", features = ["preserve_order"] }
14+
serde_yaml = "0.9.10"
15+
fancy-regex = "0.13.0"
16+
thiserror = "1.0.38"
17+
lazy_static = "1.4.0"
18+
colored = "2.2.0"
19+
unsafe-libyaml = "0.2.10"
20+
itertools = "0.4.7"
21+
chrono = "0.4.38"
22+
cruet = "0.14.0"
23+
urlencoding = "2.1.0"
24+
wasm-bindgen = "0.2.92"
25+
quick-xml = "0.30.0"
26+
27+
[dev-dependencies]
28+
pretty_assertions = "1.4.0"
29+
rstest = "0.24.0"
30+
indoc = "1.0.8"
31+
grep-searcher = "0.1.8"
32+
grep-matcher = "0.1.5"
33+
grep-regex = "0.1.9"

guard-lang/assets/cfn-lambda.yaml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Parameters:
3+
ExistingSecurityGroups:
4+
Type: List<AWS::EC2::SecurityGroup::Id>
5+
ExistingVPC:
6+
Type: AWS::EC2::VPC::Id
7+
Description: The VPC ID that includes the security groups in the ExistingSecurityGroups
8+
parameter.
9+
InstanceType:
10+
Type: String
11+
Default: t2.micro
12+
AllowedValues:
13+
- t2.micro
14+
- m1.small
15+
Mappings:
16+
AWSInstanceType2Arch:
17+
t2.micro:
18+
Arch: HVM64
19+
m1.small:
20+
Arch: HVM64
21+
22+
AWSRegionArch2AMI:
23+
us-east-1:
24+
HVM64: ami-0ff8a91507f77f867
25+
HVMG2: ami-0a584ac55a7631c0c
26+
us-west-2:
27+
HVM64: ami-a0cfeed8
28+
HVMG2: ami-0e09505bc235aa82d
29+
us-west-1:
30+
HVM64: ami-0bdb828fd58c52235
31+
HVMG2: ami-066ee5fd4a9ef77f1
32+
eu-west-1:
33+
HVM64: ami-047bb4163c506cd98
34+
HVMG2: ami-0a7c483d527806435
35+
eu-central-1:
36+
HVM64: ami-0233214e13e500f77
37+
HVMG2: ami-06223d46a6d0661c7
38+
ap-northeast-1:
39+
HVM64: ami-06cd52961ce9f0d85
40+
HVMG2: ami-053cdd503598e4a9d
41+
ap-southeast-1:
42+
HVM64: ami-08569b978cc4dfa10
43+
HVMG2: ami-0be9df32ae9f92309
44+
ap-southeast-2:
45+
HVM64: ami-09b42976632b27e9b
46+
HVMG2: ami-0a9ce9fecc3d1daf8
47+
sa-east-1:
48+
HVM64: ami-07b14488da8ea02a0
49+
HVMG2: NOT_SUPPORTED
50+
cn-north-1:
51+
HVM64: ami-0a4eaf6c4454eda75
52+
HVMG2: NOT_SUPPORTED
53+
Resources:
54+
SecurityGroup:
55+
Type: AWS::EC2::SecurityGroup
56+
Properties:
57+
GroupDescription: Allow HTTP traffic to the host
58+
VpcId:
59+
Ref: ExistingVPC
60+
SecurityGroupIngress:
61+
- IpProtocol: tcp
62+
FromPort: '80'
63+
ToPort: '80'
64+
CidrIp: 0.0.0.0/0
65+
SecurityGroupEgress:
66+
- IpProtocol: tcp
67+
FromPort: '80'
68+
ToPort: '80'
69+
CidrIp: 0.0.0.0/0
70+
AllSecurityGroups:
71+
Type: Custom::Split
72+
Properties:
73+
ServiceToken: !GetAtt AppendItemToListFunction.Arn
74+
List:
75+
Ref: ExistingSecurityGroups
76+
AppendedItem:
77+
Ref: SecurityGroup
78+
AppendItemToListFunction:
79+
Type: AWS::Lambda::Function
80+
Properties:
81+
Handler: index.handler
82+
Role: !GetAtt LambdaExecutionRole.Arn
83+
Code:
84+
ZipFile: !Sub |
85+
var response = require('cfn-response');
86+
exports.handler = function(event, context) {
87+
var responseData = {Value: event.ResourceProperties.List};
88+
responseData.Value.push(event.ResourceProperties.AppendedItem);
89+
response.send(event, context, response.SUCCESS, responseData);
90+
};
91+
Runtime: nodejs8.10
92+
MyEC2Instance:
93+
Type: AWS::EC2::Instance
94+
Properties:
95+
ImageId:
96+
Fn::FindInMap:
97+
- AWSRegionArch2AMI
98+
- Ref: AWS::Region
99+
- Fn::FindInMap:
100+
- AWSInstanceType2Arch
101+
- Ref: InstanceType
102+
- Arch
103+
SecurityGroupIds: !GetAtt AllSecurityGroups.Value
104+
InstanceType:
105+
Ref: InstanceType
106+
LambdaExecutionRole:
107+
Type: AWS::IAM::Role
108+
Properties:
109+
AssumeRolePolicyDocument:
110+
Version: '2012-10-17'
111+
Statement:
112+
- Effect: Allow
113+
Principal:
114+
Service:
115+
- lambda.amazonaws.com
116+
Action:
117+
- sts:AssumeRole
118+
Path: "/"
119+
Policies:
120+
- PolicyName: root
121+
PolicyDocument:
122+
Version: '2012-10-17'
123+
Statement:
124+
- Effect: Allow
125+
Action:
126+
- logs:*
127+
Resource: arn:aws:logs:*:*:*
128+
Outputs:
129+
AllSecurityGroups:
130+
Description: Security Groups that are associated with the EC2 instance
131+
Value:
132+
Fn::Join:
133+
- ", "
134+
- Fn::GetAtt:
135+
- AllSecurityGroups
136+
- Value

0 commit comments

Comments
 (0)