@@ -13,8 +13,7 @@ func getEnv(name string) string {
1313 value := os .Getenv (name )
1414
1515 if len (value ) == 0 {
16- log .Println ("Please set " + name + " variable" )
17- os .Exit (1 )
16+ panic ("Please set " + name + " variable" )
1817 }
1918
2019 return value
@@ -27,16 +26,15 @@ func getNodeIps() []string {
2726 nodeList , err := dockercloud .ListNodes ()
2827
2928 if err != nil {
30- log .Println (err )
31- } else {
32- log .Println ("Received public IP list from Docker Cloud" )
29+ panic (err )
3330 }
3431
32+ log .Println ("Received public IP list from Docker Cloud" )
33+
3534 nodeIps := make ([]string , 0 )
3635
3736 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" )
4038 }
4139
4240 for i := 0 ; i < len (nodeList .Objects ); i ++ {
@@ -73,28 +71,27 @@ func listenToEvents() {
7371 * Rewrite inbound rules for the security group
7472 */
7573func 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
7876 var allProtocol string = "-1"
7977
8078 log .Println ("Flushing security group... " )
8179
8280 svc := ec2 .New (session .New ())
83- inboundRules .GroupId = & groupId
84- flushRules .GroupId = & groupId
81+ newRules .GroupId = & groupId
82+ oldRules .GroupId = & groupId
8583
8684 params := & ec2.DescribeSecurityGroupsInput { GroupIds : []* string { & groupId }}
8785 resp , err := svc .DescribeSecurityGroups (params )
8886
8987 for i := 0 ; i < len (resp .SecurityGroups [0 ].IpPermissions ); i ++ {
9088 existing := resp .SecurityGroups [0 ].IpPermissions [i ]
91- flushRules .IpPermissions = append (flushRules .IpPermissions , existing )
89+ old .IpPermissions = append (oldRules .IpPermissions , existing )
9290 }
9391
94- _ , err = svc .RevokeSecurityGroupIngress (& flushRules )
95-
92+ _ , err = svc .RevokeSecurityGroupIngress (& oldRules )
9693 if err == nil {
97- log .Println ("done " )
94+ log .Println ("success " )
9895 }
9996
10097 log .Println ("Adding current node IPs to the group... " )
@@ -106,16 +103,15 @@ func modifySecurityGroup(groupId string, ips []string) {
106103 entry := new (ec2.IpPermission )
107104 entry .IpProtocol = & allProtocol
108105 entry .IpRanges = []* ec2.IpRange {{CidrIp : & ips [i ]}}
109- inboundRules .IpPermissions = append (inboundRules .IpPermissions , entry )
106+ newRules .IpPermissions = append (newRules .IpPermissions , entry )
110107 }
111108
112- _ , err = svc .AuthorizeSecurityGroupIngress (& inboundRules )
113-
109+ _ , err = svc .AuthorizeSecurityGroupIngress (& newRules )
114110 if err != nil {
115111 panic (err )
116- } else {
117- log .Println ("done" )
118112 }
113+
114+ log .Println ("success" )
119115}
120116
121117/*
@@ -130,6 +126,9 @@ func initDockerCloud() {
130126 }
131127}
132128
129+ /*
130+ * Main block
131+ */
133132func main () {
134133 initDockerCloud ()
135134
0 commit comments