enfcli 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/enfapi.rb +135 -52
- data/lib/enfcli/commands/xdns.rb +446 -0
- data/lib/enfcli/version.rb +1 -1
- data/lib/enfcli.rb +4 -0
- data/lib/enfthor.rb +11 -11
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 131b57ab3f2a4584c8474f155f551361ba8668cb502b7cbe305fb822dedc9544
|
4
|
+
data.tar.gz: 411cb6af276ea545f7a7d991cb5e2726dad76ec69e5500b74e4855fef196185b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbfd0d2f80f9610ebcca20c3ce574fbad97a8639cb39db73cfc1fb0611c3f4612714a5050d88e3762686ca98d8305a15cf444381cfbf4bfdb7018b3ec2b8a971
|
7
|
+
data.tar.gz: 2df4253529a69a7d80d8100108dd997f35de16a9fb18446da3c4d646de797c641e524ce372a7ec6f17c0ad8e8704a552cddbb28c76aa9d03d17073c8d2b7c613
|
data/Gemfile.lock
CHANGED
data/lib/enfapi.rb
CHANGED
@@ -18,6 +18,7 @@ require 'singleton'
|
|
18
18
|
require 'json'
|
19
19
|
require 'date'
|
20
20
|
require 'base64'
|
21
|
+
require 'cgi'
|
21
22
|
|
22
23
|
#
|
23
24
|
# NOTE: When api's are refactored into individual classes
|
@@ -30,25 +31,109 @@ module EnfApi
|
|
30
31
|
def self.to_json(hash)
|
31
32
|
JSON.generate(hash)
|
32
33
|
end
|
33
|
-
|
34
|
+
|
35
|
+
def self.url_encode(str)
|
36
|
+
CGI.escape( str ).gsub("+", "%20")
|
37
|
+
end
|
38
|
+
|
34
39
|
class ERROR < StandardError
|
35
40
|
def initialize(msg = "ENF Api Error")
|
36
41
|
super
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
45
|
+
class Dns
|
46
|
+
include Singleton
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@version = "2019-05-27"
|
50
|
+
@xdns_base_url = "/api/xdns/#{@version}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def list_zones(domain)
|
54
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/zones?enf_domain=#{domain}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_dns_zone(new_zone)
|
58
|
+
json = EnfApi::to_json(new_zone)
|
59
|
+
EnfApi::API.instance.post "#{@xdns_base_url}/zones", json
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_dns_zone(zone_id, updated_zone)
|
63
|
+
json = EnfApi::to_json(updated_zone)
|
64
|
+
EnfApi::API.instance.put "#{@xdns_base_url}/zones/#{zone_id}", json
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_dns_zone(zone_id)
|
68
|
+
EnfApi::API.instance.delete "#{@xdns_base_url}/zones/#{zone_id}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_networks_to_zone(zone_id, add_networks)
|
72
|
+
json = EnfApi::to_json(add_networks)
|
73
|
+
EnfApi::API.instance.post "#{@xdns_base_url}/zones/#{zone_id}/networks", json
|
74
|
+
end
|
75
|
+
|
76
|
+
def replace_networks_in_zone(zone_id, replace_networks)
|
77
|
+
json = EnfApi::to_json(replace_networks)
|
78
|
+
EnfApi::API.instance.put "#{@xdns_base_url}/zones/#{zone_id}/networks", json
|
79
|
+
end
|
80
|
+
|
81
|
+
def list_networks_in_zone(zone_id)
|
82
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/zones/#{zone_id}/networks"
|
83
|
+
end
|
84
|
+
|
85
|
+
def delete_networks_from_zone(zone_id, delete_networks)
|
86
|
+
EnfApi::API.instance.delete "#{@xdns_base_url}/zones/#{zone_id}/networks?delete=#{delete_networks}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def list_zones_in_network(network)
|
90
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/networks/#{network}/zones"
|
91
|
+
end
|
92
|
+
|
93
|
+
def provision_server(network, new_server)
|
94
|
+
json = EnfApi::to_json(new_server)
|
95
|
+
EnfApi::API.instance.post "#{@xdns_base_url}/networks/#{network}/servers", json
|
96
|
+
end
|
97
|
+
|
98
|
+
def list_servers(network)
|
99
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/networks/#{network}/servers"
|
100
|
+
end
|
101
|
+
|
102
|
+
def delete_server(network, server_ipv6)
|
103
|
+
EnfApi::API.instance.delete "#{@xdns_base_url}/networks/#{network}/servers/#{server_ipv6}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_dns_record(zone_id, new_record)
|
107
|
+
json = EnfApi::to_json(new_record)
|
108
|
+
EnfApi::API.instance.post "#{@xdns_base_url}/zones/#{zone_id}/records", json
|
109
|
+
end
|
110
|
+
|
111
|
+
def list_dns_records(zone_id)
|
112
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/zones/#{zone_id}/records"
|
113
|
+
end
|
114
|
+
|
115
|
+
def query(network, type, name)
|
116
|
+
EnfApi::API.instance.get "#{@xdns_base_url}/networks/#{network}/query/#{type}/#{name}"
|
117
|
+
end
|
118
|
+
|
119
|
+
def delete_dns_record(record_id)
|
120
|
+
EnfApi::API.instance.delete "#{@xdns_base_url}/records/#{record_id}"
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
40
125
|
class Firewall
|
41
126
|
include Singleton
|
42
|
-
|
127
|
+
|
43
128
|
def list_firewall_rules(network)
|
44
129
|
EnfApi::API.instance.get "/api/xfw/v1/#{network}/rule"
|
45
130
|
end
|
46
|
-
|
47
|
-
def add_firewall_rule(network, rule)
|
131
|
+
|
132
|
+
def add_firewall_rule(network, rule)
|
48
133
|
rule_json = EnfApi::to_json(rule)
|
49
134
|
EnfApi::API.instance.post "/api/xfw/v1/#{network}/rule", rule_json
|
50
135
|
end
|
51
|
-
|
136
|
+
|
52
137
|
def delete_firewall_rules(network, id = nil)
|
53
138
|
# Same method to call to delete all firewall rules in a network. if id is nil
|
54
139
|
EnfApi::API.instance.delete "/api/xfw/v1/#{network}/rule/#{id}"
|
@@ -59,7 +144,7 @@ module EnfApi
|
|
59
144
|
include Singleton
|
60
145
|
|
61
146
|
## NO_TEST
|
62
|
-
def provision_group(new_group)
|
147
|
+
def provision_group(new_group)
|
63
148
|
json = EnfApi::to_json(new_group)
|
64
149
|
EnfApi::API.instance.post "/api/xiam/v1/groups", json
|
65
150
|
end
|
@@ -71,7 +156,7 @@ module EnfApi
|
|
71
156
|
end
|
72
157
|
|
73
158
|
## NO_TEST
|
74
|
-
def add_group_to_network(gid, ipv6_network)
|
159
|
+
def add_group_to_network(gid, ipv6_network)
|
75
160
|
json = EnfApi::to_json(ipv6_network)
|
76
161
|
EnfApi::API.instance.post "/api/xiam/v1/groups/#{gid}/networks", json
|
77
162
|
end
|
@@ -87,17 +172,17 @@ module EnfApi
|
|
87
172
|
end
|
88
173
|
|
89
174
|
## NO_TEST
|
90
|
-
def provision_endpoint(new_endpoint)
|
175
|
+
def provision_endpoint(new_endpoint)
|
91
176
|
json = EnfApi::to_json(new_endpoint)
|
92
177
|
EnfApi::API.instance.post "/api/xiam/v1/endpoints", json
|
93
178
|
end
|
94
179
|
|
95
180
|
## NO_TEST
|
96
|
-
def update_endpoint_key(ipv6, credentials)
|
181
|
+
def update_endpoint_key(ipv6, credentials)
|
97
182
|
json = EnfApi::to_json(credentials)
|
98
183
|
EnfApi::API.instance.post "/api/xiam/v1/endpoints/#{ipv6}/credentials", json
|
99
184
|
end
|
100
|
-
|
185
|
+
|
101
186
|
end
|
102
187
|
|
103
188
|
##############################################################################
|
@@ -186,13 +271,11 @@ module EnfApi
|
|
186
271
|
EnfApi::API.instance.put "/api/captive/v1/profile/#{id}", json
|
187
272
|
end
|
188
273
|
end
|
189
|
-
|
190
|
-
|
191
|
-
|
274
|
+
|
192
275
|
class NetworkManager
|
193
276
|
include Singleton
|
194
277
|
end
|
195
|
-
|
278
|
+
|
196
279
|
class API
|
197
280
|
include Singleton
|
198
281
|
|
@@ -217,7 +300,7 @@ module EnfApi
|
|
217
300
|
case response.code
|
218
301
|
when 200
|
219
302
|
# get resp from json
|
220
|
-
resp = from_json(response.body)
|
303
|
+
resp = from_json(response.body)
|
221
304
|
|
222
305
|
# set request headers for subsequent api calls
|
223
306
|
token = resp[:data][0][:token]
|
@@ -233,28 +316,28 @@ module EnfApi
|
|
233
316
|
|
234
317
|
def get(request_uri)
|
235
318
|
@api[request_uri].get(@headers) {|response, request, result|
|
236
|
-
process_api_response response, request, result
|
319
|
+
process_api_response response, request, result
|
237
320
|
}
|
238
321
|
end
|
239
322
|
|
240
323
|
def post(request_uri, request_body = '')
|
241
324
|
@api[request_uri].post(request_body, @headers) {|response, request, result|
|
242
|
-
process_api_response response, request, result
|
325
|
+
process_api_response response, request, result
|
243
326
|
}
|
244
327
|
end
|
245
328
|
|
246
329
|
def put(request_uri, request_body = '')
|
247
330
|
@api[request_uri].put(request_body, @headers) {|response, request, result|
|
248
|
-
process_api_response response, request, result
|
331
|
+
process_api_response response, request, result
|
249
332
|
}
|
250
|
-
end
|
333
|
+
end
|
251
334
|
|
252
335
|
def delete(request_uri)
|
253
336
|
@api[request_uri].delete(@headers) {|response, request, result|
|
254
|
-
process_api_response response, request, result
|
337
|
+
process_api_response response, request, result
|
255
338
|
}
|
256
|
-
end
|
257
|
-
|
339
|
+
end
|
340
|
+
|
258
341
|
############################################################################################################################
|
259
342
|
# NOT READY API. MOVE ABOVE THIS LINE AFTER RSPEC OR INTO OWN CLASS
|
260
343
|
############################################################################################################################
|
@@ -264,47 +347,47 @@ module EnfApi
|
|
264
347
|
}
|
265
348
|
end
|
266
349
|
|
267
|
-
def list_enfnws
|
350
|
+
def list_enfnws
|
268
351
|
@api["/api/xcr/v2/enfnws"].get( @headers) {|response, request, result|
|
269
352
|
process_api_response response, request, result
|
270
353
|
}
|
271
354
|
end
|
272
|
-
|
273
|
-
def list_domains
|
355
|
+
|
356
|
+
def list_domains
|
274
357
|
@api["/api/xcr/v2/domains"].get( @headers) {|response, request, result|
|
275
358
|
process_api_response response, request, result
|
276
359
|
}
|
277
360
|
end
|
278
|
-
|
279
|
-
def get_domain(domain_id)
|
361
|
+
|
362
|
+
def get_domain(domain_id)
|
280
363
|
@api["/api/xcr/v2/domains/#{domain_id}"].get( @headers) {|response, request, result|
|
281
364
|
process_api_response response, request, result
|
282
365
|
}
|
283
366
|
end
|
284
367
|
|
285
368
|
def create_domain(domain_hash)
|
286
|
-
json = to_json( domain_hash )
|
369
|
+
json = to_json( domain_hash )
|
287
370
|
@api["/api/xcr/v2/domains"].post( json, @headers) {|response, request, result|
|
288
371
|
process_api_response response, request, result
|
289
372
|
}
|
290
373
|
end
|
291
374
|
|
292
375
|
def update_domain_rate_limits(domain_network, limit, limits_hash)
|
293
|
-
json = to_json( limits_hash )
|
376
|
+
json = to_json( limits_hash )
|
294
377
|
@api["/api/xcr/v2/domains/#{domain_network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
295
378
|
process_api_response response, request, result
|
296
379
|
}
|
297
380
|
end
|
298
381
|
|
299
382
|
def update_network_rate_limits(network, limit, limits_hash)
|
300
|
-
json = to_json( limits_hash )
|
383
|
+
json = to_json( limits_hash )
|
301
384
|
@api["/api/xcr/v2/nws/#{network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
302
385
|
process_api_response response, request, result
|
303
386
|
}
|
304
387
|
end
|
305
388
|
|
306
389
|
def update_ep_rate_limits(ipv6, limit, limits_hash)
|
307
|
-
json = to_json( limits_hash )
|
390
|
+
json = to_json( limits_hash )
|
308
391
|
@api["/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
309
392
|
process_api_response response, request, result
|
310
393
|
}
|
@@ -313,7 +396,7 @@ module EnfApi
|
|
313
396
|
def get_domain_rate_limits(domain_network, filter = nil)
|
314
397
|
api_url = "/api/xcr/v2/domains/#{domain_network}/ep_rate_limits"
|
315
398
|
api_url = "#{api_url}/#{filter}" if filter
|
316
|
-
|
399
|
+
|
317
400
|
@api[api_url].get( @headers) {|response, request, result|
|
318
401
|
process_api_response response, request, result
|
319
402
|
}
|
@@ -322,7 +405,7 @@ module EnfApi
|
|
322
405
|
def get_network_rate_limits(network, filter = nil)
|
323
406
|
api_url = "/api/xcr/v2/nws/#{network}/ep_rate_limits"
|
324
407
|
api_url = "#{api_url}/#{filter}" if filter
|
325
|
-
|
408
|
+
|
326
409
|
@api[api_url].get( @headers) {|response, request, result|
|
327
410
|
process_api_response response, request, result
|
328
411
|
}
|
@@ -331,7 +414,7 @@ module EnfApi
|
|
331
414
|
def get_ep_rate_limits(ipv6, filter = nil)
|
332
415
|
api_url = "/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits"
|
333
416
|
api_url = "#{api_url}/#{filter}" if filter
|
334
|
-
|
417
|
+
|
335
418
|
@api[api_url].get( @headers) {|response, request, result|
|
336
419
|
process_api_response response, request, result
|
337
420
|
}
|
@@ -347,35 +430,35 @@ module EnfApi
|
|
347
430
|
@api["/api/xcr/v2/domains/#{domain_network}/status"].delete( @headers) {|response, request, result|
|
348
431
|
process_api_response response, request, result
|
349
432
|
}
|
350
|
-
end
|
433
|
+
end
|
351
434
|
|
352
435
|
def create_nw(nw_hash)
|
353
436
|
json = to_json(nw_hash)
|
354
|
-
domain_id = nw_hash[:domain_id]
|
437
|
+
domain_id = nw_hash[:domain_id]
|
355
438
|
@api["/api/xcr/v2/domains/#{domain_id}/nws"].post(json, @headers) {|response, request, result|
|
356
439
|
process_api_response response, request, result
|
357
440
|
}
|
358
441
|
end
|
359
|
-
|
360
|
-
def list_nw_connections(domain_id, network_cidr, file = nil)
|
442
|
+
|
443
|
+
def list_nw_connections(domain_id, network_cidr, file = nil)
|
361
444
|
@api["/api/xcr/v2/domains/#{domain_id}/nws/#{network_cidr}/cxns"].get(@headers) {|response, request, result|
|
362
445
|
process_api_response response, request, result
|
363
446
|
}
|
364
447
|
end
|
365
448
|
|
366
|
-
def list_endpoint_events(ipv6)
|
449
|
+
def list_endpoint_events(ipv6)
|
367
450
|
@api["/api/xcr/v2/cxns/#{ipv6}/events"].get(@headers) {|response, request, result|
|
368
451
|
process_api_response response, request, result
|
369
452
|
}
|
370
453
|
end
|
371
454
|
|
372
|
-
def list_network_events(network_cidr)
|
455
|
+
def list_network_events(network_cidr)
|
373
456
|
@api["/api/xcr/v2/nws/#{network_cidr}/events"].get(@headers) {|response, request, result|
|
374
457
|
process_api_response response, request, result
|
375
458
|
}
|
376
459
|
end
|
377
460
|
|
378
|
-
def get_endpoint(ipv6)
|
461
|
+
def get_endpoint(ipv6)
|
379
462
|
@api["/api/xcr/v2/cxns/#{ipv6}"].get(@headers) {|response, request, result|
|
380
463
|
process_api_response response, request, result
|
381
464
|
}
|
@@ -384,19 +467,19 @@ module EnfApi
|
|
384
467
|
def update_endpoint(ipv6, name)
|
385
468
|
hash = { :ipv6 => ipv6, :name => name }
|
386
469
|
json = to_json( hash )
|
387
|
-
|
470
|
+
|
388
471
|
@api["/api/xcr/v2/cxns/#{ipv6}"].put( json, @headers) {|response, request, result|
|
389
|
-
process_api_response response, request, result
|
472
|
+
process_api_response response, request, result
|
390
473
|
}
|
391
474
|
end
|
392
475
|
|
393
|
-
def activate_enfnw(subnet)
|
476
|
+
def activate_enfnw(subnet)
|
394
477
|
@api["/api/xcr/v2/enfnws/#{subnet}"].put( '', @headers) {|response, request, result|
|
395
|
-
process_api_response response, request, result
|
478
|
+
process_api_response response, request, result
|
396
479
|
}
|
397
480
|
end
|
398
481
|
|
399
|
-
def list_domain_users(domain_network)
|
482
|
+
def list_domain_users(domain_network)
|
400
483
|
@api["/api/xcr/v2/domains/#{domain_network}/users"].get( @headers) {|response, request, result|
|
401
484
|
puts response.code
|
402
485
|
process_api_response response, request, result
|
@@ -413,10 +496,10 @@ module EnfApi
|
|
413
496
|
json = to_json( hash )
|
414
497
|
@api["/api/xcr/v2/domains/#{domain_network}/invites"].post( json, @headers) { |response, request, result|
|
415
498
|
process_api_response response, request, result
|
416
|
-
}
|
499
|
+
}
|
417
500
|
end
|
418
501
|
|
419
|
-
def cancel_invite(email)
|
502
|
+
def cancel_invite(email)
|
420
503
|
@api["/api/xcr/v2/invites/#{email}"].delete( @headers) {|response, request, result|
|
421
504
|
process_api_response response, request, result
|
422
505
|
}
|
@@ -425,7 +508,7 @@ module EnfApi
|
|
425
508
|
def resend_invite(email)
|
426
509
|
@api["/api/xcr/v2/invites/#{email}"].put( "{}", @headers) {|response, request, result|
|
427
510
|
process_api_response response, request, result
|
428
|
-
}
|
511
|
+
}
|
429
512
|
end
|
430
513
|
|
431
514
|
############################################################################################################################
|
@@ -440,7 +523,7 @@ module EnfApi
|
|
440
523
|
when 201
|
441
524
|
# return response body
|
442
525
|
from_json(response.body)
|
443
|
-
|
526
|
+
|
444
527
|
when 400
|
445
528
|
# api returns and error
|
446
529
|
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
@@ -452,12 +535,12 @@ module EnfApi
|
|
452
535
|
when 403
|
453
536
|
# api returns and error
|
454
537
|
raise EnfApi::ERROR, "AUTHORIZATION_ERROR: User is not authorized to perform this operation!"
|
455
|
-
|
538
|
+
|
456
539
|
else
|
457
540
|
raise EnfApi::ERROR, "Unexpected error! Please try again!"
|
458
541
|
end
|
459
542
|
end
|
460
|
-
|
543
|
+
|
461
544
|
def from_json(string)
|
462
545
|
begin
|
463
546
|
JSON.parse(string, {:symbolize_names => true})
|
@@ -0,0 +1,446 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Xaptum,Inc
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
require 'enfthor'
|
17
|
+
require 'enfapi'
|
18
|
+
|
19
|
+
module EnfCli
|
20
|
+
module Cmd
|
21
|
+
|
22
|
+
class Xdns < EnfThor
|
23
|
+
DnsRecordType_AAAA = 'AAAA'
|
24
|
+
DnsRecordType_TXT = 'TXT'
|
25
|
+
DnsRecordType_SRV = 'SRV'
|
26
|
+
DnsRecordType_CNAME = 'CNAME'
|
27
|
+
DnsRecordTypes = [DnsRecordType_AAAA, DnsRecordType_CNAME, DnsRecordType_SRV, DnsRecordType_TXT]
|
28
|
+
|
29
|
+
no_commands {
|
30
|
+
def array_option_to_string(arr)
|
31
|
+
arr.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_record_value(type, value)
|
35
|
+
case type
|
36
|
+
when DnsRecordType_AAAA
|
37
|
+
value = value[:ipv6]
|
38
|
+
|
39
|
+
when DnsRecordType_CNAME
|
40
|
+
value = value[:dname]
|
41
|
+
|
42
|
+
when DnsRecordType_SRV
|
43
|
+
value = "#{value[:priority]} #{value[:weight]} #{value[:port]} #{value[:target]}"
|
44
|
+
|
45
|
+
when DnsRecordType_TXT
|
46
|
+
value = value[:txt]
|
47
|
+
end
|
48
|
+
|
49
|
+
value
|
50
|
+
end
|
51
|
+
|
52
|
+
def display_zones_table(zones)
|
53
|
+
headings = ['Id', 'Zone', 'Description', 'Enf Domain']
|
54
|
+
rows = zones.map{ |hash|
|
55
|
+
[ hash[:id], hash[:zone_domain_name], hash[:description], hash[:enf_domain] ]
|
56
|
+
}
|
57
|
+
render_table(headings, rows)
|
58
|
+
end
|
59
|
+
|
60
|
+
def display_networks_table(networks)
|
61
|
+
headings = ['Id', 'Network' ]
|
62
|
+
rows = networks.map{ |hash|
|
63
|
+
[ hash[:rowid], hash[:enf_network] ]
|
64
|
+
}
|
65
|
+
render_table(headings, rows)
|
66
|
+
end
|
67
|
+
|
68
|
+
def display_records_table(records)
|
69
|
+
headings = ['Id', 'Name', 'Type', 'Value', 'TTL']
|
70
|
+
rows = records.map{ |hash|
|
71
|
+
[ hash[:id], hash[:name], hash[:type], get_record_value(hash[:type], hash[:value]), hash[:ttl] ]
|
72
|
+
}
|
73
|
+
render_table(headings, rows)
|
74
|
+
end
|
75
|
+
|
76
|
+
def display_servers_table(servers)
|
77
|
+
headings = ['Id', 'IPv6', 'Network', 'Description' ]
|
78
|
+
rows = servers.map{ |hash|
|
79
|
+
[ hash[:id], hash[:ipv6], hash[:enf_network], hash[:description] ]
|
80
|
+
}
|
81
|
+
render_table(headings, rows)
|
82
|
+
end
|
83
|
+
}
|
84
|
+
|
85
|
+
desc "create-zone", "Create DNS Zone"
|
86
|
+
method_option :'zone-domain-name', :type => :string, :required => true
|
87
|
+
method_option :description, :type => :array, :banner => "DESCRIPTION"
|
88
|
+
method_option :'enf-domain', :type => :string, :banner => "/48 Enf Domain"
|
89
|
+
def create_zone
|
90
|
+
try_with_rescue_in_session do
|
91
|
+
## session
|
92
|
+
session = EnfCli::CTX.instance.session
|
93
|
+
|
94
|
+
## Gather parameters
|
95
|
+
zone_domain_name = options['zone-domain-name']
|
96
|
+
description = array_option_to_string(options.description) if options.description
|
97
|
+
case session[:type]
|
98
|
+
when 'XAPTUM_ADMIN'
|
99
|
+
enf_domain = options['enf-domain']
|
100
|
+
raise "No value provided for required options '--enf-domain'" unless enf_domain
|
101
|
+
|
102
|
+
else
|
103
|
+
enf_domain = session[:domain_network]
|
104
|
+
end
|
105
|
+
|
106
|
+
## create request hash
|
107
|
+
new_zone = {
|
108
|
+
:zone_domain_name => zone_domain_name,
|
109
|
+
:description => description,
|
110
|
+
:enf_domain => enf_domain
|
111
|
+
}
|
112
|
+
|
113
|
+
## call api
|
114
|
+
data = EnfApi::Dns.instance.create_dns_zone new_zone
|
115
|
+
zones = data[:data]
|
116
|
+
|
117
|
+
## display success
|
118
|
+
say "Created DNS zone #{zone_domain_name}!", :green
|
119
|
+
|
120
|
+
display_zones_table zones
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc "list-zones", "List DNS Zones"
|
125
|
+
method_option :'enf-domain', :type => :string, :banner => "/48 Enf Domain"
|
126
|
+
def list_zones
|
127
|
+
try_with_rescue_in_session do
|
128
|
+
## session
|
129
|
+
session = EnfCli::CTX.instance.session
|
130
|
+
|
131
|
+
case session[:type]
|
132
|
+
when 'XAPTUM_ADMIN'
|
133
|
+
enf_domain = options['enf-domain']
|
134
|
+
raise "No value provided for required options '--enf-domain'" unless enf_domain
|
135
|
+
|
136
|
+
else
|
137
|
+
enf_domain = session[:domain_network]
|
138
|
+
end
|
139
|
+
|
140
|
+
## call api
|
141
|
+
data = EnfApi::Dns.instance.list_zones enf_domain
|
142
|
+
zones = data[:data]
|
143
|
+
|
144
|
+
## display table
|
145
|
+
display_zones_table zones
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
desc "delete-zone", "Delete a DNS zone"
|
150
|
+
method_option :'zone-id', :type => :string, :required => true
|
151
|
+
def delete_zone
|
152
|
+
try_with_rescue_in_session do
|
153
|
+
zone_id = options[:'zone-id']
|
154
|
+
## call api
|
155
|
+
EnfApi::Dns.instance.delete_dns_zone zone_id
|
156
|
+
|
157
|
+
## print success
|
158
|
+
say "Deleted DNS Zone with id: #{zone_id}", :green
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
desc "update-zone", "Update a DNS zone description"
|
163
|
+
method_option :'zone-id', :type => :string, :required => true
|
164
|
+
method_option :description, :type => :array, :banner => "DESCRIPTION", :required => true
|
165
|
+
def update_zone
|
166
|
+
try_with_rescue_in_session do
|
167
|
+
## get parameters
|
168
|
+
description = array_option_to_string(options.description) if options.description
|
169
|
+
|
170
|
+
## update request
|
171
|
+
update_zone_req = {
|
172
|
+
:description => description
|
173
|
+
}
|
174
|
+
|
175
|
+
## call api
|
176
|
+
data = EnfApi::Dns.instance.update_dns_zone options[:'zone-id'], update_zone_req
|
177
|
+
zones = data[:data]
|
178
|
+
|
179
|
+
## display updated result
|
180
|
+
display_zones_table zones
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
desc "add-networks-to-zone", "Add /64 networks to DNS zone"
|
185
|
+
method_option :'zone-id', :type => :string, :required => true
|
186
|
+
method_option :networks, :type => :array, :banner => "NETWORKS", :required => true
|
187
|
+
def add_networks_to_zone
|
188
|
+
try_with_rescue_in_session do
|
189
|
+
## gather parameters
|
190
|
+
zone_id = options[:'zone-id']
|
191
|
+
networks = array_option_to_string(options[:networks]).split(",").map{ |x| x.strip }
|
192
|
+
|
193
|
+
## add networks request
|
194
|
+
add_networks_req = {
|
195
|
+
:networks => networks
|
196
|
+
}
|
197
|
+
|
198
|
+
## call api
|
199
|
+
data = EnfApi::Dns.instance.add_networks_to_zone zone_id, add_networks_req
|
200
|
+
networks = data[:data]
|
201
|
+
|
202
|
+
## display data
|
203
|
+
say "Added the following networks to zone with id: #{zone_id}", :green
|
204
|
+
display_networks_table networks
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
desc "list-networks-in-zone", "List /64 networks in DNS zone"
|
209
|
+
method_option :'zone-id', :type => :string, :required => true
|
210
|
+
def list_networks_in_zone
|
211
|
+
try_with_rescue_in_session do
|
212
|
+
## gather parameters
|
213
|
+
zone_id = options[:'zone-id']
|
214
|
+
|
215
|
+
## call api
|
216
|
+
data = EnfApi::Dns.instance.list_networks_in_zone zone_id
|
217
|
+
networks = data[:data]
|
218
|
+
|
219
|
+
## display data
|
220
|
+
display_networks_table networks
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
desc "delete-networks-from-zone", "Delete /64 networks from DNS zone"
|
225
|
+
method_option :'zone-id', :type => :string, :required => true
|
226
|
+
method_option :networks, :type => :array, :banner => "NETWORKS", :required => true
|
227
|
+
def delete_networks_from_zone
|
228
|
+
try_with_rescue_in_session do
|
229
|
+
## gather parameters
|
230
|
+
zone_id = options[:'zone-id']
|
231
|
+
networks = array_option_to_string(options[:networks])
|
232
|
+
|
233
|
+
## call api
|
234
|
+
EnfApi::Dns.instance.delete_networks_from_zone zone_id, networks
|
235
|
+
|
236
|
+
## print success
|
237
|
+
say "Deleted networks from DNS zone!", :green
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
desc "replace-networks-in-zone", "Replace /64 networks in DNS zone"
|
242
|
+
method_option :'zone-id', :type => :string, :required => true
|
243
|
+
method_option :networks, :type => :array, :banner => "NETWORKS", :required => true
|
244
|
+
def replace_networks_in_zone
|
245
|
+
try_with_rescue_in_session do
|
246
|
+
## gather parameters
|
247
|
+
zone_id = options[:'zone-id']
|
248
|
+
networks = array_option_to_string(options[:networks]).split(",").map{ |x| x.strip }
|
249
|
+
|
250
|
+
## replace networks request
|
251
|
+
replace_networks_req = {
|
252
|
+
:networks => networks
|
253
|
+
}
|
254
|
+
|
255
|
+
## call api
|
256
|
+
EnfApi::Dns.instance.replace_networks_in_zone zone_id, replace_networks_req
|
257
|
+
|
258
|
+
## print success
|
259
|
+
say "Replaced networks in DNS zone!", :green
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
desc "list-zones-in-network", "List DNS Zones in /64 Network"
|
264
|
+
method_option :'network', :type => :string, :banner => "/64 Enf Network", :required => true
|
265
|
+
def list_zones_in_network
|
266
|
+
try_with_rescue_in_session do
|
267
|
+
## gather parameters
|
268
|
+
network = options[:network]
|
269
|
+
|
270
|
+
## call api
|
271
|
+
data = EnfApi::Dns.instance.list_zones_in_network network
|
272
|
+
zones = data[:data]
|
273
|
+
|
274
|
+
## display data
|
275
|
+
display_zones_table zones
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
desc "create-record", "Create a DNS record"
|
280
|
+
method_option :'zone-id', :type => :string, :required => true
|
281
|
+
method_option :name, :type => :string, :required => true
|
282
|
+
method_option :'type', :type => :string, :required => true, :enum => DnsRecordTypes
|
283
|
+
method_option :ttl, :type => :numeric, :required => true
|
284
|
+
method_option :value, :type => :array, :required => true, :banner => 'VALUE'
|
285
|
+
def create_record
|
286
|
+
try_with_rescue_in_session do
|
287
|
+
## gather parameters
|
288
|
+
zone_id = options[:'zone-id']
|
289
|
+
name = options[:name]
|
290
|
+
type = options[:type]
|
291
|
+
ttl = options[:ttl]
|
292
|
+
value = array_option_to_string(options.value)
|
293
|
+
|
294
|
+
## get value
|
295
|
+
case type
|
296
|
+
when DnsRecordType_AAAA
|
297
|
+
ipv6 = EnfCli::IPV6.new(value).to_s
|
298
|
+
value = { :ipv6 => ipv6 }
|
299
|
+
|
300
|
+
when DnsRecordType_CNAME
|
301
|
+
value = { :dname => value }
|
302
|
+
|
303
|
+
when DnsRecordType_SRV
|
304
|
+
raise "Invalid value for #{DnsRecordType_SRV} record" unless options.value.length == 4
|
305
|
+
value = { :priority => Integer(options.value[0]),
|
306
|
+
:weight => Integer(options.value[1]),
|
307
|
+
:port => Integer(options.value[2]),
|
308
|
+
:target => options.value[3],
|
309
|
+
}
|
310
|
+
|
311
|
+
when DnsRecordType_TXT
|
312
|
+
value = { :txt => value }
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
new_record = {
|
318
|
+
:name => name,
|
319
|
+
:type => type,
|
320
|
+
:ttl => ttl,
|
321
|
+
:value => value
|
322
|
+
}
|
323
|
+
|
324
|
+
## call api
|
325
|
+
data = EnfApi::Dns.instance.create_dns_record zone_id, new_record
|
326
|
+
records = data[:data]
|
327
|
+
|
328
|
+
## display table
|
329
|
+
say "Created new DNS record!", :green
|
330
|
+
display_records_table records
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
desc "list-records", "List DNS records in a DNS zone"
|
335
|
+
method_option :'zone-id', :type => :string, :required => true
|
336
|
+
def list_records
|
337
|
+
try_with_rescue_in_session do
|
338
|
+
## gather parameters
|
339
|
+
zone_id = options[:'zone-id']
|
340
|
+
|
341
|
+
## call api
|
342
|
+
data = EnfApi::Dns.instance.list_dns_records zone_id
|
343
|
+
records = data[:data]
|
344
|
+
|
345
|
+
## display table
|
346
|
+
display_records_table records
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
desc "query", "Query DNS for a record"
|
351
|
+
method_option :'network', :type => :string, :required => true, :banner => "/64 Enf Network"
|
352
|
+
method_option :name, :type => :string, :required => true
|
353
|
+
method_option :'type', :type => :string, :required => true, :enum => DnsRecordTypes
|
354
|
+
def query
|
355
|
+
try_with_rescue_in_session do
|
356
|
+
## gather parameters
|
357
|
+
network = options[:network]
|
358
|
+
name = options[:name]
|
359
|
+
type = options[:type]
|
360
|
+
|
361
|
+
## call api
|
362
|
+
data = EnfApi::Dns.instance.query network, type, name
|
363
|
+
records = data[:data]
|
364
|
+
|
365
|
+
## display table
|
366
|
+
display_records_table records
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
desc "delete-record", "Delete a DNS record"
|
371
|
+
method_option :'id', :type => :string, :required => true
|
372
|
+
def delete_record
|
373
|
+
try_with_rescue_in_session do
|
374
|
+
## gather parameters
|
375
|
+
id = options[:id]
|
376
|
+
|
377
|
+
## call api
|
378
|
+
EnfApi::Dns.instance.delete_dns_record id
|
379
|
+
|
380
|
+
## print success
|
381
|
+
say "Deleted DNS record!", :green
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
desc "provision-server", "Provision a DNS server in /64 network"
|
386
|
+
method_option :'network', :type => :string, :banner => "/64 Enf Network", :required => true
|
387
|
+
method_option :'ipv6', :type => :string
|
388
|
+
method_option :description, :type => :array, :banner => "DESCRIPTION"
|
389
|
+
def provision_server
|
390
|
+
try_with_rescue_in_session do
|
391
|
+
## gather parameters
|
392
|
+
network = options[:network]
|
393
|
+
description = array_option_to_string(options.description) if options.description
|
394
|
+
ipv6 = options[:ipv6]
|
395
|
+
|
396
|
+
new_server = {
|
397
|
+
:ipv6 => ipv6,
|
398
|
+
:description => description
|
399
|
+
}
|
400
|
+
|
401
|
+
## call API
|
402
|
+
data = EnfApi::Dns.instance.provision_server network, new_server
|
403
|
+
servers = data[:data]
|
404
|
+
|
405
|
+
## display results
|
406
|
+
display_servers_table servers
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
desc "list-servers", "List DNS server in /64 network"
|
411
|
+
method_option :'network', :type => :string, :banner => "/64 Enf Network", :required => true
|
412
|
+
def list_servers
|
413
|
+
try_with_rescue_in_session do
|
414
|
+
## gather parameters
|
415
|
+
network = options[:network]
|
416
|
+
|
417
|
+
## call api
|
418
|
+
data = EnfApi::Dns.instance.list_servers network
|
419
|
+
servers = data[:data]
|
420
|
+
|
421
|
+
## display resutls
|
422
|
+
display_servers_table servers
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
desc "delete-server", "Delete DNS server in /64 network"
|
427
|
+
method_option :'network', :type => :string, :banner => "/64 Enf Network", :required => true
|
428
|
+
method_option :'ipv6', :type => :string, :banner => "Server Ipv6", :required => true
|
429
|
+
def delete_server
|
430
|
+
try_with_rescue_in_session do
|
431
|
+
## gather parameters
|
432
|
+
network = options[:network]
|
433
|
+
ipv6 = options[:ipv6]
|
434
|
+
|
435
|
+
## call api
|
436
|
+
EnfApi::Dns.instance.delete_server network, ipv6
|
437
|
+
|
438
|
+
## print success
|
439
|
+
say "Delete DNS server with ipv6 #{ipv6} in #{network}!", :green
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
end # Xdns
|
444
|
+
|
445
|
+
end # Cmd module
|
446
|
+
end # EnfCli module
|
data/lib/enfcli/version.rb
CHANGED
data/lib/enfcli.rb
CHANGED
@@ -30,6 +30,7 @@ require 'enfcli/commands/xiam'
|
|
30
30
|
require 'enfcli/commands/xfw'
|
31
31
|
require 'enfcli/commands/user'
|
32
32
|
require 'enfcli/commands/captive'
|
33
|
+
require 'enfcli/commands/xdns'
|
33
34
|
|
34
35
|
module EnfCli
|
35
36
|
FIREWALL_CMD = "firewall"
|
@@ -37,6 +38,7 @@ module EnfCli
|
|
37
38
|
NETWORK_CMD = "network"
|
38
39
|
USER_CMD = "user"
|
39
40
|
CAPTIVE_CMD = "captive"
|
41
|
+
DNS_CMD = "dns"
|
40
42
|
|
41
43
|
class IPV6
|
42
44
|
def initialize(ipv6)
|
@@ -390,6 +392,8 @@ module EnfCli
|
|
390
392
|
desc "#{EnfCli::CAPTIVE_CMD} COMMANDS", "#{EnfCli::CAPTIVE_CMD} commands"
|
391
393
|
subcommand EnfCli::CAPTIVE_CMD, EnfCli::Cmd::Captive
|
392
394
|
|
395
|
+
desc "#{EnfCli::DNS_CMD} COMMANDS", "#{EnfCli::DNS_CMD} commands"
|
396
|
+
subcommand EnfCli::DNS_CMD, EnfCli::Cmd::Xdns
|
393
397
|
end
|
394
398
|
end
|
395
399
|
|
data/lib/enfthor.rb
CHANGED
@@ -23,11 +23,11 @@ module EnfCli
|
|
23
23
|
|
24
24
|
# helper functions
|
25
25
|
no_commands {
|
26
|
-
|
26
|
+
|
27
27
|
def format_date(date)
|
28
28
|
DateTime.strptime("#{date}",'%s') if date
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def render_table(headings, rows, file = nil)
|
32
32
|
table = Terminal::Table.new
|
33
33
|
table.headings = headings
|
@@ -50,11 +50,11 @@ module EnfCli
|
|
50
50
|
raise EnfCli::ERROR, "User Session not establised!" if !session
|
51
51
|
|
52
52
|
yield
|
53
|
-
end
|
53
|
+
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def try_with_rescue
|
57
|
-
begin
|
57
|
+
begin
|
58
58
|
yield
|
59
59
|
rescue EnfApi::ERROR => e
|
60
60
|
say e, :red
|
@@ -62,13 +62,13 @@ module EnfCli
|
|
62
62
|
rescue OpenSSL::SSL::SSLError => e
|
63
63
|
say e, :red
|
64
64
|
say "Host may not support https. Try http instead", :bold
|
65
|
-
|
65
|
+
|
66
66
|
rescue => e
|
67
67
|
say e, :red
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
|
72
72
|
}
|
73
73
|
|
74
74
|
# override help methods
|
@@ -79,9 +79,9 @@ module EnfCli
|
|
79
79
|
text = $stdout.string
|
80
80
|
$stdout = STDOUT
|
81
81
|
text
|
82
|
-
end
|
83
|
-
|
84
|
-
def help(shell, subcommand = false)
|
82
|
+
end
|
83
|
+
|
84
|
+
def help(shell, subcommand = false)
|
85
85
|
list = printable_commands(true, subcommand)
|
86
86
|
Thor::Util.thor_classes_in(self).each do |klass|
|
87
87
|
list += klass.printable_commands(false)
|
@@ -107,12 +107,12 @@ module EnfCli
|
|
107
107
|
|
108
108
|
# Print the actual help message
|
109
109
|
shell.say help_text
|
110
|
-
|
110
|
+
|
111
111
|
# Add this line if you want to print custom text at the end of your help output.
|
112
112
|
# (similar to how Rails does it)
|
113
113
|
shell.say 'All commands can be run with -h (or --help) for more information.'
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
end
|
118
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enfcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Venkatakumar Srinivasan
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/enfcli/commands/captive.rb
|
191
191
|
- lib/enfcli/commands/user.rb
|
192
192
|
- lib/enfcli/commands/xcr.rb
|
193
|
+
- lib/enfcli/commands/xdns.rb
|
193
194
|
- lib/enfcli/commands/xfw.rb
|
194
195
|
- lib/enfcli/commands/xiam.rb
|
195
196
|
- lib/enfcli/version.rb
|