Skip to content

Commit 703e19b

Browse files
committed
Allow ssh/config to accept string, or array of strings
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
1 parent 74a06b0 commit 703e19b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/kamal/configuration/ssh.rb

Lines changed: 6 additions & 2 deletions
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
@@ -38,8 +38,12 @@ def key_data
3838
ssh_config["key_data"]
3939
end
4040

41+
def config
42+
ssh_config["config"]
43+
end
44+
4145
def options
42-
{ user: user, port: port, proxy: proxy, logger: logger, keepalive: true, keepalive_interval: 30, keys_only: keys_only, keys: keys, key_data: key_data }.compact
46+
{ 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
4347
end
4448

4549
def to_h
Lines changed: 25 additions & 0 deletions
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)