@@ -13,8 +13,7 @@ func getEnv(name string) string {
13
13
value := os .Getenv (name )
14
14
15
15
if len (value ) == 0 {
16
- log .Println ("Please set " + name + " variable" )
17
- os .Exit (1 )
16
+ panic ("Please set " + name + " variable" )
18
17
}
19
18
20
19
return value
@@ -27,16 +26,15 @@ func getNodeIps() []string {
27
26
nodeList , err := dockercloud .ListNodes ()
28
27
29
28
if err != nil {
30
- log .Println (err )
31
- } else {
32
- log .Println ("Received public IP list from Docker Cloud" )
29
+ panic (err )
33
30
}
34
31
32
+ log .Println ("Received public IP list from Docker Cloud" )
33
+
35
34
nodeIps := make ([]string , 0 )
36
35
37
36
if len (nodeList .Objects ) == 0 {
38
- log .Println ("There are no nodes in your Docker Cloud account" )
39
- os .Exit (1 )
37
+ log .Println ("There are no nodes in your Docker Cloud account yet" )
40
38
}
41
39
42
40
for i := 0 ; i < len (nodeList .Objects ); i ++ {
@@ -73,28 +71,27 @@ func listenToEvents() {
73
71
* Rewrite inbound rules for the security group
74
72
*/
75
73
func modifySecurityGroup (groupId string , ips []string ) {
76
- var inboundRules ec2.AuthorizeSecurityGroupIngressInput
77
- var flushRules ec2.RevokeSecurityGroupIngressInput
74
+ var newRules ec2.AuthorizeSecurityGroupIngressInput
75
+ var oldRules ec2.RevokeSecurityGroupIngressInput
78
76
var allProtocol string = "-1"
79
77
80
78
log .Println ("Flushing security group... " )
81
79
82
80
svc := ec2 .New (session .New ())
83
- inboundRules .GroupId = & groupId
84
- flushRules .GroupId = & groupId
81
+ newRules .GroupId = & groupId
82
+ oldRules .GroupId = & groupId
85
83
86
84
params := & ec2.DescribeSecurityGroupsInput { GroupIds : []* string { & groupId }}
87
85
resp , err := svc .DescribeSecurityGroups (params )
88
86
89
87
for i := 0 ; i < len (resp .SecurityGroups [0 ].IpPermissions ); i ++ {
90
88
existing := resp .SecurityGroups [0 ].IpPermissions [i ]
91
- flushRules .IpPermissions = append (flushRules .IpPermissions , existing )
89
+ old .IpPermissions = append (oldRules .IpPermissions , existing )
92
90
}
93
91
94
- _ , err = svc .RevokeSecurityGroupIngress (& flushRules )
95
-
92
+ _ , err = svc .RevokeSecurityGroupIngress (& oldRules )
96
93
if err == nil {
97
- log .Println ("done " )
94
+ log .Println ("success " )
98
95
}
99
96
100
97
log .Println ("Adding current node IPs to the group... " )
@@ -106,16 +103,15 @@ func modifySecurityGroup(groupId string, ips []string) {
106
103
entry := new (ec2.IpPermission )
107
104
entry .IpProtocol = & allProtocol
108
105
entry .IpRanges = []* ec2.IpRange {{CidrIp : & ips [i ]}}
109
- inboundRules .IpPermissions = append (inboundRules .IpPermissions , entry )
106
+ newRules .IpPermissions = append (newRules .IpPermissions , entry )
110
107
}
111
108
112
- _ , err = svc .AuthorizeSecurityGroupIngress (& inboundRules )
113
-
109
+ _ , err = svc .AuthorizeSecurityGroupIngress (& newRules )
114
110
if err != nil {
115
111
panic (err )
116
- } else {
117
- log .Println ("done" )
118
112
}
113
+
114
+ log .Println ("success" )
119
115
}
120
116
121
117
/*
@@ -130,6 +126,9 @@ func initDockerCloud() {
130
126
}
131
127
}
132
128
129
+ /*
130
+ * Main block
131
+ */
133
132
func main () {
134
133
initDockerCloud ()
135
134
0 commit comments