Skip to content

Commit 7abd339

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 basecamp#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 34bc2a3 commit 7abd339

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/kamal/configuration/ssh.rb

Lines changed: 1 addition & 1 deletion
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
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

test/configuration/ssh_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ class ConfigurationSshTest < ActiveSupport::TestCase
4242
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "config" => false }) })
4343
assert_equal false, config.ssh.options[:config]
4444
end
45+
46+
test "ssh options with path to an ssh_config-file" do
47+
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "config" => "config/ssh_config" }) })
48+
assert_equal "config/ssh_config", config.ssh.options[:config]
49+
end
50+
51+
test "ssh options with an array of ssh_config-files" do
52+
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "config" => %w[ ssh_config_a ssh_config_b ] }) })
53+
assert_equal %w[ ssh_config_a ssh_config_b ], config.ssh.options[:config]
54+
end
4555
end

0 commit comments

Comments
 (0)