Class: Bosh::Cli::SSHSession

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/ssh_session.rb

Constant Summary collapse

SSH_USER_PREFIX =
'bosh_'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSSHSession

Returns a new instance of SSHSession.



10
11
12
13
14
# File 'lib/cli/ssh_session.rb', line 10

def initialize
  @session_uuid = SecureRandom::uuid
  @public_key = generate_rsa_key
  @user = random_ssh_username
end

Instance Attribute Details

#public_keyObject (readonly)

Returns the value of attribute public_key.



8
9
10
# File 'lib/cli/ssh_session.rb', line 8

def public_key
  @public_key
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/cli/ssh_session.rb', line 8

def user
  @user
end

Instance Method Details

#cleanupObject



40
41
42
43
# File 'lib/cli/ssh_session.rb', line 40

def cleanup
  remove_private_key
  remove_known_host_file
end

#set_host_session(session) ⇒ Object



16
17
18
# File 'lib/cli/ssh_session.rb', line 16

def set_host_session(session)
  @host_session = session
end

#ssh_known_host_option(port) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/cli/ssh_session.rb', line 20

def ssh_known_host_option(port)
  path = user_known_host_path(port)
  if path.length > 0
    path = "-o UserKnownHostsFile=#{path}"
  end
  return path
end

#ssh_known_host_path(port) ⇒ Object



28
29
30
# File 'lib/cli/ssh_session.rb', line 28

def ssh_known_host_path(port)
  user_known_host_path(port)
end

#ssh_private_key_optionObject



32
33
34
# File 'lib/cli/ssh_session.rb', line 32

def ssh_private_key_option
  "-i#{ssh_private_key_path}"
end

#ssh_private_key_pathObject



36
37
38
# File 'lib/cli/ssh_session.rb', line 36

def ssh_private_key_path
  File.join(ENV['HOME'], '.bosh', 'tmp', "#{@session_uuid}_key")
end