-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpn.go
109 lines (86 loc) · 3.2 KB
/
vpn.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package window
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
)
type (
VPNConnection struct {
// The configuration information for the VPN connection's customer gateway (in
// the native XML format). This element is always present in the CreateVpnConnection
// response; however, it's present in the DescribeVpnConnections response only
// if the VPN connection is in the pending or available state.
CustomerGatewayConfiguration string
// The ID of the customer gateway at your end of the VPN connection.
CustomerGatewayId string
// The VPN connection options.
Options *ec2.VpnConnectionOptions
// The static routes associated with the VPN connection.
Routes []*ec2.VpnStaticRoute
// The current state of the VPN connection.
State string
// Any tags assigned to the VPN connection.
Tags []*ec2.Tag
// The type of VPN connection.
Type string
// Information about the VPN tunnel.
VgwTelemetry []*ec2.VgwTelemetry
// The ID of the VPN connection.
VpnConnectionId string
// The ID of the virtual private gateway at the AWS side of the VPN connection.
VpnGatewayId string
Name string
Id string
VPNConnectionConfiguration *VPNConnectionConfiguration
VPGateway *VPGateway
CustomerGateway *CustomerGateway
CloudWatchAlarms []*CloudWatchAlarm
}
VPNConnectionByNameAsc []*VPNConnection
)
func (a VPNConnectionByNameAsc) Len() int { return len(a) }
func (a VPNConnectionByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a VPNConnectionByNameAsc) Less(i, j int) bool {
return string_less_than(a[i].Name, a[j].Name)
}
func (vpn *VPNConnection) String() string {
if vpn != nil {
return vpn.Name
}
return ""
}
func LoadVPNConnections(input *ec2.DescribeVpnConnectionsInput) (map[string]*VPNConnection, error) {
resp, err := EC2Client.DescribeVpnConnections(input)
if err != nil {
return nil, err
}
vpns := make(map[string]*VPNConnection, len(resp.VpnConnections))
for _, ec2vpn := range resp.VpnConnections {
vpn := &VPNConnection{
CustomerGatewayConfiguration: aws.StringValue(ec2vpn.CustomerGatewayConfiguration),
CustomerGatewayId: aws.StringValue(ec2vpn.CustomerGatewayId),
Options: ec2vpn.Options,
Routes: ec2vpn.Routes,
State: aws.StringValue(ec2vpn.State),
Tags: ec2vpn.Tags,
Type: aws.StringValue(ec2vpn.Type),
VgwTelemetry: ec2vpn.VgwTelemetry,
VpnConnectionId: aws.StringValue(ec2vpn.VpnConnectionId),
VpnGatewayId: aws.StringValue(ec2vpn.VpnGatewayId),
}
vpn.Name = TagOrDefault(vpn.Tags, "Name", vpn.VpnConnectionId)
vpn.Id = "vpn:" + vpn.VpnConnectionId
vpn.VPNConnectionConfiguration, err = ParseVPNConnectionConfiguration(vpn.CustomerGatewayConfiguration)
if err != nil {
log.Println(err)
}
vpns[vpn.VpnConnectionId] = vpn
}
return vpns, nil
}
func (vpn *VPNConnection) Inactive() bool {
return vpn.CustomerGateway == nil ||
vpn.VPGateway == nil ||
vpn.CustomerGateway.Inactive() ||
vpn.VPGateway.Inactive()
}