Module: ESSH
- Defined in:
- lib/evented-ssh.rb,
lib/evented-ssh/version.rb,
lib/evented-ssh/transport/session.rb,
lib/evented-ssh/transport/algorithms.rb,
lib/evented-ssh/transport/packet_stream.rb
Defined Under Namespace
Modules: Transport
Constant Summary collapse
- VALID_OPTIONS =
[ :auth_methods, :bind_address, :compression, :compression_level, :config, :encryption, :forward_agent, :hmac, :host_key, :remote_user, :keepalive, :keepalive_interval, :keepalive_maxcount, :kex, :keys, :key_data, :languages, :logger, :paranoid, :password, :port, :proxy, :rekey_blocks_limit,:rekey_limit, :rekey_packet_limit, :timeout, :verbose, :known_hosts, :global_known_hosts_file, :user_known_hosts_file, :host_key_alias, :host_name, :user, :properties, :passphrase, :keys_only, :max_pkt_size, :max_win_size, :send_env, :use_agent, :number_of_password_prompts, :append_all_supported_algorithms, :non_interactive, :password_prompt, :agent_socket_factory, :minimum_dh_bits ]
- VERSION =
'0.1.1'
Class Method Summary collapse
- .assign_defaults(options) ⇒ Object
- .configuration_for(host, use_ssh_config) ⇒ Object
-
.p_start(host, user = nil, **options) ⇒ Object
Start using a promise.
- .start(host, user = nil, **options, &block) ⇒ Object
Class Method Details
.assign_defaults(options) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/evented-ssh.rb', line 103 def self.assign_defaults() if ![:logger] [:logger] = Logger.new(STDERR) [:logger].level = Logger::FATAL end [:password_prompt] ||= ::Net::SSH::Prompt.default() [:password, :passphrase].each do |key| .delete(key) if .key?(key) && [key].nil? end end |
.configuration_for(host, use_ssh_config) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/evented-ssh.rb', line 93 def self.configuration_for(host, use_ssh_config) files = case use_ssh_config when true then ::Net::SSH::Config. when false, nil then return {} else Array(use_ssh_config) end ::Net::SSH::Config.for(host, files) end |
.p_start(host, user = nil, **options) ⇒ Object
Start using a promise
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/evented-ssh.rb', line 79 def self.p_start(host, user = nil, **) thread = ::Libuv.reactor defer = thread.defer thread.next_tick do begin connection = start(host, user, **) defer.resolve(connection) rescue Exception => e defer.reject(e) end end defer.promise end |
.start(host, user = nil, **options, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/evented-ssh.rb', line 25 def self.start(host, user = nil, **, &block) = .keys - VALID_OPTIONS if .any? raise ArgumentError, "invalid option(s): #{.join(', ')}" end assign_defaults() () [:user] = user if user = configuration_for(host, .fetch(:config, true)).merge() host = .fetch(:host_name, host) if [:non_interactive] [:number_of_password_prompts] = 0 end if [:verbose] [:logger].level = case [:verbose] when Integer then [:verbose] when :debug then Logger::DEBUG when :info then Logger::INFO when :warn then Logger::WARN when :error then Logger::ERROR when :fatal then Logger::FATAL else raise ArgumentError, "can't convert #{[:verbose].inspect} to any of the Logger level constants" end end transport = Transport::Session.new(host, ) auth = ::Net::SSH::Authentication::Session.new(transport, ) user = .fetch(:user, user) || Etc.getlogin if auth.authenticate("ssh-connection", user, [:password]) connection = ::Net::SSH::Connection::Session.new(transport, ) if block_given? begin yield connection ensure connection.close unless connection.closed? end else return connection end else transport.close raise ::Net::SSH::AuthenticationFailed, "Authentication failed for user #{user}@#{host}" end rescue => e transport.socket.__send__(:reject, e) if transport raise end |