Module: KnifeSSHAgent::Authenticator

Defined in:
lib/knife/ssh-agent/authenticator.rb

Instance Method Summary collapse

Instance Method Details

#load_agent_default_identObject



26
27
28
29
30
31
32
33
34
# File 'lib/knife/ssh-agent/authenticator.rb', line 26

def load_agent_default_ident
  agent = Net::SSH::Authentication::Agent.connect
  ident = agent.identities.select { |id| id.ssh_type == 'ssh-rsa' }

  raise AgentException, 'cannot retrieve a valid RSA key from the SSH agent' if ident.empty?
  ident.first
ensure
  agent&.close
end

#load_ident_file(path) ⇒ Object



19
20
21
22
23
24
# File 'lib/knife/ssh-agent/authenticator.rb', line 19

def load_ident_file(path)
  file = [path + '.pub'].find(path) { |f| ::File.exist?(::File.expand_path(f)) }
  Net::SSH::KeyFactory.load_public_key(file)
rescue Net::SSH::Exception
  raise AgentException, "unable to find requested SSH identity: #{path}"
end

#load_signing_key(key_file, raw_key = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/knife/ssh-agent/authenticator.rb', line 6

def load_signing_key(key_file, raw_key = nil)
  use_agent  = Chef::Config[:knife][:use_ssh_agent]
  ident_file = Chef::Config[:knife][:ssh_agent_identity]

  return super(key_file, raw_key) unless use_agent

  @key = if ident_file
           load_ident_file(ident_file)
         else
           load_agent_default_ident
         end
end