forked from awslabs/fargatecli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eni.go
47 lines (37 loc) · 1.02 KB
/
eni.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ec2
import (
"github.com/aws/aws-sdk-go/aws"
awsec2 "github.com/aws/aws-sdk-go/service/ec2"
"github.com/jpignata/fargate/console"
)
type Eni struct {
PublicIpAddress string
EniId string
SecurityGroupIds []string
}
func (ec2 *EC2) DescribeNetworkInterfaces(eniIds []string) map[string]Eni {
enis := make(map[string]Eni)
resp, err := ec2.svc.DescribeNetworkInterfaces(
&awsec2.DescribeNetworkInterfacesInput{
NetworkInterfaceIds: aws.StringSlice(eniIds),
},
)
if err != nil {
console.ErrorExit(err, "Could not describe network interfaces")
}
for _, e := range resp.NetworkInterfaces {
var securityGroupIds []*string
for _, group := range e.Groups {
securityGroupIds = append(securityGroupIds, group.GroupId)
}
if e.Association != nil {
eni := Eni{
EniId: aws.StringValue(e.NetworkInterfaceId),
PublicIpAddress: aws.StringValue(e.Association.PublicIp),
SecurityGroupIds: aws.StringValueSlice(securityGroupIds),
}
enis[eni.EniId] = eni
}
}
return enis
}