Class: SshShort::KeySet
- Inherits:
-
Object
- Object
- SshShort::KeySet
- Defined in:
- lib/ssh_short/keyset.rb
Instance Method Summary collapse
- #get_key(key_name) ⇒ Object
-
#initialize(keys_dir) ⇒ KeySet
constructor
A new instance of KeySet.
- #prompt_for_key ⇒ Object
Constructor Details
#initialize(keys_dir) ⇒ KeySet
Returns a new instance of KeySet.
7 8 9 |
# File 'lib/ssh_short/keyset.rb', line 7 def initialize(keys_dir) @keys_dir = keys_dir end |
Instance Method Details
#get_key(key_name) ⇒ Object
27 28 29 30 31 |
# File 'lib/ssh_short/keyset.rb', line 27 def get_key(key_name) key = "#{@keys_dir}/#{key_name}" abort "Error: Cannot find #{key}" unless File.exist? key key end |
#prompt_for_key ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ssh_short/keyset.rb', line 11 def prompt_for_key abort "Error: Cannot find keys directory at #{@keys_dir}" unless File.exist? @keys_dir keys = Dir.glob("#{@keys_dir}/*").select{ |e| File.file? e } abort "Error: No keys found in #{@keys_dir}" unless keys.count > 0 key_names = keys.collect { |key| File.basename key } puts 'Select a key:' key_names.each_with_index { |key_name, i| puts "#{i}) #{key_name}" } key_selection = STDIN.gets.to_i abort "#{key_selection} is not a valid key" if (key_selection >= key_names.count) key_names[key_selection] end |