Skip to content

Commit

Permalink
Allow ssh/config to accept string, or array of strings
Browse files Browse the repository at this point in the history
This gets passed through to SSHKit options. See basecamp#908

Documentation mentions a string or array of strings are allowed, but they are not because:
* Validator example supplies a boolean, so only true/false are enabled.
* `Kamal::Configuration::Ssh#options` doesn't expose `config`, used in lib/kamal/commander.rb:167
  • Loading branch information
Burgestrand committed Oct 17, 2024
1 parent 74a06b0 commit 703e19b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/kamal/configuration/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Kamal::Configuration::Ssh

def initialize(config:)
@ssh_config = config.raw_config.ssh || {}
validate! ssh_config
validate! ssh_config, with: Kamal::Configuration::Validator::Ssh
end

def user
Expand Down Expand Up @@ -38,8 +38,12 @@ def key_data
ssh_config["key_data"]
end

def config
ssh_config["config"]
end

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
{ user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data, config: config }.compact
end

def to_h
Expand Down
25 changes: 25 additions & 0 deletions lib/kamal/configuration/validator/ssh.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Kamal::Configuration::Validator::Ssh < Kamal::Configuration::Validator
BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS = [ "config" ]
SPECIAL_KEYS = BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS

def validate!
validate_against_example! \
config.except(*SPECIAL_KEYS),
example.except(*SPECIAL_KEYS)

BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS.each do |key|
value = config[key]

with_context(key) do
validate_type! value, TrueClass, String, Array
validate_array_of!(value, String) if value.is_a?(Array)
end
end
end

private

def special_keys
@special_keys ||= config.keys & SPECIAL_KEYS
end
end

0 comments on commit 703e19b

Please sign in to comment.