Skip to content

Commit

Permalink
Extract conditional into method
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Oct 9, 2024
1 parent 5f9f70b commit e8cdf52
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/kamal/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ def initialize(config)
end

def run_over_ssh(*command, host:)
"ssh".then do |cmd|
if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump)
cmd = "#{cmd} -J #{config.ssh.proxy.jump_proxies}"
elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
cmd = "#{cmd} -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
end
"#{cmd} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
end
"ssh #{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
end

def container_id_for(container_name:, only_running: false)
Expand Down Expand Up @@ -92,5 +85,13 @@ def grep(*args)
def tags(**details)
Kamal::Tags.from_config(config, **details)
end

def ssh_proxy_args
if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump)
"-J #{config.ssh.proxy.jump_proxies}"
elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
"-o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
end
end
end
end

0 comments on commit e8cdf52

Please sign in to comment.