haproxy-api 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/install_haproxy-api_initd +1 -1
- data/haproxy-api.gemspec +1 -1
- data/lib/hapi/application/app.rb +68 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ec0d41213ad50b219654bd950588472b9431257
|
4
|
+
data.tar.gz: da194c115f417fe807cffcd80269927bcf4b9647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284ca7c41cdcd1a0aa116637abe630a89b8d042829eb896b467deb8474f3f8c32d5e8f3c2fc654edf6937c3c593c0e3327a1221653beb73aca39dc4d371b2544
|
7
|
+
data.tar.gz: 8155a14a98fafbeb65c56d035115f15540f028f334a684fcc772e1af0a38525df4fa46028ec076d746f511325ce4855ab7b54d89f6c7488c8e4721ea0b6ae5cf
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
if !File.exists('/etc/haproxy/hapi.crt')
|
3
|
+
if !File.exists?('/etc/haproxy/hapi.crt')
|
4
4
|
puts "generating hapi.crt and hapi.key in /etc/haproxy"
|
5
5
|
Dir.chdir '/etc/haproxy'
|
6
6
|
system("openssl req -x509 -newkey rsa:4096 -keyout hapi.key -out hapi.crt -days 365 -nodes -subj \"/C=UT/ST=Sandy /L=Sandy/O=Global Security/OU=IT Department/CN=tooese.com\"")
|
data/haproxy-api.gemspec
CHANGED
data/lib/hapi/application/app.rb
CHANGED
@@ -31,13 +31,6 @@ class HaproxyApi < Sinatra::Base
|
|
31
31
|
$haproxy_config = ENV['HAPROXY_CONFIG']
|
32
32
|
end
|
33
33
|
$mutable_haproxy_config = $haproxy_config + '.haproxy-api.json'
|
34
|
-
|
35
|
-
#before do
|
36
|
-
# request.body.rewind
|
37
|
-
# if request.body.size > 0
|
38
|
-
# @request_payload = JSON.parse request.body.read
|
39
|
-
# end
|
40
|
-
#end
|
41
34
|
|
42
35
|
|
43
36
|
def get_config
|
@@ -70,7 +63,18 @@ class HaproxyApi < Sinatra::Base
|
|
70
63
|
config['frontend'].each_pair do |name, frontend|
|
71
64
|
content += "frontend #{name}\n"
|
72
65
|
content += " bind 0.0.0.0:#{frontend['port']}\n"
|
73
|
-
|
66
|
+
if frontend.has_key? 'acls'
|
67
|
+
port = ''
|
68
|
+
frontend['acls'].each_pair do |acl,backend_port|
|
69
|
+
clean_name = acl.gsub('/','_')
|
70
|
+
content += " acl url_#{clean_name} path_beg #{acl}\n"
|
71
|
+
content += " use_backend #{name}-#{backend_port}-backend if url_#{clean_name}\n"
|
72
|
+
port = backend_port
|
73
|
+
end
|
74
|
+
content += " default_backend #{name}-#{port}-backend\n"
|
75
|
+
else
|
76
|
+
content += " default_backend #{name}-backend\n"
|
77
|
+
end
|
74
78
|
content += "\n"
|
75
79
|
end
|
76
80
|
|
@@ -93,7 +97,7 @@ class HaproxyApi < Sinatra::Base
|
|
93
97
|
end
|
94
98
|
|
95
99
|
backend['servers'].each do |server|
|
96
|
-
content += " server #{server}:#{port} #{server}:#{port} #{server_options} \n"
|
100
|
+
content += " server #{server}:#{port} #{server}:#{port} #{server_options} \n"
|
97
101
|
end
|
98
102
|
content += "\n"
|
99
103
|
end
|
@@ -121,17 +125,33 @@ class HaproxyApi < Sinatra::Base
|
|
121
125
|
return status(500)
|
122
126
|
end
|
123
127
|
end
|
128
|
+
|
129
|
+
|
130
|
+
def add_acl ( frontend, id, config )
|
131
|
+
acl = frontend['acl']
|
132
|
+
backend_port = frontend['backend_port']
|
133
|
+
if config.has_key?('frontend') && config['frontend'].has_key?(id)
|
134
|
+
frontend = config['frontend'][id]
|
135
|
+
end
|
136
|
+
if !frontend.has_key?('acls')
|
137
|
+
frontend['acls'] = {}
|
138
|
+
end
|
139
|
+
frontend['acls'][acl] = backend_port
|
140
|
+
end
|
124
141
|
|
142
|
+
|
125
143
|
get '/render' do
|
126
144
|
config = get_config
|
127
145
|
render config
|
128
146
|
end
|
129
|
-
|
147
|
+
|
148
|
+
|
130
149
|
get '/frontends' do
|
131
150
|
config = get_config
|
132
151
|
JSON.dump(config['frontend'])
|
133
152
|
end
|
134
|
-
|
153
|
+
|
154
|
+
|
135
155
|
get '/frontend/:id' do
|
136
156
|
config = get_config
|
137
157
|
id = params[:id]
|
@@ -139,6 +159,7 @@ class HaproxyApi < Sinatra::Base
|
|
139
159
|
JSON.dump(config['frontend'][id])
|
140
160
|
end
|
141
161
|
|
162
|
+
|
142
163
|
post '/frontend/:id' do
|
143
164
|
config = get_config
|
144
165
|
|
@@ -149,11 +170,30 @@ class HaproxyApi < Sinatra::Base
|
|
149
170
|
end
|
150
171
|
|
151
172
|
frontend = JSON.parse request.body.read
|
173
|
+
if frontend.has_key? 'acl'
|
174
|
+
add_acl frontend, id, config
|
175
|
+
end
|
176
|
+
|
152
177
|
config['frontend'][id] = frontend
|
153
178
|
set_config config
|
154
179
|
JSON.dump(frontend)
|
155
180
|
end
|
156
181
|
|
182
|
+
|
183
|
+
put '/frontend/:id' do
|
184
|
+
config = get_config
|
185
|
+
id = params[:id]
|
186
|
+
frontend = JSON.parse request.body.read
|
187
|
+
if frontend.has_key? 'acl'
|
188
|
+
add_acl frontend, id, config
|
189
|
+
else
|
190
|
+
config['frontend'][id] = frontend
|
191
|
+
end
|
192
|
+
set_config config
|
193
|
+
JSON.dump(frontend)
|
194
|
+
end
|
195
|
+
|
196
|
+
|
157
197
|
delete '/frontend/:id' do
|
158
198
|
config = get_config
|
159
199
|
config['frontend'].delete params[:id]
|
@@ -177,17 +217,31 @@ class HaproxyApi < Sinatra::Base
|
|
177
217
|
|
178
218
|
post '/backend/:id' do
|
179
219
|
config = get_config
|
180
|
-
|
220
|
+
backend = JSON.parse request.body.read
|
221
|
+
if backend.has_key?('acl')
|
222
|
+
id = params[:id] + '-' + backend['port'] + "-backend"
|
223
|
+
else
|
224
|
+
id = params[:id] + "-backend"
|
225
|
+
end
|
181
226
|
if config['backend'].has_key?(id)
|
182
227
|
puts "#{id} already exists - use put"
|
183
228
|
return status(500)
|
184
229
|
end
|
185
|
-
backend = JSON.parse request.body.read
|
186
230
|
config['backend'][id] = backend
|
187
231
|
set_config config
|
188
232
|
JSON.dump(backend)
|
189
233
|
end
|
190
|
-
|
234
|
+
|
235
|
+
|
236
|
+
put '/backend/:id' do
|
237
|
+
config = get_config
|
238
|
+
id = params[:id] + "-backend"
|
239
|
+
backend = JSON.parse request.body.read
|
240
|
+
config['backend'][id] = backend
|
241
|
+
set_config config
|
242
|
+
JSON.dump(backend)
|
243
|
+
end
|
244
|
+
|
191
245
|
|
192
246
|
delete '/backend/:id' do
|
193
247
|
config = get_config
|
@@ -198,4 +252,3 @@ class HaproxyApi < Sinatra::Base
|
|
198
252
|
end
|
199
253
|
|
200
254
|
Rack::Handler::WEBrick.run HaproxyApi, webrick_options
|
201
|
-
|