Skip to content

Commit

Permalink
Merge pull request #4 from st1t/fix-sg
Browse files Browse the repository at this point in the history
Addressed the omission of consideration of ClassicEC2 in SecurityGroup.
  • Loading branch information
st1t committed Feb 15, 2022
2 parents 048aede + cab1092 commit 8e529ad
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/vaws/root.go
Expand Up @@ -11,7 +11,7 @@ var rootCmd = &cobra.Command{
Use: "vaws",
Short: "The vaws command was created to simplify the display of AWS resources.",
Long: `The vaws command was created to simplify the display of AWS resources.`,
Version: "0.3.0",
Version: "0.3.1",
}

func Execute() {
Expand Down
12 changes: 9 additions & 3 deletions cmd/vaws/security_group.go
Expand Up @@ -79,8 +79,14 @@ func showSecurityGroup(outputs []*ec2.DescribeSecurityGroupsOutput, table *table
table.SetHeader(header)
var records [][]string
var allowPort int32
var vpcId string
for _, o := range outputs {
for _, sg := range o.SecurityGroups {
if sg.VpcId == nil {
vpcId = "none"
} else {
vpcId = *sg.VpcId
}
for _, in := range sg.IpPermissions {
allowType := "inbound"
if in.ToPort != nil {
Expand All @@ -96,7 +102,7 @@ func showSecurityGroup(outputs []*ec2.DescribeSecurityGroupsOutput, table *table
*sg.GroupId,
strconv.Itoa(int(allowPort)),
*v.CidrIp,
*sg.VpcId,
vpcId,
})
}
}
Expand All @@ -108,7 +114,7 @@ func showSecurityGroup(outputs []*ec2.DescribeSecurityGroupsOutput, table *table
*sg.GroupId,
strconv.Itoa(int(allowPort)),
*prefix.PrefixListId,
*sg.VpcId,
vpcId,
})
}
}
Expand All @@ -120,7 +126,7 @@ func showSecurityGroup(outputs []*ec2.DescribeSecurityGroupsOutput, table *table
*sg.GroupId,
strconv.Itoa(int(allowPort)),
*v.GroupId,
*sg.VpcId,
vpcId,
})
}
}
Expand Down
51 changes: 51 additions & 0 deletions cmd/vaws/security_group_test.go
Expand Up @@ -124,6 +124,57 @@ func Test_showSecurityGroup(t *testing.T) {
| launch-wizard-2 | inbound | sg-08d35fef29987e75e | 22 | sg-0d642190887707fd0 | vpc-0f9999c7db8c44b21 |
| launch-wizard-2 | inbound | sg-08d35fef29987e75e | 53 | pl-61a12345 | vpc-0f9999c7db8c44b21 |
+-----------------+---------+----------------------+------+----------------------+-----------------------+
`,
},
{
name: "classic ec2",
args: args{
outputs: []*ec2.DescribeSecurityGroupsOutput{
{
SecurityGroups: []types.SecurityGroup{
{
GroupName: aws.String("default"),
GroupId: aws.String("sg-0d642190887707fd0"),
VpcId: nil,
IpPermissions: []types.IpPermission{
{
IpRanges: []types.IpRange{
{
CidrIp: aws.String("0.0.0.0/0"),
},
},
ToPort: nil,
},
},
},
{
GroupName: aws.String("launch-wizard-1"),
GroupId: aws.String("sg-0d642190887707fd0"),
VpcId: aws.String("vpc-0f9999c7db8c44b21"),
IpPermissions: []types.IpPermission{
{
IpRanges: []types.IpRange{
{
CidrIp: aws.String("0.0.0.0/0"),
},
},
ToPort: aws.Int32(22),
},
},
},
},
ResultMetadata: middleware.Metadata{},
},
},
table: nil,
sortPosition: 1,
},
want: `+-----------------+---------+----------------------+------+-----------+-----------------------+
| NAME | TYPE | ID | PORT | SOURCE | VPC |
+-----------------+---------+----------------------+------+-----------+-----------------------+
| default | inbound | sg-0d642190887707fd0 | -1 | 0.0.0.0/0 | none |
| launch-wizard-1 | inbound | sg-0d642190887707fd0 | 22 | 0.0.0.0/0 | vpc-0f9999c7db8c44b21 |
+-----------------+---------+----------------------+------+-----------+-----------------------+
`,
},
{
Expand Down

0 comments on commit 8e529ad

Please sign in to comment.