enfcli 3.5.0 → 3.5.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 131b57ab3f2a4584c8474f155f551361ba8668cb502b7cbe305fb822dedc9544
4
- data.tar.gz: 411cb6af276ea545f7a7d991cb5e2726dad76ec69e5500b74e4855fef196185b
3
+ metadata.gz: e6af8d561223bdd6c26e0eba12c88a4a299053483aac5b011c37dd509a72835e
4
+ data.tar.gz: 8bcd07d80348541069042dd5e27b5c8b23476881add8df2f24ed9afc8546d21f
5
5
  SHA512:
6
- metadata.gz: bbfd0d2f80f9610ebcca20c3ce574fbad97a8639cb39db73cfc1fb0611c3f4612714a5050d88e3762686ca98d8305a15cf444381cfbf4bfdb7018b3ec2b8a971
7
- data.tar.gz: 2df4253529a69a7d80d8100108dd997f35de16a9fb18446da3c4d646de797c641e524ce372a7ec6f17c0ad8e8704a552cddbb28c76aa9d03d17073c8d2b7c613
6
+ metadata.gz: dd995bff0e655b7011998377eb30f5a6ff8d615481a469332efad4c2ac2fbab33f06d604664d5e89f4b737c7f305a3f97e9d8bca314a28a112d39bd8e2efdb78
7
+ data.tar.gz: 6fdbd6f6a9d8ae5c3eb1db554c233fc9b57e7fef2d213e8f313055b6f377645ee7600a7fd97d762905a8360289cfa1846200933f8fb4f4df63996811fd4bf1aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enfcli (3.5.0)
4
+ enfcli (3.5.2.pre.alpha)
5
5
  rest-client (~> 2.0)
6
6
  terminal-table
7
7
  thor (~> 0.20.0)
@@ -78,4 +78,4 @@ DEPENDENCIES
78
78
  webmock
79
79
 
80
80
  BUNDLED WITH
81
- 2.0.1
81
+ 2.0.2
data/lib/enfapi.rb CHANGED
@@ -187,7 +187,7 @@ module EnfApi
187
187
 
188
188
  ##############################################################################
189
189
  #
190
- # Captive
190
+ # Captive
191
191
  #
192
192
  ##############################################################################
193
193
  class Captive
@@ -212,7 +212,7 @@ module EnfApi
212
212
  EnfApi::API.instance.get url
213
213
  end
214
214
 
215
- # Update an existing wifi configuration
215
+ # Update an existing wifi configuration
216
216
  ## NO_TEST
217
217
  def update_wifi_configuration(wifi_id, updated_wifi_config)
218
218
  json = EnfApi::to_json(updated_wifi_config)
@@ -241,6 +241,12 @@ module EnfApi
241
241
  EnfApi::API.instance.get "/api/captive/v1/device/#{dev_id}"
242
242
  end
243
243
 
244
+ # Get the status of a device
245
+ ## NO_TEST
246
+ def get_device_status(dev_id)
247
+ EnfApi::API.instance.get "/api/captive/v1/device/#{dev_id}/status"
248
+ end
249
+
244
250
  # Post the new profile
245
251
  ## NO_TEST
246
252
  def create_profile(new_profile_hash)
@@ -271,7 +277,7 @@ module EnfApi
271
277
  EnfApi::API.instance.put "/api/captive/v1/profile/#{id}", json
272
278
  end
273
279
  end
274
-
280
+
275
281
  class NetworkManager
276
282
  include Singleton
277
283
  end
@@ -536,6 +542,10 @@ module EnfApi
536
542
  # api returns and error
537
543
  raise EnfApi::ERROR, "AUTHORIZATION_ERROR: User is not authorized to perform this operation!"
538
544
 
545
+ when 404
546
+ # api returns and error
547
+ raise EnfApi::ERROR, api_error_msg(from_json(response.body))
548
+
539
549
  else
540
550
  raise EnfApi::ERROR, "Unexpected error! Please try again!"
541
551
  end
@@ -197,6 +197,20 @@ module EnfCli
197
197
  end
198
198
  end
199
199
 
200
+ desc 'get-device-status',
201
+ 'Get the latest status of the specified device.'
202
+ method_option :'device-id', required: true, type: :string,
203
+ banner: 'DEVICE-ID',
204
+ desc: 'DEVICE-ID is either the device serial number or its ipv6 address.'
205
+ def get_device_status
206
+ try_with_rescue_in_session do
207
+ device_id = options[:'device-id']
208
+ status = EnfApi::Captive.instance.get_device_status device_id
209
+
210
+ display_device_status status
211
+ end
212
+ end
213
+
200
214
  desc 'create-profile',
201
215
  'Create a new profile.'
202
216
  method_option :'profile-name', type: :string, required: true,
@@ -311,33 +325,37 @@ module EnfCli
311
325
  # Display a single wifi configuration in detail
312
326
  def display_wifi_detail(wifi_data)
313
327
  name = wifi_data[:name]
328
+ name = "\n" unless name
314
329
  wifi_id = wifi_data[:id]
315
330
  desc = wifi_data[:description]
316
- configs = wifi_data[:config]
331
+ desc = "\n" unless desc
332
+ nets = wifi_data[:networks]
317
333
 
318
334
  say "Wifi ID : #{wifi_id}"
319
335
  say "Name : #{name}"
320
336
  say "Description : #{desc}"
321
337
  say "WiFi Networks :"
322
- configs.each do |wifi_net|
323
- display_wifi_net(wifi_net, 1)
338
+ if nets
339
+ nets.each do |wifi_net|
340
+ display_wifi_net(wifi_net, 1)
341
+ end
324
342
  end
325
343
 
326
344
  end
327
345
 
328
346
  def display_wifi_net(wifi_net, tabs)
329
347
  indent = " " * tabs
330
- say "Name : #{wifi_net[:name]}"
331
- say indent + "SSID :#{wifi_net[:SSID]}"
332
- say indent + "SSID type :#{wifi_net[:SSID_type]}"
348
+ say indent + "Name : #{wifi_net[:name]}"
349
+ say indent + " SSID :#{wifi_net[:SSID]}"
350
+ say indent + " SSID type :#{wifi_net[:SSID_type]}"
333
351
 
334
352
  auth = wifi_net[:auth]
335
353
  if auth
336
- say indent + "auth :#{auth[:type]}"
354
+ say indent + " auth :#{auth[:type]}"
337
355
  end
338
356
 
339
- display_ipv4_addr(wifi_net[:IPv4], tabs)
340
- display_ipv6_addr(wifi_net[:IPv6], tabs)
357
+ display_ipv4_addr(wifi_net[:IPv4], tabs + 1) # these are subelements, so indent 1 more.
358
+ display_ipv6_addr(wifi_net[:IPv6], tabs + 1)
341
359
  end
342
360
 
343
361
  def display_ipv4_addr (ipv4, tabs)
@@ -398,16 +416,19 @@ module EnfCli
398
416
  dev_addr = device_data[:device_address]
399
417
  mac_addrs = device_data[:mac_address]
400
418
  firmware = device_data[:firmware_version]
419
+ firmware = '< not available >' unless firmware
401
420
  profile_id = device_data[:profile]
421
+ profile_id = '< not available >' unless profile_id
402
422
  status = device_data[:status]
423
+ status = '< not available >' unless status
403
424
 
404
425
  say "Serial Number : #{device_data[:serial_number]}"
405
426
  say "Device Name : #{name}"
406
- say "Control Address : #{ctl_addr}"
427
+ say "Control Address : #{ctl_addr}" if ctl_addr
407
428
  say "Device Address : #{dev_addr}"
408
429
  say 'Mac Address :'
409
430
  if mac_addrs
410
- say " 1 : #{mac_addrs[:wifi]}"
431
+ say " 1 : #{mac_addrs[:'1']}"
411
432
  say " 2 : #{mac_addrs[:'2']}"
412
433
  say " 3 : #{mac_addrs[:'3']}"
413
434
  say " 4 : #{mac_addrs[:'4']}"
@@ -415,6 +436,50 @@ module EnfCli
415
436
  say "Firmware Version : #{firmware}"
416
437
  say "Profile ID : #{profile_id}"
417
438
  say "Status : #{status}"
439
+ say ''
440
+ end
441
+
442
+ #
443
+ # display the status of the device.
444
+ # status is a hash matching the json structure
445
+ #
446
+ def display_device_status(device_status)
447
+ sn = device_status[:serial_number]
448
+ mode = device_status[:router_mode]
449
+ uptime = device_status[:uptime]
450
+ refresh = device_status[:refresh_time]
451
+ connected = device_status[:wifi][:connected]
452
+ ssid = device_status[:wifi][:SSID]
453
+ ipv4 = device_status[:wifi][:IPv4_addresses]
454
+ ipv6 = device_status[:wifi][:IPv6_addresses]
455
+ wifi = device_status[:wifi][:config]
456
+
457
+ say "Serial Number : #{sn}"
458
+ say "Router Mode : #{mode}"
459
+ say "Uptime (in seconds) : #{uptime}"
460
+ say "Status refresh time : #{refresh}"
461
+ say "WIFI :"
462
+ say " connected : #{connected}"
463
+ say " SSID : #{ssid}"
464
+ if ipv4
465
+ say " IPv4 addresses :"
466
+ ipv4.each do |addr|
467
+ display_ipv4_addr(addr, 2)
468
+ end
469
+ end
470
+
471
+ if ipv6
472
+ say " IPv6 addresses :"
473
+ ipv6.each do |addr|
474
+ display_ipv6_addr(addr, 2)
475
+ end
476
+ end
477
+
478
+ if wifi
479
+ display_wifi_detail(wifi)
480
+ end
481
+
482
+ say ''
418
483
  end
419
484
 
420
485
  #
@@ -17,7 +17,7 @@ require 'enfthor'
17
17
  require 'enfapi'
18
18
 
19
19
  module EnfCli
20
-
20
+
21
21
  module Cmd
22
22
 
23
23
  class User < EnfThor
@@ -30,7 +30,7 @@ module EnfCli
30
30
 
31
31
  render_table(headings, rows)
32
32
  end
33
-
33
+
34
34
  def display_users users
35
35
  headings = ['User Name', 'Full Name', 'Last Login', 'Type', 'Reset Code', 'Reset Time']
36
36
  rows = users.map{ |hash|
@@ -39,34 +39,13 @@ module EnfCli
39
39
  render_table(headings, rows)
40
40
  end
41
41
 
42
- def send_invite options, user_type
42
+ def send_invite options, user_type
43
43
  # Get options
44
44
  domain_network = options.domain
45
-
46
- # Get user role
47
- user_role = EnfCli::CTX.instance.session[:type]
48
-
49
- # check user roles
50
- if user_role == "XAPTUM_ADMIN"
51
- # make sure that a domain is specified in domain option for XAPTUM_ADMIN
52
- raise EnfCli::ERROR, "No domain specified. Please use --domain option!" unless domain_network
53
- else
54
- # use the domain network of the user
55
- domain_network = EnfCli::CTX.instance.session[:domain_network]
56
- raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
57
- end
58
45
 
59
46
  # get params
60
- case user_type
61
- when "DOMAIN_USER"
62
- name = options[:'name'].join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
63
- email = options[:'email']
64
-
65
- when "DOMAIN_ADMIN"
66
- name = options[:'admin-name'].join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
67
- email = options[:'admin-email']
68
-
69
- end
47
+ name = options[:'name'].join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
48
+ email = options[:'email']
70
49
 
71
50
  # call api
72
51
  hash = { :email => email, :full_name => name, :welcome_text => "", :user_type => user_type }
@@ -82,21 +61,95 @@ module EnfCli
82
61
  method_option :'email', :type => :string, :required => true, :banner => "EMAIL"
83
62
  def invite_read_only_user
84
63
  try_with_rescue_in_session do
85
- send_invite options, "DOMAIN_USER"
64
+ # use the domain network of the user
65
+ domain_network = EnfCli::CTX.instance.session[:domain_network]
66
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
67
+
68
+ # Get user role
69
+ user_role = EnfCli::CTX.instance.session[:type]
70
+
71
+ # check user roles
72
+ if user_role == "XAPTUM_ADMIN"
73
+ domain_network = options[:domain] if options[:domain]
74
+ else
75
+ say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow if options[:domain]
76
+ end
77
+
78
+ send_invite options, "DOMAIN_USER"
86
79
  end
87
80
  end
88
81
 
89
- desc "invite-admin-user", "Invite a domain administrator"
82
+ desc "invite-domain-admin-user", "Invite a domain administrator"
90
83
  method_option :domain, :default => nil, :type => :string, :aliases => "-d"
91
- method_option :'admin-name', :type => :array, :required => true, :banner => "NAME"
92
- method_option :'admin-email', :type => :string, :required => true, :banner => "EMAIL"
93
- def invite_admin_user
84
+ method_option :'name', :type => :array, :required => true, :banner => "NAME"
85
+ method_option :'email', :type => :string, :required => true, :banner => "EMAIL"
86
+ def invite_domain_admin_user
94
87
  try_with_rescue_in_session do
95
- send_invite options, "DOMAIN_ADMIN"
88
+ # use the domain network of the user
89
+ domain_network = EnfCli::CTX.instance.session[:domain_network]
90
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
91
+
92
+ # Get user role
93
+ user_role = EnfCli::CTX.instance.session[:type]
94
+
95
+ # check user roles
96
+ if user_role == "XAPTUM_ADMIN"
97
+ domain_network = options[:domain] if options[:domain]
98
+ else
99
+ say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow if options[:domain]
100
+ end
101
+
102
+ send_invite options, "DOMAIN_ADMIN"
96
103
  end
97
104
  end
98
105
 
99
-
106
+ desc "invite-enf-admin-user", "Invite an ENF administrator"
107
+ method_option :'name', :type => :array, :required => true, :banner => "NAME"
108
+ method_option :'email', :type => :string, :required => true, :banner => "EMAIL"
109
+ def invite_enf_admin_user
110
+ try_with_rescue_in_session do
111
+ # Get user role
112
+ user_role = EnfCli::CTX.instance.session[:type]
113
+
114
+ raise EnfCli::ERROR, "Only ENF Administrators can invite ENF Administrator" unless user_role == "XAPTUM_ADMIN"
115
+
116
+ options[:domain] = EnfCli::CTX.instance.session[:domain_network]
117
+ send_invite options, "XAPTUM_ADMIN"
118
+ end
119
+ end
120
+
121
+ desc "invite-iam-admin-user", "Invite an IAM administrator"
122
+ method_option :'name', :type => :array, :required => true, :banner => "NAME"
123
+ method_option :'email', :type => :string, :required => true, :banner => "EMAIL"
124
+ def invite_iam_admin_user
125
+ try_with_rescue_in_session do
126
+ # Get user role
127
+ user_role = EnfCli::CTX.instance.session[:type]
128
+
129
+ raise EnfCli::ERROR, "Only ENF Administrators can invite IAM Administrator" unless user_role == "XAPTUM_ADMIN"
130
+
131
+ options[:domain] = EnfCli::CTX.instance.session[:domain_network]
132
+ send_invite options, "IAM_ADMIN"
133
+ end
134
+ end
135
+
136
+ desc "invite-captive-admin-user", "Invite a captive administrator"
137
+ method_option :'captive-domain', :type => :string, :required => true, :banner => "CAPTIVE CONTROL DOMAIN"
138
+ method_option :'name', :type => :array, :required => true, :banner => "NAME"
139
+ method_option :'email', :type => :string, :required => true, :banner => "EMAIL"
140
+ def invite_captive_admin_user
141
+ try_with_rescue_in_session do
142
+ # Get user role
143
+ user_role = EnfCli::CTX.instance.session[:type]
144
+
145
+ raise EnfCli::ERROR, "Only ENF Administrators can invite CAPTIVE Administrator" unless user_role == "XAPTUM_ADMIN"
146
+
147
+ options[:domain] = options[:'captive-domain']
148
+ send_invite options, "CAPTIVE_ADMIN"
149
+ end
150
+ end
151
+
152
+
100
153
  desc "cancel-user-invite", "Cancel an invite"
101
154
  method_option :email, :type => :string, :required => true
102
155
  def cancel_user_invite
@@ -120,25 +173,23 @@ module EnfCli
120
173
  say "Resent invite email!", :green
121
174
  end
122
175
  end
123
-
124
- desc "list-domain-invites", "List domain invites"
176
+
177
+ desc "list-invites", "List user invites"
125
178
  method_option :domain, :default => nil, :type => :string, :aliases => "-d"
126
- def list_domain_invites
179
+ def list_invites
127
180
  try_with_rescue_in_session do
128
- # Get options
129
- domain_network = options.domain
130
-
181
+ # use the domain network of the user
182
+ domain_network = EnfCli::CTX.instance.session[:domain_network]
183
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
184
+
131
185
  # Get user role
132
186
  user_role = EnfCli::CTX.instance.session[:type]
133
187
 
134
188
  # check user roles
135
189
  if user_role == "XAPTUM_ADMIN"
136
- # make sure that a domain is specified in domain option for XAPTUM_ADMIN
137
- raise EnfCli::ERROR, "No domain specified. Please use --domain option!" unless domain_network
190
+ domain_network = options[:domain] if options[:domain]
138
191
  else
139
- # use the domain network of the user
140
- domain_network = EnfCli::CTX.instance.session[:domain_network]
141
- raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
192
+ say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow if options[:domain]
142
193
  end
143
194
 
144
195
  # call the api
@@ -147,26 +198,24 @@ module EnfCli
147
198
 
148
199
  display_invites invites
149
200
  end
150
- end
201
+ end
151
202
 
152
- desc "list-domain-users", "List domain users"
203
+ desc "list-users", "List users"
153
204
  method_option :domain, :default => nil, :type => :string, :aliases => "-d"
154
- def list_domain_users
205
+ def list_users
155
206
  try_with_rescue_in_session do
156
- # Get options
157
- domain_network = options.domain
158
-
207
+ # use the domain network of the user
208
+ domain_network = EnfCli::CTX.instance.session[:domain_network]
209
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
210
+
159
211
  # Get user role
160
212
  user_role = EnfCli::CTX.instance.session[:type]
161
213
 
162
214
  # check user roles
163
215
  if user_role == "XAPTUM_ADMIN"
164
- # make sure that a domain is specified in domain option for XAPTUM_ADMIN
165
- raise EnfCli::ERROR, "No domain specified. Please use --domain option!" unless domain_network
216
+ domain_network = options[:domain] if options[:domain]
166
217
  else
167
- # use the domain network of the user
168
- domain_network = EnfCli::CTX.instance.session[:domain_network]
169
- raise EnfCli::ERROR, "User not in a valid domain!" unless domain_network
218
+ say "Warning: Ignoring command option -d #{options[:domain]}", :yellow if options[:domain]
170
219
  end
171
220
 
172
221
  # call the api
@@ -177,9 +226,9 @@ module EnfCli
177
226
  end
178
227
  end
179
228
 
180
-
229
+
181
230
  end
182
-
231
+
183
232
  end
184
233
 
185
234
  end
@@ -278,7 +278,8 @@ module EnfCli
278
278
 
279
279
  desc "create-record", "Create a DNS record"
280
280
  method_option :'zone-id', :type => :string, :required => true
281
- method_option :name, :type => :string, :required => true
281
+ method_option :name, :type => :string, :required => true, :banner => '<name>',
282
+ :desc => '<name> is DNS record name. Enter . to create a record with the zone domain name'
282
283
  method_option :'type', :type => :string, :required => true, :enum => DnsRecordTypes
283
284
  method_option :ttl, :type => :numeric, :required => true
284
285
  method_option :value, :type => :array, :required => true, :banner => 'VALUE'
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module EnfCli
17
- VERSION = '3.5.0'
17
+ VERSION = '3.5.2-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.5.0
4
+ version: 3.5.2.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-07-09 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -209,9 +209,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - ">="
212
+ - - ">"
213
213
  - !ruby/object:Gem::Version
214
- version: '0'
214
+ version: 1.3.1
215
215
  requirements: []
216
216
  rubygems_version: 3.0.1
217
217
  signing_key: