Class: EnfCli::Cmd::Xiam
Instance Method Summary
collapse
Methods inherited from EnfThor
capture_stdout, command_help, handle_argument_error, help
Instance Method Details
#add_group_to_network ⇒ Object
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/enfcli/commands/xiam.rb', line 268
def add_group_to_network
try_with_rescue_in_session do
network = EnfCli::IPV6Cidr.new(options[:network]).to_s
if options[:gid]
gid = options[:gid]
else
gid = scan_gid
end
if options[:set_as_default]
modified_group = {
:gid => gid,
:default_network => network,
}
EnfApi::Iam.instance.update_group gid, modified_group
say "Associated group #{gid} with #{network} as default network", :green
else
EnfApi::Iam.instance.add_group_to_network gid, network
say "Associated group #{gid} with #{network}", :green
end
end
end
|
#create_endpoint_cert ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
# File 'lib/enfcli/commands/xiam.rb', line 364
def create_endpoint_cert
try_with_rescue_in_session do
ipv6 = EnfCli::IPV6.new(options["identity"]).to_s
keyfile = EnfCli::expand_path(options["key-in-file"])
certfile = EnfCli::expand_path(options["cert-out-file"])
key = read_ec_key_file keyfile
cert = EnfCli::generate_ec_cert(key, ipv6)
write_pem_file certfile, cert.to_pem
end
end
|
#create_endpoint_from_cert ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
# File 'lib/enfcli/commands/xiam.rb', line 442
def create_endpoint_from_cert
try_with_rescue_in_session do
certfile = EnfCli::expand_path(options["cert-in-file"])
raise EnfCli::ERROR, "#{certfile} does not exist!" unless File.exists?(certfile)
rawcert = File.read certfile
cert = OpenSSL::X509::Certificate.new rawcert
subject = cert.subject.to_a
cn = subject.select { |d| "CN".eql?(d[0].upcase) }
ipv6_address = EnfCli::IPV6.new cn[0][1]
pub = cert.public_key.public_key
provision_endpoint ipv6_address, pub
end
end
|
#create_endpoint_in_network ⇒ Object
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
# File 'lib/enfcli/commands/xiam.rb', line 386
def create_endpoint_in_network
try_with_rescue_in_session do
network = EnfCli::IPV6Cidr.new(options[:network]).to_s
keyfile = EnfCli::expand_path(options["public-key-in-file"])
key = read_ec_key_file keyfile
pub = key.public_key
pubkey = pub.to_bn.to_s(16)
new_credential = {
:type => "ecdsa_p256",
:key => pubkey,
}
new_endpoint = {
:ecdsa_credential => new_credential,
:address_request => {
:network => network,
},
}
data = EnfApi::Iam.instance.provision_endpoint new_endpoint
provisioned_ip = data[:address]
say "Created new ipv6 endpoint #{provisioned_ip}", :green
end
end
|
#create_endpoint_key ⇒ Object
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
# File 'lib/enfcli/commands/xiam.rb', line 340
def create_endpoint_key
try_with_rescue_in_session do
keyfile = options["key-out-file"]
pubfile = options["public-key-out-file"]
key = OpenSSL::PKey::EC.new("prime256v1")
key.generate_key
write_pem_file keyfile, key.to_pem
key.private_key = nil
write_pem_file pubfile, key.to_pem
end
end
|
#create_endpoint_with_address ⇒ Object
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'lib/enfcli/commands/xiam.rb', line 424
def create_endpoint_with_address
try_with_rescue_in_session do
ipv6_address = EnfCli::IPV6.new options[:address]
keyfile = EnfCli::expand_path(options["public-key-in-file"])
key = read_ec_key_file keyfile
pub = key.public_key
provision_endpoint ipv6_address, pub
end
end
|
#get_group ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/enfcli/commands/xiam.rb', line 162
def get_group
try_with_rescue_in_session do
if options[:gid]
gid = options[:gid]
else
gid = scan_gid
end
data = EnfApi::Iam.instance.get_group gid
groups = [data]
display_groups groups
end
end
|
#list_groups ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/enfcli/commands/xiam.rb', line 183
def list_groups
try_with_rescue_in_session do
if options[:network]
network = EnfCli::IPV6Cidr.new options[:network]
data = EnfApi::Iam.instance.list_network_groups network.to_s
else
data = EnfApi::Iam.instance.list_groups
end
groups = data[:body]
display_groups groups
end
end
|
#provision_group ⇒ Object
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/enfcli/commands/xiam.rb', line 298
def provision_group
try_with_rescue_in_session do
qr_code_info = scan_group_qr_code()
gpk_info = qr_code_info.split(",")
basename = gpk_info[0]
gpk = gpk_info[1]
gid = calculate_gid basename, gpk
operator = options.operator.join(" ").gsub(/\A"+(.*?)"+\Z/m, '\1')
quantity = options[:'device-count']
new_provisioning = {
:group_id => gid,
:quantity => quantity,
:operator => operator,
}
new_group = {
:group_public_key => gpk,
:basename => basename,
:provisionings => [new_provisioning],
}
EnfApi::Iam.instance.provision_group new_group
say "Provisioned a new DAA group #{gid}", :green
end
end
|
#set_group_default_network ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/enfcli/commands/xiam.rb', line 211
def set_group_default_network
try_with_rescue_in_session do
network = EnfCli::IPV6Cidr.new(options[:network]).to_s
if options[:gid]
gid = options[:gid]
else
gid = scan_gid
end
modified_group = {
:gid => gid,
:default_network => network,
}
EnfApi::Iam.instance.update_group gid, modified_group
say "Set #{network} as default network for group #{gid}", :green
end
end
|
#set_group_domain ⇒ Object
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/enfcli/commands/xiam.rb', line 239
def set_group_domain
try_with_rescue_in_session do
domain = EnfCli::IPV6Cidr.new(options[:domain]).to_s
if options[:gid]
gid = options[:gid]
else
gid = scan_gid
end
modified_group = {
:gid => gid,
:domain => domain,
}
EnfApi::Iam.instance.update_group gid, modified_group
say "Associated group #{gid} with #{domain}", :green
end
end
|
#update_endpoint_cert ⇒ Object
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
# File 'lib/enfcli/commands/xiam.rb', line 489
def update_endpoint_cert
try_with_rescue_in_session do
certfile = EnfCli::expand_path(options["cert-in-file"])
raise EnfCli::ERROR, "#{certfile} does not exist!" unless File.exists?(certfile)
rawcert = File.read certfile
cert = OpenSSL::X509::Certificate.new rawcert
subject = cert.subject.to_a
cn = subject.select { |d| "CN".eql?(d[0].upcase) }
ipv6_address = EnfCli::IPV6.new cn[0][1]
pub = cert.public_key.public_key
update_endpoint_credentials ipv6_address, pub
end
end
|
#update_endpoint_key ⇒ Object
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/enfcli/commands/xiam.rb', line 471
def update_endpoint_key
try_with_rescue_in_session do
ipv6_address = EnfCli::IPV6.new options[:address]
keyfile = EnfCli::expand_path(options["public-key-in-file"])
key = read_ec_key_file keyfile
pub = key.public_key
update_endpoint_credentials ipv6_address, pub
end
end
|