enfcli 3.10.4.pre.alpha → 3.11.0.pre.alpha

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: '060840337e5587c05f399f72499547dd919e344b560d7f8bf16027c067b9f9a9'
4
- data.tar.gz: 5cecd80db91bd74922f05aba5ce31124a7aa06d0fc49888ca7416a99d8345e47
3
+ metadata.gz: 26b242ed9d5db128c862067ce214faddb6c8842635f947538b5be9bc2ef44de6
4
+ data.tar.gz: 7531477be394b40a9cacda41ac4eb781b82495443ecc32e780d2efd7a7d63e30
5
5
  SHA512:
6
- metadata.gz: e8a7b06fff19daebe9463a2b808c76d3227605b1180a31db5b407beaf9bffc590997de86f80052e6aaf9198132d81f8cb96068a44a2ae4489389426c38f82acc
7
- data.tar.gz: cb1c049b79375bb3a90bf94edf53fad34c9bcee1d2313c7ad010d2307ed7d55198cd1804d791d19cdac20e46035e4f32b3708ac1862fb2118588bc63f861511d
6
+ metadata.gz: 3aa34b98fde5eea1a318cafc26756261c3b4a069d8baaf6aedf2a1e8adc4cbfe47d6822813835f8827e3dbb4d05c0add4e43f6942e49df11ec708904c9a217b8
7
+ data.tar.gz: 789a4512c071c67771c20001e7339317141c27ddcd14a566a45f35f115abe91ed9928939d9f3a0128f2738f44cd1dbc2ba0c6eb25d6cd89697fac9b3adfe727d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enfcli (3.10.4.pre.alpha)
4
+ enfcli (3.11.0.pre.alpha)
5
5
  rest-client (~> 2.0)
6
6
  terminal-table
7
7
  thor (~> 0.20.0)
data/lib/enfapi.rb CHANGED
@@ -558,12 +558,19 @@ module EnfApi
558
558
  raise EnfApi::ERROR, "AUTHORIZATION_ERROR: User is not authorized to perform this operation!"
559
559
 
560
560
  when 404
561
- # api returns and error
562
- raise EnfApi::ERROR, api_error_msg(from_json(response.body))
561
+ # api returns an error
562
+ # for the 404, we're going to check if it is JSON before parsing the
563
+ # error message
564
+ begin
565
+ JSON.parse(response.body)
566
+ raise EnfApi::ERROR, api_error_msg(from_json(response.body))
567
+ rescue JSON::ParserError => e
568
+ raise EnfApi::ERROR, "Not Found"
569
+ end
563
570
 
564
571
  else
565
572
  raise EnfApi::ERROR, "Unexpected error! Please try again!"
566
- end
573
+ end
567
574
  end
568
575
 
569
576
  def from_json(string)
@@ -18,6 +18,7 @@
18
18
  require 'enfthor'
19
19
  require 'enfapi'
20
20
  require 'json'
21
+ require 'erb'
21
22
 
22
23
  module EnfCli
23
24
  module Cmd
@@ -203,7 +204,8 @@ module EnfCli
203
204
  desc: 'DEVICE-ID is either the device serial number or its ipv6 address.'
204
205
  def get_device
205
206
  try_with_rescue_in_session do
206
- device_id = options[:'device-id']
207
+ device_id = ERB::Util::url_encode(options[:'device-id'])
208
+
207
209
  data = EnfApi::Captive.instance.get_device device_id
208
210
 
209
211
  display_device data
@@ -220,7 +222,7 @@ module EnfCli
220
222
  desc: 'UUID of the profile that the device will use. The profile must already exist.'
221
223
  def update_device
222
224
  try_with_rescue_in_session do
223
- id = options[:'device-id']
225
+ id = ERB::Util::url_encode(options[:'device-id'])
224
226
  name = options[:'device-name']
225
227
  profile_id = options[:'profile-id']
226
228
 
@@ -245,7 +247,7 @@ module EnfCli
245
247
  desc: 'DEVICE-ID is either the device serial number or its ipv6 address.'
246
248
  def get_device_status
247
249
  try_with_rescue_in_session do
248
- device_id = options[:'device-id']
250
+ device_id = ERB::Util::url_encode(options[:'device-id'])
249
251
  status = EnfApi::Captive.instance.get_device_status device_id
250
252
 
251
253
  display_device_status status
@@ -366,36 +368,36 @@ module EnfCli
366
368
  end
367
369
 
368
370
  # Display a single wifi configuration in detail
369
- def display_wifi_detail(wifi_data)
371
+ def display_wifi_detail(wifi_data, full_listing=true)
370
372
  name = wifi_data[:name]
371
- name = "\n" unless name
372
373
  wifi_id = wifi_data[:id]
373
- wifi_id = "\n" unless wifi_id
374
374
  desc = wifi_data[:description]
375
- desc = "\n" unless desc
376
375
  nets = wifi_data[:networks]
377
376
 
378
- say "Wifi ID : #{wifi_id}"
379
- say "Name : #{name}"
380
- say "Description : #{desc}"
381
- say "WiFi Networks :"
382
- if nets
383
- nets.each do |wifi_net|
384
- display_wifi_net(wifi_net, 1)
377
+ say "Wifi ID : #{wifi_id}", nil, true
378
+ say "Name : #{name}", nil, true
379
+ say "Description : #{desc}", nil, true if desc
380
+ if full_listing
381
+ say "WiFi Networks :"
382
+ if nets
383
+ nets.each do |wifi_net|
384
+ display_wifi_net(wifi_net, 1)
385
+ end
385
386
  end
387
+
386
388
  end
387
389
 
388
390
  end
389
391
 
390
392
  def display_wifi_net(wifi_net, tabs)
391
393
  indent = " " * tabs
392
- say indent + "Name : #{wifi_net[:name]}"
393
- say indent + " SSID :#{wifi_net[:SSID]}"
394
- say indent + " SSID type :#{wifi_net[:SSID_type]}"
394
+ say indent + "Name : #{wifi_net[:name]}", nil, true
395
+ say indent + " SSID : #{wifi_net[:SSID]}", nil, true
396
+ say indent + " SSID type : #{wifi_net[:SSID_type]}", nil, true
395
397
 
396
398
  auth = wifi_net[:auth]
397
399
  if auth
398
- say indent + " auth :#{auth[:type]}"
400
+ say indent + " auth : #{auth[:type]}", nil, true
399
401
  end
400
402
 
401
403
  display_ipv4_addr(wifi_net[:IPv4], tabs + 1) # these are subelements, so indent 1 more.
@@ -405,18 +407,18 @@ module EnfCli
405
407
  def display_ipv4_addr (ipv4, tabs)
406
408
  indent = " " * tabs
407
409
  if ipv4.instance_of? String
408
- say indent + "IPv4 :#{ipv4}"
410
+ say indent + "IPv4 : #{ipv4}", nil, true
409
411
  elsif ipv4.instance_of? NilClass
410
- say indent + "IPv4 :off"
412
+ say indent + "IPv4 : off"
411
413
  elsif ipv4.instance_of? Hash
412
414
  addr_type = ipv4[:type]
413
415
  if addr_type == "dhcp"
414
- say indent + "IPv4 :#{addr_type}"
416
+ say indent + "IPv4 : #{addr_type}"
415
417
  elsif addr_type == "static"
416
418
  addr = ipv4[:address]
417
419
  mask = ipv4[:mask]
418
420
  gw = ipv4[:gateway]
419
- say indent + "IPv4 :#{addr}/#{mask}/#{gw}"
421
+ say indent + "IPv4 : #{addr}/#{mask}/#{gw}", nil, true
420
422
  else
421
423
  say indent + "*** Invalid ipv4 address. Type is #{addr_type} ***"
422
424
  end
@@ -428,18 +430,18 @@ module EnfCli
428
430
  def display_ipv6_addr (ipv6, tabs)
429
431
  indent = " " * tabs
430
432
  if ipv6.instance_of? String
431
- say indent + "IPv6 :#{ipv6}"
433
+ say indent + "IPv6 : #{ipv6}", nil, true
432
434
  elsif ipv6.instance_of? NilClass
433
- say indent + "IPv6 :off"
435
+ say indent + "IPv6 : off"
434
436
  elsif ipv6.instance_of? Hash
435
437
  addr_type = ipv6[:type]
436
438
  if addr_type == "auto"
437
- say indent + "IPv6 :#{addr_type}"
439
+ say indent + "IPv6 : #{addr_type}"
438
440
  elsif addr_type == "static"
439
441
  addr = ipv6[:address]
440
442
  pref = ipv6[:prefix_length]
441
443
  gw = ipv6[:gateway]
442
- say indent + "IPv6 :#{addr}/#{pref}/#{gw}"
444
+ say indent + "IPv6 : #{addr}/#{pref}/#{gw}", nil, true
443
445
  else
444
446
  say indent + "*** Invalid ipv6 address. Type is #{addr_type} ***"
445
447
  end
@@ -463,18 +465,32 @@ module EnfCli
463
465
  profile = device_data[:profile]
464
466
  status = device_data[:status]
465
467
 
466
- say "Serial Number : #{device_data[:serial_number]}"
467
- say "Device Name : #{name}"
468
+ say "Serial Number : #{device_data[:serial_number]}", nil, true
469
+ say "Device Name : #{name}", nil, true
468
470
  say "Control Address : #{ctl_addr}" if ctl_addr
469
- say "Device Address : #{dev_addr}"
470
- say 'Mac Address :'
471
+ say "Device Address : #{dev_addr}", nil, true
471
472
  if mac_addrs
472
- say " 1 : #{mac_addrs[:'1']}"
473
- say " 2 : #{mac_addrs[:'2']}"
474
- say " 3 : #{mac_addrs[:'3']}"
475
- say " 4 : #{mac_addrs[:'4']}"
473
+ mac1 = mac_addrs[:'1']
474
+ mac2 = mac_addrs[:'2']
475
+ mac3 = mac_addrs[:'3']
476
+ mac4 = mac_addrs[:'4']
477
+
478
+ if !mac1
479
+ say 'Mac Address : < not available >'
480
+ elsif !mac2 && !mac3 && !mac4
481
+ say "Mac Address : #{mac1}", nil, true
482
+ else
483
+ say 'Mac Address :'
484
+ say " 1 : #{mac1}", nil, true
485
+ say " 2 : #{mac2}", nil, true if mac2
486
+ say " 3 : #{mac3}", nil, true if mac3
487
+ say " 4 : #{mac4}", nil, true if mac4
488
+ end
489
+ else
490
+ say 'Mac Address : < not available >'
476
491
  end
477
- say "Firmware Version : #{firmware}"
492
+
493
+ say "Firmware Version : #{firmware}", nil, true
478
494
  if profile
479
495
  say "Profile :"
480
496
  display_profile profile, true
@@ -482,7 +498,7 @@ module EnfCli
482
498
  say "Profile : < not available >"
483
499
  end
484
500
  display_device_status_summary status
485
- say ''
501
+ say ' ', nil, true
486
502
  end
487
503
 
488
504
  #
@@ -490,13 +506,12 @@ module EnfCli
490
506
  #
491
507
  def display_device_status_summary (device_status)
492
508
  if device_status
493
- mode = device_status[:router_mode]
494
- mode = device_status[:mode] unless mode
495
- mode = "\n" unless mode
509
+ mode = device_status[:router_mode] || device_status[:mode] || '< not available >'
510
+
496
511
  wifi = device_status[:wifi]
497
512
 
498
513
  say 'Status :'
499
- say " Router Mode : #{mode}"
514
+ say " Router Mode : #{mode}", nil, true
500
515
 
501
516
  if wifi
502
517
  connected = wifi[:connected] || " < unknown >"
@@ -514,44 +529,51 @@ module EnfCli
514
529
  # status is a hash matching the json structure
515
530
  #
516
531
  def display_device_status(device_status)
517
- sn = device_status[:serial_number]
518
- mode = device_status[:router_mode]
519
- mode = device_status[:mode] unless mode
520
- mode = "\n" unless mode
532
+ sn = device_status[:serial_number] || '< not available >'
533
+ mode = device_status[:router_mode] || device_status[:mode] || '< not available >'
521
534
 
522
- uptime = device_status[:uptime]
535
+ uptime = device_status[:uptime] || '< not available >'
523
536
  refresh = device_status[:refresh_time] || '< not available >'
524
- wifi_status = device_status[:wifi][:status]
525
- connected = wifi_status[:connected] || '< not available >'
526
- ssid = wifi_status[:SSID]
527
- ipv4 = wifi_status[:IPv4_addresses]
528
- ipv6 = wifi_status[:IPv6_addresses]
529
- wifi = device_status[:wifi][:config]
530
-
531
- say "Serial Number : #{sn}"
532
- say "Router Mode : #{mode}"
533
- say "Uptime (in seconds) : #{uptime}"
534
- say "Status refresh time : #{refresh}"
537
+
538
+ wifi = device_status[:wifi]
539
+ if wifi
540
+ connected = wifi[:connected] || '< not available >'
541
+ ssid = wifi[:SSID]
542
+ ipv4 = wifi[:IPv4_addresses]
543
+ ipv6 = wifi[:IPv6_addresses]
544
+ wifi_config = wifi[:config]
545
+ else
546
+ connected = '< not available >'
547
+ ssid = nil
548
+ ipv4 = nil
549
+ ipv6 = nil
550
+ wifi_config = nil
551
+ end
552
+
553
+ say "Serial Number : #{sn}", nil, true
554
+ say "Router Mode : #{mode}", nil, true
555
+ say "Uptime (in seconds) : #{uptime}", nil, true
556
+ say "Status refresh time : #{refresh}", nil, true
535
557
  say "WIFI :"
536
- say " connected : #{connected}"
558
+ say " connected : #{connected}", nil, true
537
559
  say " SSID : #{ssid}" if ssid
538
- if ipv4
539
- say " IPv4 addresses :"
560
+ if ipv4 && !ipv4.empty?
561
+ say " IPv4 addresses :"
540
562
  ipv4.each do |addr|
541
563
  display_ipv4_addr(addr, 2)
542
564
  end
543
565
  end
544
566
 
545
- if ipv6
546
- say " IPv6 addresses :"
567
+ if ipv6 && !ipv6.empty?
568
+ say " IPv6 addresses :"
547
569
  ipv6.each do |addr|
548
570
  display_ipv6_addr(addr, 2)
549
571
  end
550
572
  end
551
573
 
552
- display_wifi_detail(wifi) if wifi
574
+ display_wifi_detail(wifi_config, false) if wifi_config
553
575
 
554
- say ''
576
+ say ' ', nil, true
555
577
  end
556
578
 
557
579
  #
@@ -566,8 +588,10 @@ module EnfCli
566
588
  wifi = status[:wifi]
567
589
  connected = wifi ? wifi[:connected] : nil
568
590
  ssid = wifi ? wifi[:SSID] : nil
591
+ mode = status[:router_mode] || status[:mode]
592
+
569
593
  [hash[:serial_number], hash[:device_name], hash[:device_address],
570
- status[:router_mode], connected, ssid]
594
+ mode, connected, ssid]
571
595
  else
572
596
  [hash[:serial_number], hash[:device_name], hash[:device_address],
573
597
  nil, nil, nil]
@@ -586,11 +610,11 @@ module EnfCli
586
610
  def display_profile(profile, summary = false)
587
611
  indent = summary ? ' ' : ''
588
612
 
589
- say indent + "Name : #{profile[:name]}"
590
- say indent + "Profile ID : #{profile[:id]}"
591
- say indent + "Configuration version : #{profile[:config][:version]}"
613
+ say indent + "Name : #{profile[:name]}", nil, true
614
+ say indent + "Profile ID : #{profile[:id]}", nil, true
615
+ say indent + "Configuration version : #{profile[:config][:version]}", nil, true
592
616
  unless summary
593
- say "Mode :#{profile[:config][:mode]}"
617
+ say "Mode : #{profile[:config][:mode]}", nil, true
594
618
  display_wifi_summary profile[:config][:wifi]
595
619
  end
596
620
  end
@@ -601,13 +625,13 @@ module EnfCli
601
625
  def display_wifi_summary (wifi)
602
626
  if wifi
603
627
  say "Wifi config :"
604
- say " id :#{wifi[:id]}"
628
+ say " id : #{wifi[:id]}", nil, true
605
629
  # TODO - make accessible only to Xaptum admins
606
- say " domain :#{wifi[:domain]}"
607
- say " name :#{wifi[:name]}"
630
+ say " domain : #{wifi[:domain]}", nil, true
631
+ say " name : #{wifi[:name]}", nil, true
608
632
  desc = wifi[:description]
609
- say " description :#{desc}" if desc
610
- say " config version :#{wifi[:version]}"
633
+ say " description : #{desc}" if desc
634
+ say " config version : #{wifi[:version]}", nil, true
611
635
  else
612
636
  say "Wifi config : < not configured >"
613
637
  end
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module EnfCli
17
- VERSION = '3.10.4-alpha'
17
+ VERSION = '3.11.0-alpha'
18
18
  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.10.4.pre.alpha
4
+ version: 3.11.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-10-15 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor