enfcli 3.4.0.pre.alpha → 3.4.0
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/Gemfile.lock +2 -2
- data/lib/enfapi.rb +52 -135
- data/lib/enfcli/version.rb +1 -1
- data/lib/enfcli.rb +0 -4
- data/lib/enfthor.rb +11 -11
- metadata +3 -4
- data/lib/enfcli/commands/xdns.rb +0 -446
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8ebf306726a1569a5a3153cfa050bb9b636061333373b4e4ea3f478f4bb90e
|
4
|
+
data.tar.gz: '067847d53544ab678eed5bd2d97ae3d1c180d3f89ee5a08483d535e36b74a86f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c102ae5a073496bdb01207202c1424f42ebdb8775124a80a60f3825bcfb2feb2996344c706ff26f2ca41e11896b2c6ff120996ddf527faa9f0af3b5d013da7
|
7
|
+
data.tar.gz: 6faff192e846ef26cacd6e044a2db724ade8e4112c909d5bf1218b3517d0ad8d9a9450dfbfd49f8a6bf64b76b9c89b2c0e0a9fabfde12cf2dce631094a180a24
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enfcli (3.4.0
|
4
|
+
enfcli (3.4.0)
|
5
5
|
rest-client (~> 2.0)
|
6
6
|
terminal-table
|
7
7
|
thor (~> 0.20.0)
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
crack (0.4.3)
|
16
16
|
safe_yaml (~> 1.0.0)
|
17
17
|
diff-lcs (1.3)
|
18
|
-
domain_name (0.5.
|
18
|
+
domain_name (0.5.20190701)
|
19
19
|
unf (>= 0.0.5, < 1.0.0)
|
20
20
|
fuubar (2.3.2)
|
21
21
|
rspec-core (~> 3.0)
|
data/lib/enfapi.rb
CHANGED
@@ -18,7 +18,6 @@ require 'singleton'
|
|
18
18
|
require 'json'
|
19
19
|
require 'date'
|
20
20
|
require 'base64'
|
21
|
-
require 'cgi'
|
22
21
|
|
23
22
|
#
|
24
23
|
# NOTE: When api's are refactored into individual classes
|
@@ -31,109 +30,25 @@ module EnfApi
|
|
31
30
|
def self.to_json(hash)
|
32
31
|
JSON.generate(hash)
|
33
32
|
end
|
34
|
-
|
35
|
-
def self.url_encode(str)
|
36
|
-
CGI.escape( str ).gsub("+", "%20")
|
37
|
-
end
|
38
|
-
|
33
|
+
|
39
34
|
class ERROR < StandardError
|
40
35
|
def initialize(msg = "ENF Api Error")
|
41
36
|
super
|
42
37
|
end
|
43
38
|
end
|
44
39
|
|
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
|
-
|
125
40
|
class Firewall
|
126
41
|
include Singleton
|
127
|
-
|
42
|
+
|
128
43
|
def list_firewall_rules(network)
|
129
44
|
EnfApi::API.instance.get "/api/xfw/v1/#{network}/rule"
|
130
45
|
end
|
131
|
-
|
132
|
-
def add_firewall_rule(network, rule)
|
46
|
+
|
47
|
+
def add_firewall_rule(network, rule)
|
133
48
|
rule_json = EnfApi::to_json(rule)
|
134
49
|
EnfApi::API.instance.post "/api/xfw/v1/#{network}/rule", rule_json
|
135
50
|
end
|
136
|
-
|
51
|
+
|
137
52
|
def delete_firewall_rules(network, id = nil)
|
138
53
|
# Same method to call to delete all firewall rules in a network. if id is nil
|
139
54
|
EnfApi::API.instance.delete "/api/xfw/v1/#{network}/rule/#{id}"
|
@@ -144,7 +59,7 @@ module EnfApi
|
|
144
59
|
include Singleton
|
145
60
|
|
146
61
|
## NO_TEST
|
147
|
-
def provision_group(new_group)
|
62
|
+
def provision_group(new_group)
|
148
63
|
json = EnfApi::to_json(new_group)
|
149
64
|
EnfApi::API.instance.post "/api/xiam/v1/groups", json
|
150
65
|
end
|
@@ -156,7 +71,7 @@ module EnfApi
|
|
156
71
|
end
|
157
72
|
|
158
73
|
## NO_TEST
|
159
|
-
def add_group_to_network(gid, ipv6_network)
|
74
|
+
def add_group_to_network(gid, ipv6_network)
|
160
75
|
json = EnfApi::to_json(ipv6_network)
|
161
76
|
EnfApi::API.instance.post "/api/xiam/v1/groups/#{gid}/networks", json
|
162
77
|
end
|
@@ -172,17 +87,17 @@ module EnfApi
|
|
172
87
|
end
|
173
88
|
|
174
89
|
## NO_TEST
|
175
|
-
def provision_endpoint(new_endpoint)
|
90
|
+
def provision_endpoint(new_endpoint)
|
176
91
|
json = EnfApi::to_json(new_endpoint)
|
177
92
|
EnfApi::API.instance.post "/api/xiam/v1/endpoints", json
|
178
93
|
end
|
179
94
|
|
180
95
|
## NO_TEST
|
181
|
-
def update_endpoint_key(ipv6, credentials)
|
96
|
+
def update_endpoint_key(ipv6, credentials)
|
182
97
|
json = EnfApi::to_json(credentials)
|
183
98
|
EnfApi::API.instance.post "/api/xiam/v1/endpoints/#{ipv6}/credentials", json
|
184
99
|
end
|
185
|
-
|
100
|
+
|
186
101
|
end
|
187
102
|
|
188
103
|
##############################################################################
|
@@ -271,11 +186,13 @@ module EnfApi
|
|
271
186
|
EnfApi::API.instance.put "/api/captive/v1/profile/#{id}", json
|
272
187
|
end
|
273
188
|
end
|
274
|
-
|
189
|
+
|
190
|
+
|
191
|
+
|
275
192
|
class NetworkManager
|
276
193
|
include Singleton
|
277
194
|
end
|
278
|
-
|
195
|
+
|
279
196
|
class API
|
280
197
|
include Singleton
|
281
198
|
|
@@ -300,7 +217,7 @@ module EnfApi
|
|
300
217
|
case response.code
|
301
218
|
when 200
|
302
219
|
# get resp from json
|
303
|
-
resp = from_json(response.body)
|
220
|
+
resp = from_json(response.body)
|
304
221
|
|
305
222
|
# set request headers for subsequent api calls
|
306
223
|
token = resp[:data][0][:token]
|
@@ -316,28 +233,28 @@ module EnfApi
|
|
316
233
|
|
317
234
|
def get(request_uri)
|
318
235
|
@api[request_uri].get(@headers) {|response, request, result|
|
319
|
-
process_api_response response, request, result
|
236
|
+
process_api_response response, request, result
|
320
237
|
}
|
321
238
|
end
|
322
239
|
|
323
240
|
def post(request_uri, request_body = '')
|
324
241
|
@api[request_uri].post(request_body, @headers) {|response, request, result|
|
325
|
-
process_api_response response, request, result
|
242
|
+
process_api_response response, request, result
|
326
243
|
}
|
327
244
|
end
|
328
245
|
|
329
246
|
def put(request_uri, request_body = '')
|
330
247
|
@api[request_uri].put(request_body, @headers) {|response, request, result|
|
331
|
-
process_api_response response, request, result
|
248
|
+
process_api_response response, request, result
|
332
249
|
}
|
333
|
-
end
|
250
|
+
end
|
334
251
|
|
335
252
|
def delete(request_uri)
|
336
253
|
@api[request_uri].delete(@headers) {|response, request, result|
|
337
|
-
process_api_response response, request, result
|
254
|
+
process_api_response response, request, result
|
338
255
|
}
|
339
|
-
end
|
340
|
-
|
256
|
+
end
|
257
|
+
|
341
258
|
############################################################################################################################
|
342
259
|
# NOT READY API. MOVE ABOVE THIS LINE AFTER RSPEC OR INTO OWN CLASS
|
343
260
|
############################################################################################################################
|
@@ -347,47 +264,47 @@ module EnfApi
|
|
347
264
|
}
|
348
265
|
end
|
349
266
|
|
350
|
-
def list_enfnws
|
267
|
+
def list_enfnws
|
351
268
|
@api["/api/xcr/v2/enfnws"].get( @headers) {|response, request, result|
|
352
269
|
process_api_response response, request, result
|
353
270
|
}
|
354
271
|
end
|
355
|
-
|
356
|
-
def list_domains
|
272
|
+
|
273
|
+
def list_domains
|
357
274
|
@api["/api/xcr/v2/domains"].get( @headers) {|response, request, result|
|
358
275
|
process_api_response response, request, result
|
359
276
|
}
|
360
277
|
end
|
361
|
-
|
362
|
-
def get_domain(domain_id)
|
278
|
+
|
279
|
+
def get_domain(domain_id)
|
363
280
|
@api["/api/xcr/v2/domains/#{domain_id}"].get( @headers) {|response, request, result|
|
364
281
|
process_api_response response, request, result
|
365
282
|
}
|
366
283
|
end
|
367
284
|
|
368
285
|
def create_domain(domain_hash)
|
369
|
-
json = to_json( domain_hash )
|
286
|
+
json = to_json( domain_hash )
|
370
287
|
@api["/api/xcr/v2/domains"].post( json, @headers) {|response, request, result|
|
371
288
|
process_api_response response, request, result
|
372
289
|
}
|
373
290
|
end
|
374
291
|
|
375
292
|
def update_domain_rate_limits(domain_network, limit, limits_hash)
|
376
|
-
json = to_json( limits_hash )
|
293
|
+
json = to_json( limits_hash )
|
377
294
|
@api["/api/xcr/v2/domains/#{domain_network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
378
295
|
process_api_response response, request, result
|
379
296
|
}
|
380
297
|
end
|
381
298
|
|
382
299
|
def update_network_rate_limits(network, limit, limits_hash)
|
383
|
-
json = to_json( limits_hash )
|
300
|
+
json = to_json( limits_hash )
|
384
301
|
@api["/api/xcr/v2/nws/#{network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
385
302
|
process_api_response response, request, result
|
386
303
|
}
|
387
304
|
end
|
388
305
|
|
389
306
|
def update_ep_rate_limits(ipv6, limit, limits_hash)
|
390
|
-
json = to_json( limits_hash )
|
307
|
+
json = to_json( limits_hash )
|
391
308
|
@api["/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result|
|
392
309
|
process_api_response response, request, result
|
393
310
|
}
|
@@ -396,7 +313,7 @@ module EnfApi
|
|
396
313
|
def get_domain_rate_limits(domain_network, filter = nil)
|
397
314
|
api_url = "/api/xcr/v2/domains/#{domain_network}/ep_rate_limits"
|
398
315
|
api_url = "#{api_url}/#{filter}" if filter
|
399
|
-
|
316
|
+
|
400
317
|
@api[api_url].get( @headers) {|response, request, result|
|
401
318
|
process_api_response response, request, result
|
402
319
|
}
|
@@ -405,7 +322,7 @@ module EnfApi
|
|
405
322
|
def get_network_rate_limits(network, filter = nil)
|
406
323
|
api_url = "/api/xcr/v2/nws/#{network}/ep_rate_limits"
|
407
324
|
api_url = "#{api_url}/#{filter}" if filter
|
408
|
-
|
325
|
+
|
409
326
|
@api[api_url].get( @headers) {|response, request, result|
|
410
327
|
process_api_response response, request, result
|
411
328
|
}
|
@@ -414,7 +331,7 @@ module EnfApi
|
|
414
331
|
def get_ep_rate_limits(ipv6, filter = nil)
|
415
332
|
api_url = "/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits"
|
416
333
|
api_url = "#{api_url}/#{filter}" if filter
|
417
|
-
|
334
|
+
|
418
335
|
@api[api_url].get( @headers) {|response, request, result|
|
419
336
|
process_api_response response, request, result
|
420
337
|
}
|
@@ -430,35 +347,35 @@ module EnfApi
|
|
430
347
|
@api["/api/xcr/v2/domains/#{domain_network}/status"].delete( @headers) {|response, request, result|
|
431
348
|
process_api_response response, request, result
|
432
349
|
}
|
433
|
-
end
|
350
|
+
end
|
434
351
|
|
435
352
|
def create_nw(nw_hash)
|
436
353
|
json = to_json(nw_hash)
|
437
|
-
domain_id = nw_hash[:domain_id]
|
354
|
+
domain_id = nw_hash[:domain_id]
|
438
355
|
@api["/api/xcr/v2/domains/#{domain_id}/nws"].post(json, @headers) {|response, request, result|
|
439
356
|
process_api_response response, request, result
|
440
357
|
}
|
441
358
|
end
|
442
|
-
|
443
|
-
def list_nw_connections(domain_id, network_cidr, file = nil)
|
359
|
+
|
360
|
+
def list_nw_connections(domain_id, network_cidr, file = nil)
|
444
361
|
@api["/api/xcr/v2/domains/#{domain_id}/nws/#{network_cidr}/cxns"].get(@headers) {|response, request, result|
|
445
362
|
process_api_response response, request, result
|
446
363
|
}
|
447
364
|
end
|
448
365
|
|
449
|
-
def list_endpoint_events(ipv6)
|
366
|
+
def list_endpoint_events(ipv6)
|
450
367
|
@api["/api/xcr/v2/cxns/#{ipv6}/events"].get(@headers) {|response, request, result|
|
451
368
|
process_api_response response, request, result
|
452
369
|
}
|
453
370
|
end
|
454
371
|
|
455
|
-
def list_network_events(network_cidr)
|
372
|
+
def list_network_events(network_cidr)
|
456
373
|
@api["/api/xcr/v2/nws/#{network_cidr}/events"].get(@headers) {|response, request, result|
|
457
374
|
process_api_response response, request, result
|
458
375
|
}
|
459
376
|
end
|
460
377
|
|
461
|
-
def get_endpoint(ipv6)
|
378
|
+
def get_endpoint(ipv6)
|
462
379
|
@api["/api/xcr/v2/cxns/#{ipv6}"].get(@headers) {|response, request, result|
|
463
380
|
process_api_response response, request, result
|
464
381
|
}
|
@@ -467,19 +384,19 @@ module EnfApi
|
|
467
384
|
def update_endpoint(ipv6, name)
|
468
385
|
hash = { :ipv6 => ipv6, :name => name }
|
469
386
|
json = to_json( hash )
|
470
|
-
|
387
|
+
|
471
388
|
@api["/api/xcr/v2/cxns/#{ipv6}"].put( json, @headers) {|response, request, result|
|
472
|
-
process_api_response response, request, result
|
389
|
+
process_api_response response, request, result
|
473
390
|
}
|
474
391
|
end
|
475
392
|
|
476
|
-
def activate_enfnw(subnet)
|
393
|
+
def activate_enfnw(subnet)
|
477
394
|
@api["/api/xcr/v2/enfnws/#{subnet}"].put( '', @headers) {|response, request, result|
|
478
|
-
process_api_response response, request, result
|
395
|
+
process_api_response response, request, result
|
479
396
|
}
|
480
397
|
end
|
481
398
|
|
482
|
-
def list_domain_users(domain_network)
|
399
|
+
def list_domain_users(domain_network)
|
483
400
|
@api["/api/xcr/v2/domains/#{domain_network}/users"].get( @headers) {|response, request, result|
|
484
401
|
puts response.code
|
485
402
|
process_api_response response, request, result
|
@@ -496,10 +413,10 @@ module EnfApi
|
|
496
413
|
json = to_json( hash )
|
497
414
|
@api["/api/xcr/v2/domains/#{domain_network}/invites"].post( json, @headers) { |response, request, result|
|
498
415
|
process_api_response response, request, result
|
499
|
-
}
|
416
|
+
}
|
500
417
|
end
|
501
418
|
|
502
|
-
def cancel_invite(email)
|
419
|
+
def cancel_invite(email)
|
503
420
|
@api["/api/xcr/v2/invites/#{email}"].delete( @headers) {|response, request, result|
|
504
421
|
process_api_response response, request, result
|
505
422
|
}
|
@@ -508,7 +425,7 @@ module EnfApi
|
|
508
425
|
def resend_invite(email)
|
509
426
|
@api["/api/xcr/v2/invites/#{email}"].put( "{}", @headers) {|response, request, result|
|
510
427
|
process_api_response response, request, result
|
511
|
-
}
|
428
|
+
}
|
512
429
|
end
|
513
430
|
|
514
431
|
############################################################################################################################
|
@@ -523,7 +440,7 @@ module EnfApi
|
|
523
440
|
when 201
|
524
441
|
# return response body
|
525
442
|
from_json(response.body)
|
526
|
-
|
443
|
+
|
527
444
|
when 400
|
528
445
|
# api returns and error
|
529
446
|
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
@@ -535,12 +452,12 @@ module EnfApi
|
|
535
452
|
when 403
|
536
453
|
# api returns and error
|
537
454
|
raise EnfApi::ERROR, "AUTHORIZATION_ERROR: User is not authorized to perform this operation!"
|
538
|
-
|
455
|
+
|
539
456
|
else
|
540
457
|
raise EnfApi::ERROR, "Unexpected error! Please try again!"
|
541
458
|
end
|
542
459
|
end
|
543
|
-
|
460
|
+
|
544
461
|
def from_json(string)
|
545
462
|
begin
|
546
463
|
JSON.parse(string, {:symbolize_names => true})
|
data/lib/enfcli/version.rb
CHANGED
data/lib/enfcli.rb
CHANGED
@@ -30,7 +30,6 @@ 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'
|
34
33
|
|
35
34
|
module EnfCli
|
36
35
|
FIREWALL_CMD = "firewall"
|
@@ -38,7 +37,6 @@ module EnfCli
|
|
38
37
|
NETWORK_CMD = "network"
|
39
38
|
USER_CMD = "user"
|
40
39
|
CAPTIVE_CMD = "captive"
|
41
|
-
DNS_CMD = "dns"
|
42
40
|
|
43
41
|
class IPV6
|
44
42
|
def initialize(ipv6)
|
@@ -392,8 +390,6 @@ module EnfCli
|
|
392
390
|
desc "#{EnfCli::CAPTIVE_CMD} COMMANDS", "#{EnfCli::CAPTIVE_CMD} commands"
|
393
391
|
subcommand EnfCli::CAPTIVE_CMD, EnfCli::Cmd::Captive
|
394
392
|
|
395
|
-
desc "#{EnfCli::DNS_CMD} COMMANDS", "#{EnfCli::DNS_CMD} commands"
|
396
|
-
subcommand EnfCli::DNS_CMD, EnfCli::Cmd::Xdns
|
397
393
|
end
|
398
394
|
end
|
399
395
|
|
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.0
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Venkatakumar Srinivasan
|
@@ -190,7 +190,6 @@ 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
|
194
193
|
- lib/enfcli/commands/xfw.rb
|
195
194
|
- lib/enfcli/commands/xiam.rb
|
196
195
|
- lib/enfcli/version.rb
|
@@ -209,9 +208,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
208
|
version: '0'
|
210
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
210
|
requirements:
|
212
|
-
- - "
|
211
|
+
- - ">="
|
213
212
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
213
|
+
version: '0'
|
215
214
|
requirements: []
|
216
215
|
rubygems_version: 3.0.1
|
217
216
|
signing_key:
|
data/lib/enfcli/commands/xdns.rb
DELETED
@@ -1,446 +0,0 @@
|
|
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
|