enfcli 3.3.4 → 3.4.0.pre.alpha

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.
@@ -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
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module EnfCli
17
- VERSION = '3.3.4'
17
+ VERSION = '3.4.0-alpha'
18
18
  end
data/lib/enfcli.rb CHANGED
@@ -29,12 +29,16 @@ require 'enfcli/commands/xcr'
29
29
  require 'enfcli/commands/xiam'
30
30
  require 'enfcli/commands/xfw'
31
31
  require 'enfcli/commands/user'
32
+ require 'enfcli/commands/captive'
33
+ require 'enfcli/commands/xdns'
32
34
 
33
35
  module EnfCli
34
36
  FIREWALL_CMD = "firewall"
35
37
  IAM_CMD = "iam"
36
38
  NETWORK_CMD = "network"
37
39
  USER_CMD = "user"
40
+ CAPTIVE_CMD = "captive"
41
+ DNS_CMD = "dns"
38
42
 
39
43
  class IPV6
40
44
  def initialize(ipv6)
@@ -286,6 +290,7 @@ module EnfCli
286
290
  end
287
291
 
288
292
  def start(host, user)
293
+ $stdout.sync = true
289
294
  # Set prompt
290
295
  EnfCli::CTX.instance.prompt = user
291
296
 
@@ -383,7 +388,12 @@ module EnfCli
383
388
 
384
389
  desc "#{EnfCli::USER_CMD} COMMANDS", "#{EnfCli::USER_CMD} commands"
385
390
  subcommand EnfCli::USER_CMD, EnfCli::Cmd::User
386
-
391
+
392
+ desc "#{EnfCli::CAPTIVE_CMD} COMMANDS", "#{EnfCli::CAPTIVE_CMD} commands"
393
+ subcommand EnfCli::CAPTIVE_CMD, EnfCli::Cmd::Captive
394
+
395
+ desc "#{EnfCli::DNS_CMD} COMMANDS", "#{EnfCli::DNS_CMD} commands"
396
+ subcommand EnfCli::DNS_CMD, EnfCli::Cmd::Xdns
387
397
  end
388
398
  end
389
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,25 +50,25 @@ 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
61
-
61
+
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enfcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.4.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Venkatakumar Srinivasan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-06 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -187,8 +187,10 @@ files:
187
187
  - enfcli.gemspec
188
188
  - lib/enfapi.rb
189
189
  - lib/enfcli.rb
190
+ - lib/enfcli/commands/captive.rb
190
191
  - lib/enfcli/commands/user.rb
191
192
  - lib/enfcli/commands/xcr.rb
193
+ - lib/enfcli/commands/xdns.rb
192
194
  - lib/enfcli/commands/xfw.rb
193
195
  - lib/enfcli/commands/xiam.rb
194
196
  - lib/enfcli/version.rb
@@ -207,9 +209,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
209
  version: '0'
208
210
  required_rubygems_version: !ruby/object:Gem::Requirement
209
211
  requirements:
210
- - - ">="
212
+ - - ">"
211
213
  - !ruby/object:Gem::Version
212
- version: '0'
214
+ version: 1.3.1
213
215
  requirements: []
214
216
  rubygems_version: 3.0.1
215
217
  signing_key: