def do_sign_ssh_agent(rsa_key, string_to_sign)
begin
require "net/ssh"
rescue LoadError => e
raise AuthenticationError, "net-ssh gem is not available, unable to use ssh-agent signing: #{e.message}"
end
begin
agent = Net::SSH::Authentication::Agent.connect
rescue Net::SSH::Authentication::AgentNotAvailable => e
raise AuthenticationError, "Could not connect to ssh-agent. Make sure the SSH_AUTH_SOCK environment variable is set and ssh-agent is running: #{e.message}"
end
begin
ssh2_signature = agent.sign(rsa_key.public_key, string_to_sign, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_256)
rescue Net::SSH::Authentication::AgentError => e
raise AuthenticationError, "Unable to sign request with ssh-agent. Make sure your key is loaded with ssh-add: #{e.class.name} #{e.message})"
end
ssh2_signature[20..-1]
end