Skip to content

Commit 14cde2c

Browse files
committed
Allow ssh/config to additionally accept a string, or an array of strings
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.
1 parent f924b68 commit 14cde2c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/kamal/configuration/ssh.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Kamal::Configuration::Ssh
77

88
def initialize(config:)
99
@ssh_config = config.raw_config.ssh || {}
10-
validate! ssh_config
10+
validate! ssh_config, with: Kamal::Configuration::Validator::Ssh
1111
end
1212

1313
def user
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Kamal::Configuration::Validator::Ssh < Kamal::Configuration::Validator
2+
BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS = [ "config" ]
3+
SPECIAL_KEYS = BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS
4+
5+
def validate!
6+
validate_against_example! \
7+
config.except(*SPECIAL_KEYS),
8+
example.except(*SPECIAL_KEYS)
9+
10+
BOOLEAN_OR_STRING_OR_ARRAY_OF_STRING_KEYS.each do |key|
11+
value = config[key]
12+
13+
with_context(key) do
14+
validate_type! value, TrueClass, String, Array
15+
validate_array_of!(value, String) if value.is_a?(Array)
16+
end
17+
end
18+
end
19+
20+
private
21+
22+
def special_keys
23+
@special_keys ||= config.keys & SPECIAL_KEYS
24+
end
25+
end

0 commit comments

Comments
 (0)