Class: Conjure::Service::ForwardedShell

Inherits:
Object
  • Object
show all
Defined in:
lib/conjure/service/forwarded_shell.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ForwardedShell

Returns a new instance of ForwardedShell.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/conjure/service/forwarded_shell.rb', line 4

def initialize(options)
  @shell = options[:shell].prepare(
    :label => "forwarded",
    :setup_commands => [
      "apt-get install -y openssh-server",
      "mkdir -p /var/run/sshd",
      "mkdir -p /root/.ssh; echo '#{options[:public_key]}' > /root/.ssh/authorized_keys",
      "chmod 600 /root/.ssh/authorized_keys"
    ],
  )
end

Instance Method Details

#command(c) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/conjure/service/forwarded_shell.rb', line 16

def command(c)
  container = @shell.run "/usr/sbin/sshd -D -e"
  escaped_command = @shell.docker_host.shell_escape c
  ssh_command = "ssh -A -o StrictHostKeyChecking=no -o PasswordAuthentication=no #{container.ip_address} '#{escaped_command}'"
  result = @shell.docker_host.server.run ssh_command
  result.stdout
end