@@ -26,19 +26,19 @@ type AWSWeb struct {
26
26
func (a AWSWeb ) TokenManager (w http.ResponseWriter , r * http.Request ) {
27
27
// get the swarm manager token, if they are a manager node,
28
28
// and are not already in the swarm. Block otherwise
29
- GetRequestInfo (r )
30
- found := AlreadyInSwarm (r )
31
- isManager := IsManagerNode (r )
29
+ RequestInfo (r )
30
+ found := alreadyInSwarm (r )
31
+ isManager := isManagerNode (r )
32
32
33
33
if found || ! isManager {
34
34
// they are either already in the swarm, or they are not a manager
35
35
w .WriteHeader (http .StatusForbidden )
36
- fmt .Fprintf (w , "Access Denied\n " )
36
+ fmt .Fprintln (w , "Access Denied" )
37
37
return
38
38
}
39
39
40
40
// They are not in the swarm, and they are a manager, so good to go.
41
- cli , ctx := GetDockerClient ()
41
+ cli , ctx := DockerClient ()
42
42
swarm , err := cli .SwarmInspect (ctx )
43
43
if err != nil {
44
44
w .WriteHeader (http .StatusInternalServerError )
@@ -51,20 +51,20 @@ func (a AWSWeb) TokenManager(w http.ResponseWriter, r *http.Request) {
51
51
func (a AWSWeb ) TokenWorker (w http.ResponseWriter , r * http.Request ) {
52
52
// get the swarm worker token, if they are a worker node,
53
53
// and are not already in the swarm. block otherwise
54
- GetRequestInfo (r )
54
+ RequestInfo (r )
55
55
56
- found := AlreadyInSwarm (r )
57
- isWorker := IsWorkerNode (r )
56
+ found := alreadyInSwarm (r )
57
+ isWorker := isWorkerNode (r )
58
58
59
59
if found || ! isWorker {
60
60
// they are either already in the swarm, or they are not a worker
61
61
w .WriteHeader (http .StatusForbidden )
62
- fmt .Fprintf (w , "Access Denied\n " )
62
+ fmt .Fprintln (w , "Access Denied" )
63
63
return
64
64
}
65
65
66
66
// They are not in the swarm, and they are a worker, so good to go.
67
- cli , ctx := GetDockerClient ()
67
+ cli , ctx := DockerClient ()
68
68
swarm , err := cli .SwarmInspect (ctx )
69
69
if err != nil {
70
70
w .WriteHeader (http .StatusInternalServerError )
@@ -74,84 +74,23 @@ func (a AWSWeb) TokenWorker(w http.ResponseWriter, r *http.Request) {
74
74
fmt .Fprintf (w , swarm .JoinTokens .Worker )
75
75
}
76
76
77
- func (a AWSWeb ) CheckManager (w http.ResponseWriter , r * http.Request ) {
78
- // check if this node is a manager and already in the swarm.
79
- GetRequestInfo (r )
80
- ip := GetRequestIP (r )
81
- found := AlreadyInSwarm (r )
82
- isManager := IsManagerNode (r )
83
- fmt .Fprintf (w , "IP:%s;InSwarm:%v;IsManager:%v;\n " , ip , found , isManager )
84
- }
85
-
86
- func (a AWSWeb ) CheckWorker (w http.ResponseWriter , r * http.Request ) {
87
- // check if this node is a worker, and already in the swarm.
88
- GetRequestInfo (r )
89
- ip := GetRequestIP (r )
90
- found := AlreadyInSwarm (r )
91
- isWorker := IsWorkerNode (r )
92
- fmt .Fprintf (w , "IP:%s;InSwarm:%v;IsWorker:%v;\n " , ip , found , isWorker )
93
- }
94
-
95
- func (a AWSWeb ) Instances (w http.ResponseWriter , r * http.Request ) {
96
- // show both manager and worker instances
97
- GetRequestInfo (r )
98
- fmt .Fprintf (w , "Managers: \n " )
99
- instances := GetAWSManagers ()
100
- for _ , instance := range instances {
101
- fmt .Fprintf (w , "%s %s\n " , instance .InstanceID , instance .PrivateIPAddress )
102
- }
103
- fmt .Fprintf (w , "Workers: \n " )
104
- instances = GetAWSWorkers ()
105
- for _ , instance := range instances {
106
- fmt .Fprintf (w , "%s %s\n " , instance .InstanceID , instance .PrivateIPAddress )
107
- }
108
- }
109
-
110
- func (a AWSWeb ) ManagerInstances (w http.ResponseWriter , r * http.Request ) {
111
- // only show manager instances
112
- GetRequestInfo (r )
113
- instances := GetAWSManagers ()
114
- for _ , instance := range instances {
115
- fmt .Fprintf (w , "%s %s\n " , instance .InstanceID , instance .PrivateIPAddress )
116
- }
117
- }
118
-
119
- func (a AWSWeb ) WorkerInstances (w http.ResponseWriter , r * http.Request ) {
120
- // only show worker instances
121
- GetRequestInfo (r )
122
- instances := GetAWSWorkers ()
123
- for _ , instance := range instances {
124
- fmt .Fprintf (w , "%s %s\n " , instance .InstanceID , instance .PrivateIPAddress )
125
- }
126
- }
127
-
128
- func (a AWSWeb ) Nodes (w http.ResponseWriter , r * http.Request ) {
129
- // print the list of nodes in the swarm.
130
- GetRequestInfo (r )
131
- nodes := GetSwarmNodes ()
132
- for _ , node := range nodes {
133
- ip := ConvertAWSHostToIP (node .Description .Hostname )
134
- fmt .Fprintf (w , "%s %s %s\n " , node .ID [:15 ], node .Description .Hostname , ip )
135
- }
136
- }
137
-
138
- func AlreadyInSwarm (r * http.Request ) bool {
77
+ func alreadyInSwarm (r * http.Request ) bool {
139
78
// Is the node making the request, already in the swarm.
140
- ip := GetRequestIP (r )
141
- nodes := GetSwarmNodes ()
79
+ ip := RequestIP (r )
80
+ nodes := SwarmNodes ()
142
81
for _ , node := range nodes {
143
- nodeIP := ConvertAWSHostToIP (node .Description .Hostname )
82
+ nodeIP := convertAWSHostToIP (node .Description .Hostname )
144
83
if ip == nodeIP {
145
84
return true
146
85
}
147
86
}
148
87
return false
149
88
}
150
89
151
- func IsManagerNode (r * http.Request ) bool {
90
+ func isManagerNode (r * http.Request ) bool {
152
91
// Is the node making the request a manager node
153
- ip := GetRequestIP (r )
154
- instances := GetAWSManagers ()
92
+ ip := RequestIP (r )
93
+ instances := awsManagers ()
155
94
for _ , instance := range instances {
156
95
if ip == instance .PrivateIPAddress {
157
96
return true
@@ -160,10 +99,10 @@ func IsManagerNode(r *http.Request) bool {
160
99
return false
161
100
}
162
101
163
- func IsWorkerNode (r * http.Request ) bool {
102
+ func isWorkerNode (r * http.Request ) bool {
164
103
// Is the node making the request a worker node
165
- ip := GetRequestIP (r )
166
- instances := GetAWSWorkers ()
104
+ ip := RequestIP (r )
105
+ instances := awsWorkers ()
167
106
for _ , instance := range instances {
168
107
if ip == instance .PrivateIPAddress {
169
108
return true
@@ -172,7 +111,7 @@ func IsWorkerNode(r *http.Request) bool {
172
111
return false
173
112
}
174
113
175
- func GetAWSWorkers () []AwsInstance {
114
+ func awsWorkers () []AwsInstance {
176
115
// get the instances from AWS worker security group
177
116
178
117
customFilter := []* ec2.Filter {
@@ -188,10 +127,10 @@ func GetAWSWorkers() []AwsInstance {
188
127
Values : []* string {aws .String (os .Getenv ("WORKER_SECURITY_GROUP_ID" ))},
189
128
})
190
129
191
- return getInstances (customFilter )
130
+ return awsInstances (customFilter )
192
131
}
193
132
194
- func GetAWSManagers () []AwsInstance {
133
+ func awsManagers () []AwsInstance {
195
134
// get the instances from AWS Manager security group
196
135
197
136
customFilter := []* ec2.Filter {
@@ -207,10 +146,10 @@ func GetAWSManagers() []AwsInstance {
207
146
Values : []* string {aws .String (os .Getenv ("MANAGER_SECURITY_GROUP_ID" ))},
208
147
})
209
148
210
- return getInstances (customFilter )
149
+ return awsInstances (customFilter )
211
150
}
212
151
213
- func getInstances (customFilters []* ec2.Filter ) []AwsInstance {
152
+ func awsInstances (customFilters []* ec2.Filter ) []AwsInstance {
214
153
// get the instances from AWS, takes a filter to limit the results.
215
154
216
155
client := ec2 .New (session .New (& aws.Config {}))
@@ -255,7 +194,7 @@ func getInstances(customFilters []*ec2.Filter) []AwsInstance {
255
194
return instances
256
195
}
257
196
258
- func ConvertAWSHostToIP (hostStr string ) string {
197
+ func convertAWSHostToIP (hostStr string ) string {
259
198
// This is risky, this assumes the following formation for hosts in swarm node ls
260
199
// ip-10-0-3-149.ec2.internal
261
200
// there was one use case when someone had an old account, and their hostnames were not
0 commit comments