Module: SshKeySwitcher::Utils::Helper
- Includes:
- Contains
- Defined in:
- lib/ssh_key_switcher/utils/helper.rb
Constant Summary
Constants included
from Contains
Contains::SERVER_NAMES, Contains::SSH_DIR, Contains::STRING_DETECT_OPENSSH_KEY
Class Method Summary
collapse
Class Method Details
.find_open_ssh_keys ⇒ Object
10
11
12
13
14
|
# File 'lib/ssh_key_switcher/utils/helper.rb', line 10
def find_open_ssh_keys
ssh_folder = File.expand_path(SSH_DIR)
Dir.glob("#{ssh_folder}/*").select { |file| valid_ssh_key?(file) }.sort
end
|
.valid_ssh_key?(file) ⇒ Boolean
16
17
18
19
20
21
22
23
24
|
# File 'lib/ssh_key_switcher/utils/helper.rb', line 16
def valid_ssh_key?(file)
File.open(file, 'rb') do |f|
= f.read(20)
.include?(STRING_DETECT_OPENSSH_KEY)
end
rescue StandardError
false
end
|