From 14cde2c783614a6f15160a1f7be3b182d1dfe729 Mon Sep 17 00:00:00 2001 From: Kim Burgestrand Date: Thu, 17 Oct 2024 13:03:48 +0200 Subject: [PATCH] Allow `ssh/config` to additionally accept a string, or an array of strings This is accepted by Net::SSH, research done by @jeremy in https://github.com/basecamp/kamal/pull/908#issuecomment-2387652198 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. --- lib/kamal/configuration/ssh.rb | 2 +- lib/kamal/configuration/validator/ssh.rb | 25 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib/kamal/configuration/validator/ssh.rb diff --git a/lib/kamal/configuration/ssh.rb b/lib/kamal/configuration/ssh.rb index ee7c28b0e..28ba96717 100644 --- a/lib/kamal/configuration/ssh.rb +++ b/lib/kamal/configuration/ssh.rb @@ -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 diff --git a/lib/kamal/configuration/validator/ssh.rb b/lib/kamal/configuration/validator/ssh.rb new file mode 100644 index 000000000..0c92e417b --- /dev/null +++ b/lib/kamal/configuration/validator/ssh.rb @@ -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