diff options
author | Jamis Buck <jamis@37signals.com> | 2009-02-02 22:40:54 -0700 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2009-02-02 22:40:54 -0700 |
commit | 17cadf135c3f16b5ddf2ddc59ac4fbda98df3ce1 (patch) | |
tree | c0d9b116799b12821caafebcc23ecef301a0a6c2 | |
parent | e1fed2b5b7e9e0b5992e33b1c9eb38b755e2e919 (diff) | |
download | net-ssh-17cadf135c3f16b5ddf2ddc59ac4fbda98df3ce1.tar.gz |
make it easier to query SSH configuration in a standard way
-rw-r--r-- | CHANGELOG.rdoc | 5 | ||||
-rw-r--r-- | lib/net/ssh.rb | 27 |
2 files changed, 25 insertions, 7 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 0f9b323..7076fa4 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,8 @@ +=== (unreleased) + +* Added Net::SSH.configuration_for to make it easier to query the SSH configuration file(s) [Jamis Buck] + + === 2.0.9 / 1 Feb 2009 * Specifying non-nil user argument overrides user in .ssh/config [Jamis Buck] diff --git a/lib/net/ssh.rb b/lib/net/ssh.rb index a752392..0d36d78 100644 --- a/lib/net/ssh.rb +++ b/lib/net/ssh.rb @@ -153,14 +153,8 @@ module Net raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}" end - files = case options.fetch(:config, true) - when true then Net::SSH::Config.default_files - when false, nil then [] - else Array(options[:config]) - end - options[:user] = user if user - options = Net::SSH::Config.for(host, files).merge(options) + options = configuration_for(host, options.fetch(:config, true)).merge(options) host = options.fetch(:host_name, host) if !options.key?(:logger) @@ -196,5 +190,24 @@ module Net raise AuthenticationFailed, user end end + + # Returns a hash of the configuration options for the given host, as read + # from the SSH configuration file(s). If +use_ssh_config+ is true (the + # default), this will load configuration from both ~/.ssh/config and + # /etc/ssh_config. If +use_ssh_config+ is nil or false, nothing will be + # loaded (and an empty hash returned). Otherwise, +use_ssh_config+ may + # be a file name (or array of file names) of SSH configuration file(s) + # to read. + # + # See Net::SSH::Config for the full description of all supported options. + def self.configuration_for(host, use_ssh_config=true) + files = case use_ssh_config + when true then Net::SSH::Config.default_files + when false, nil then return {} + else Array(use_ssh_config) + end + + Net::SSH::Config.for(host, files) + end end end |