-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgw.go
78 lines (60 loc) · 2 KB
/
cgw.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package window
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
CustomerGateway struct {
// The customer gateway's Border Gateway Protocol (BGP) Autonomous System Number
// (ASN).
BgpAsn string
// The ID of the customer gateway.
CustomerGatewayId string
// The Internet-routable IP address of the customer gateway's outside interface.
IpAddress string
// The current state of the customer gateway (pending | available | deleting | deleted).
State string
// Any tags assigned to the customer gateway.
Tags []*ec2.Tag
// The type of VPN connection the customer gateway supports (ipsec.1).
Type string
Name string
Id string
}
CustomerGatewayByNameAsc []*CustomerGateway
)
func (a CustomerGatewayByNameAsc) Len() int { return len(a) }
func (a CustomerGatewayByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a CustomerGatewayByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func (cgw *CustomerGateway) String() string {
if cgw != nil {
return cgw.Name
}
return ""
}
func LoadCustomerGateways(input *ec2.DescribeCustomerGatewaysInput) (map[string]*CustomerGateway, error) {
resp, err := EC2Client.DescribeCustomerGateways(input)
if err != nil {
return nil, err
}
cgws := make(map[string]*CustomerGateway, len(resp.CustomerGateways))
for _, ec2cgw := range resp.CustomerGateways {
cgw := &CustomerGateway{
BgpAsn: aws.StringValue(ec2cgw.BgpAsn),
CustomerGatewayId: aws.StringValue(ec2cgw.CustomerGatewayId),
IpAddress: aws.StringValue(ec2cgw.IpAddress),
State: aws.StringValue(ec2cgw.State),
Tags: ec2cgw.Tags,
Type: aws.StringValue(ec2cgw.Type),
Id: aws.StringValue(ec2cgw.CustomerGatewayId),
}
cgw.Name = TagOrDefault(cgw.Tags, "Name", cgw.CustomerGatewayId)
cgws[cgw.CustomerGatewayId] = cgw
}
return cgws, nil
}
func (cgw *CustomerGateway) Inactive() bool {
return cgw.State == "deleted"
}