smart_proxy_ipam 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7332a15117cab62b21214132d6e95eb6b97c025ed8ffd4b38b6ad053c1673a3c
|
4
|
+
data.tar.gz: 29f5d76007278fc6e0124ee2438e434d96cbbd02caf6375a4f8afdaf12a650a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d737e1a77f8a9487793f8efed346539ce461433e222e94debcb4d43f9365b92a4d43dfd35966122377d4e90d5c34852a684ea91d1f8aeca866abc8f894947b
|
7
|
+
data.tar.gz: 2d0a3ff8288589413c3b896a849d747263ff78a4bba0736088282d0bdc09059578c20b34dc65bbacf7cd85fa21623a28e5b40a07af1e65476b77488bff0ba4fb
|
@@ -34,6 +34,8 @@ module Proxy::Phpipam
|
|
34
34
|
section_name = params[:group]
|
35
35
|
|
36
36
|
phpipam_client = PhpipamClient.new
|
37
|
+
return auth_error unless phpipam_client.authenticated?
|
38
|
+
|
37
39
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
38
40
|
|
39
41
|
return {:code => subnet['code'], :error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
@@ -82,6 +84,8 @@ module Proxy::Phpipam
|
|
82
84
|
cidr = params[:address] + '/' + params[:prefix]
|
83
85
|
|
84
86
|
phpipam_client = PhpipamClient.new
|
87
|
+
return auth_error unless phpipam_client.authenticated?
|
88
|
+
|
85
89
|
phpipam_client.get_subnet(cidr)
|
86
90
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
87
91
|
logger.debug(errors[:no_connection])
|
@@ -106,8 +110,11 @@ module Proxy::Phpipam
|
|
106
110
|
|
107
111
|
begin
|
108
112
|
phpipam_client = PhpipamClient.new
|
113
|
+
return auth_error unless phpipam_client.authenticated?
|
114
|
+
|
109
115
|
sections = phpipam_client.get_sections
|
110
116
|
return {:code => 200, :data => []}.to_json if no_sections_found?(JSON.parse(sections))
|
117
|
+
|
111
118
|
sections
|
112
119
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
113
120
|
logger.debug(errors[:no_connection])
|
@@ -136,9 +143,11 @@ module Proxy::Phpipam
|
|
136
143
|
return err if err.length > 0
|
137
144
|
|
138
145
|
phpipam_client = PhpipamClient.new
|
146
|
+
return auth_error unless phpipam_client.authenticated?
|
147
|
+
|
139
148
|
section = JSON.parse(phpipam_client.get_section(params[:group]))
|
140
|
-
|
141
149
|
return {:code => section['code'], :message => section['message']}.to_json if no_section_found?(section)
|
150
|
+
|
142
151
|
section.to_json
|
143
152
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
144
153
|
logger.debug(errors[:no_connection])
|
@@ -209,8 +218,9 @@ module Proxy::Phpipam
|
|
209
218
|
return err if err.length > 0
|
210
219
|
|
211
220
|
phpipam_client = PhpipamClient.new
|
212
|
-
|
221
|
+
return auth_error unless phpipam_client.authenticated?
|
213
222
|
|
223
|
+
section = JSON.parse(phpipam_client.get_section(params[:group]))
|
214
224
|
return {:code => 404, :error => errors[:no_section]}.to_json if no_section_found?(section)
|
215
225
|
|
216
226
|
phpipam_client.get_subnets(section['data']['id'].to_s, false)
|
@@ -243,9 +253,11 @@ module Proxy::Phpipam
|
|
243
253
|
ip = params[:ip]
|
244
254
|
cidr = params[:address] + '/' + params[:prefix]
|
245
255
|
section_name = params[:group]
|
256
|
+
|
246
257
|
phpipam_client = PhpipamClient.new
|
258
|
+
return auth_error unless phpipam_client.authenticated?
|
259
|
+
|
247
260
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
248
|
-
|
249
261
|
return {:code => 404, :error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
250
262
|
|
251
263
|
ip_exists = JSON.parse(phpipam_client.ip_exists(ip, subnet['data']['id']))
|
@@ -287,8 +299,9 @@ module Proxy::Phpipam
|
|
287
299
|
section_name = URI.escape(params[:group])
|
288
300
|
|
289
301
|
phpipam_client = PhpipamClient.new
|
302
|
+
return auth_error unless phpipam_client.authenticated?
|
303
|
+
|
290
304
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
291
|
-
|
292
305
|
return {:code => 404, :error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
293
306
|
|
294
307
|
add_ip = JSON.parse(phpipam_client.add_ip_to_subnet(ip, subnet['data']['id'], 'Address auto added by Foreman'))
|
@@ -327,8 +340,9 @@ module Proxy::Phpipam
|
|
327
340
|
cidr = params[:address] + '/' + params[:prefix]
|
328
341
|
section_name = URI.escape(params[:group])
|
329
342
|
phpipam_client = PhpipamClient.new
|
330
|
-
|
343
|
+
return auth_error unless phpipam_client.authenticated?
|
331
344
|
|
345
|
+
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
332
346
|
return {:code => 404, :error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
333
347
|
|
334
348
|
delete_ip = JSON.parse(phpipam_client.delete_ip_from_subnet(ip, subnet['data']['id']))
|
@@ -367,6 +381,8 @@ module Proxy::Phpipam
|
|
367
381
|
cidr = params[:address] + '/' + params[:prefix]
|
368
382
|
|
369
383
|
phpipam_client = PhpipamClient.new
|
384
|
+
return auth_error unless phpipam_client.authenticated?
|
385
|
+
|
370
386
|
phpipam_client.get_subnet_by_section(cidr, params[:group])
|
371
387
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
372
388
|
logger.debug(errors[:no_connection])
|
@@ -26,6 +26,7 @@ module Proxy::Phpipam
|
|
26
26
|
@@m = Monitor.new
|
27
27
|
init_cache if @@ip_cache.nil?
|
28
28
|
start_cleanup_task if @@timer_task.nil?
|
29
|
+
authenticate
|
29
30
|
end
|
30
31
|
|
31
32
|
def get_subnet(cidr, section_name = nil)
|
@@ -170,6 +171,10 @@ module Proxy::Phpipam
|
|
170
171
|
@@timer_task.execute
|
171
172
|
end
|
172
173
|
|
174
|
+
def authenticated?
|
175
|
+
!@token.nil?
|
176
|
+
end
|
177
|
+
|
173
178
|
private
|
174
179
|
|
175
180
|
# @@ip_cache structure
|
@@ -291,7 +296,6 @@ module Proxy::Phpipam
|
|
291
296
|
end
|
292
297
|
|
293
298
|
def get(path)
|
294
|
-
authenticate
|
295
299
|
uri = URI(@api_base + path)
|
296
300
|
request = Net::HTTP::Get.new(uri)
|
297
301
|
request['token'] = @token
|
@@ -302,7 +306,6 @@ module Proxy::Phpipam
|
|
302
306
|
end
|
303
307
|
|
304
308
|
def delete(path, body=nil)
|
305
|
-
authenticate
|
306
309
|
uri = URI(@api_base + path)
|
307
310
|
uri.query = URI.encode_www_form(body) if body
|
308
311
|
request = Net::HTTP::Delete.new(uri)
|
@@ -314,7 +317,6 @@ module Proxy::Phpipam
|
|
314
317
|
end
|
315
318
|
|
316
319
|
def post(path, body=nil)
|
317
|
-
authenticate
|
318
320
|
uri = URI(@api_base + path)
|
319
321
|
uri.query = URI.encode_www_form(body) if body
|
320
322
|
request = Net::HTTP::Post.new(uri)
|
@@ -335,7 +337,8 @@ module Proxy::Phpipam
|
|
335
337
|
}
|
336
338
|
|
337
339
|
response = JSON.parse(response.body)
|
338
|
-
|
340
|
+
logger.warn(response['message']) if response['message']
|
341
|
+
@token = response.dig('data', 'token')
|
339
342
|
end
|
340
343
|
end
|
341
344
|
end
|
@@ -28,6 +28,10 @@ module PhpipamHelper
|
|
28
28
|
def ip_not_found_in_ipam?(ip)
|
29
29
|
ip && ip['message'] && ip['message'].downcase == 'no addresses found'
|
30
30
|
end
|
31
|
+
|
32
|
+
def auth_error
|
33
|
+
{:code => 401, :error => "Invalid username and password for External IPAM"}.to_json
|
34
|
+
end
|
31
35
|
|
32
36
|
# Returns an array of hashes with only the fields given in the fields param
|
33
37
|
def filter_fields(json_body, fields)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_ipam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Smart proxy plugin for IPAM integration with various IPAM providers
|
14
14
|
email: chrisjsmith001@gmail.com
|