Class: Legate::CLI::AuthMappingCommands
Overview
URL mapping management subcommands
Instance Method Summary
collapse
#auth_manager, #credential_type_description, #mask_sensitive_value, #print_header, #print_row, #scheme_type_description, #sensitive_field?
Methods inherited from BaseCommand
#tree
Instance Method Details
#create ⇒ Object
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
# File 'lib/legate/cli/auth_commands.rb', line 439
def create
scheme_name = options[:scheme].to_sym
cred_name = options[:credential].to_sym
unless auth_manager.get_scheme(scheme_name)
puts ::CLI::UI.fmt("{{red:Scheme not found:}} #{options[:scheme]}")
exit 1
end
unless auth_manager.get_credential(cred_name)
puts ::CLI::UI.fmt("{{red:Credential not found:}} #{options[:credential]}")
exit 1
end
pattern = if options[:regex]
begin
Regexp.new(options[:pattern])
rescue RegexpError => e
puts ::CLI::UI.fmt("{{red:Invalid regex:}} #{e.message}")
exit 1
end
else
options[:pattern]
end
auth_manager.register_url_mapping(pattern, scheme_name, cred_name)
puts ::CLI::UI.fmt('{{green:✓}} URL mapping created successfully')
end
|
#delete(index) ⇒ Object
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/legate/cli/auth_commands.rb', line 469
def delete(index)
idx = index.to_i
mappings = auth_manager.instance_variable_get(:@url_mappings) || []
if idx < 0 || idx >= mappings.size
puts ::CLI::UI.fmt("{{red:Invalid index:}} #{index} (valid range: 0-#{mappings.size - 1})")
exit 1
end
auth_manager.remove_url_mapping(idx)
puts ::CLI::UI.fmt("{{green:✓}} URL mapping [#{index}] deleted")
end
|
#list ⇒ Object
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
# File 'lib/legate/cli/auth_commands.rb', line 413
def list
mappings = auth_manager.instance_variable_get(:@url_mappings) || []
if mappings.empty?
puts ::CLI::UI.fmt('{{yellow:No URL mappings registered.}}')
return
end
("URL Mappings (#{mappings.size})")
puts
mappings.each_with_index do |mapping, idx|
pattern = mapping[:pattern].is_a?(Regexp) ? mapping[:pattern].source : mapping[:pattern].to_s
pattern_type = mapping[:pattern].is_a?(Regexp) ? 'regex' : 'string'
puts ::CLI::UI.fmt(" {{bold:[#{idx}]}} #{pattern} {{gray:(#{pattern_type})}}")
puts " Scheme: #{mapping[:scheme_name]}, Credential: #{mapping[:credential_name]}"
puts
end
end
|