Class: Kamal::Configuration::Ssh

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/kamal/configuration/ssh.rb

Constant Summary collapse

LOGGER =
::Logger.new(STDERR)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#validate!, #validation_yml

Constructor Details

#initialize(config:) ⇒ Ssh

Returns a new instance of Ssh.



8
9
10
11
# File 'lib/kamal/configuration/ssh.rb', line 8

def initialize(config:)
  @ssh_config = config.raw_config.ssh || {}
  validate! ssh_config
end

Instance Attribute Details

#ssh_configObject (readonly)

Returns the value of attribute ssh_config.



6
7
8
# File 'lib/kamal/configuration/ssh.rb', line 6

def ssh_config
  @ssh_config
end

Instance Method Details

#key_dataObject



37
38
39
# File 'lib/kamal/configuration/ssh.rb', line 37

def key_data
  ssh_config["key_data"]
end

#keysObject



33
34
35
# File 'lib/kamal/configuration/ssh.rb', line 33

def keys
  ssh_config["keys"]
end

#keys_onlyObject



29
30
31
# File 'lib/kamal/configuration/ssh.rb', line 29

def keys_only
  ssh_config["keys_only"]
end

#optionsObject



41
42
43
# File 'lib/kamal/configuration/ssh.rb', line 41

def options
  { user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data }.compact
end

#portObject



17
18
19
# File 'lib/kamal/configuration/ssh.rb', line 17

def port
  ssh_config.fetch("port", 22)
end

#proxyObject



21
22
23
24
25
26
27
# File 'lib/kamal/configuration/ssh.rb', line 21

def proxy
  if (proxy = ssh_config["proxy"])
    Net::SSH::Proxy::Jump.new(proxy.include?("@") ? proxy : "root@#{proxy}")
  elsif (proxy_command = ssh_config["proxy_command"])
    Net::SSH::Proxy::Command.new(proxy_command)
  end
end

#to_hObject



45
46
47
# File 'lib/kamal/configuration/ssh.rb', line 45

def to_h
  options.except(:logger).merge(log_level: log_level)
end

#userObject



13
14
15
# File 'lib/kamal/configuration/ssh.rb', line 13

def user
  ssh_config.fetch("user", "root")
end