Module: ZTK::SSH::Private
- Included in:
- ZTK::SSH
- Defined in:
- lib/ztk/ssh/private.rb
Overview
SSH Private Functionality
Instance Method Summary (collapse)
-
- (Object) base_options
Builds our core options.
-
- (Object) gateway_options
Builds our SSH gateway options hash.
- - (Object) log_header(what, char = '=')
-
- (Object) process_key(key)
Process a individual key, rendering it to a temporary file if needed.
-
- (Object) process_keys
Iterate the keys and proxy_keys, converting them as needed.
-
- (Object) ssh_options
Builds our SSH options hash.
-
- (Object) tag
Builds a human readable tag about our connection.
Instance Method Details
- (Object) base_options
Builds our core options
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ztk/ssh/private.rb', line 8 def = Hash.new config.encryption.nil? or .merge!(:encryption => config.encryption) config.compression.nil? or .merge!(:compression => config.compression) config.compression_level.nil? or .merge!(:compression_level => config.compression_level) config.timeout.nil? or .merge!(:timeout => config.timeout) config.forward_agent.nil? or .merge!(:forward_agent => config.forward_agent) config.global_known_hosts_file.nil? or .merge!(:global_known_hosts_file => config.global_known_hosts_file) config.auth_methods.nil? or .merge!(:auth_methods => config.auth_methods) config.host_key.nil? or .merge!(:host_key => config.host_key) config.host_key_alias.nil? or .merge!(:host_key_alias => config.host_key_alias) config.keys_only.nil? or .merge!(:keys_only => config.keys_only) config.hmac.nil? or .merge!(:hmac => config.hmac) config.rekey_limit.nil? or .merge!(:rekey_limit => config.rekey_limit) config.user_known_hosts_file.nil? or .merge!(:user_known_hosts_file => config.user_known_hosts_file) end |
- (Object) gateway_options
Builds our SSH gateway options hash.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ztk/ssh/private.rb', line 42 def process_keys = config.proxy_port.nil? or .merge!(:port => config.proxy_port) config.proxy_password.nil? or .merge!(:password => config.proxy_password) config.proxy_keys.nil? or .merge!(:keys => config.proxy_keys) config.ui.logger.debug { "gateway_options(#{.inspect})" } end |
- (Object) log_header(what, char = '=')
102 103 104 105 106 107 |
# File 'lib/ztk/ssh/private.rb', line 102 def log_header(what, char='=') count = 16 sep = (char * count) header = [sep, "[ #{tag} >>> #{what} ]", sep].join "#{header}\n" end |
- (Object) process_key(key)
Process a individual key, rendering it to a temporary file if needed.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ztk/ssh/private.rb', line 70 def process_key(key) if ::File.exists?(key) key else tempfile = ::Tempfile.new('key') tempfile.write(key) tempfile.flush tempfile.path end end |
- (Object) process_keys
Iterate the keys and proxy_keys, converting them as needed.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ztk/ssh/private.rb', line 55 def process_keys if (!config.keys.nil? && !config.keys.empty?) config.keys = [config.keys].flatten.compact.collect do |key| process_key(key) end end if (!config.proxy_keys.nil? && !config.proxy_keys.empty?) config.proxy_keys = [config.proxy_keys].flatten.compact.collect do |proxy_key| process_key(proxy_key) end end end |
- (Object) ssh_options
Builds our SSH options hash.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ztk/ssh/private.rb', line 29 def process_keys = config.port.nil? or .merge!(:port => config.port) config.password.nil? or .merge!(:password => config.password) config.keys.nil? or .merge!(:keys => config.keys) config.ui.logger.debug { "ssh_options(#{.inspect})" } end |
- (Object) tag
Builds a human readable tag about our connection. Used for internal logging purposes.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ztk/ssh/private.rb', line 84 def tag = Array.new user_host = "#{config.user}@#{config.host_name}" port = (config.port ? ":#{config.port}" : nil) << [user_host, port].compact.join if config.proxy_host_name << " via " proxy_user_host = "#{config.proxy_user}@#{config.proxy_host_name}" proxy_port = (config.proxy_port ? ":#{config.proxy_port}" : nil) << [proxy_user_host, proxy_port].compact.join end .join.strip end |