Class: SSHKit::EC2InstanceConnect::Backend

Inherits:
Backend::Abstract
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sshkit/ec2instanceconnect/backend.rb

Overview

SSHKit backend that integrates with EC2 Instance Connect.

It ensures that SSH keys are automatically created and send to the server before executing any command. It also ensures a timely refresh of the SSH key before it expires.

Constant Summary collapse

EXPIRES_IN =

SSH keys using EC2 Instance Connect are valid for 60 seconds, so refresh them a bit earlier.

50

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Backend

Returns a new instance of Backend.



38
39
40
41
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 38

def initialize(host, &)
  super
  @backend = SSHKit::Backend::Netssh.new(host)
end

Class Attribute Details

.ssh_keysObject

Returns the value of attribute ssh_keys.



29
30
31
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 29

def ssh_keys
  @ssh_keys
end

.tunnelsObject

Returns the value of attribute tunnels.



29
30
31
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 29

def tunnels
  @tunnels
end

Class Method Details

.configureObject



43
44
45
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 43

def self.configure(&)
  SSHKit::Backend::Netssh.configure(&)
end

Instance Method Details

#download!(remote, local = nil, options = {}) ⇒ Object



52
53
54
55
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 52

def download!(remote, local = nil, options = {})
  ensure_connection
  @backend.send(:download!, remote, local, options)
end

#execute_command(cmd) ⇒ Object



57
58
59
60
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 57

def execute_command(cmd)
  ensure_connection
  @backend.send(:execute_command, cmd)
end

#upload!(local, remote, options = {}) ⇒ Object



47
48
49
50
# File 'lib/sshkit/ec2instanceconnect/backend.rb', line 47

def upload!(local, remote, options = {})
  ensure_connection
  @backend.send(:upload!, local, remote, options)
end