Skip to content

Commit

Permalink
Allow ssh/config to additionally accept a string, or an array of st…
Browse files Browse the repository at this point in the history
…rings

This is accepted by Net::SSH, research done by @jeremy in #908 (comment)

This is already documented as working correctly in https://github.com/basecamp/kamal/blob/74a06b0ccda616c86ebe1729d0795f39bcac9f00/lib/kamal/configuration/docs/ssh.yml#L65-L70

However, before this change only booleans were allowed because of the example configuration file.
  • Loading branch information
Burgestrand committed Oct 17, 2024
1 parent f924b68 commit 14cde2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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
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 14cde2c

Please sign in to comment.