Class: Net::SSH::HostKeys

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/net/ssh/known_hosts.rb

Overview

Represents the result of a search in known hosts see search_for

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_keys, host, known_hosts, options = {}, revoked_keys = []) ⇒ HostKeys

Returns a new instance of HostKeys.



130
131
132
133
134
135
136
# File 'lib/net/ssh/known_hosts.rb', line 130

def initialize(host_keys, host, known_hosts, options = {}, revoked_keys = [])
  @host_keys = host_keys
  @host = host
  @known_hosts = known_hosts
  @options = options
  @revoked_keys = revoked_keys
end

Instance Attribute Details

#host ⇒ Object (readonly)

Returns the value of attribute host.



128
129
130
# File 'lib/net/ssh/known_hosts.rb', line 128

def host
  @host
end

Instance Method Details

#add_host_key(key) ⇒ Object



143
144
145
146
# File 'lib/net/ssh/known_hosts.rb', line 143

def add_host_key(key)
  @known_hosts.add(@host, key, @options)
  @host_keys.push(key)
end

#each(&block) ⇒ Object



148
149
150
# File 'lib/net/ssh/known_hosts.rb', line 148

def each(&block)
  @host_keys.each(&block)
end

#empty? ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/net/ssh/known_hosts.rb', line 152

def empty?
  @host_keys.empty?
end

#hostname ⇒ Object

Returns the bare hostname, stripping port and IP portions from the comma-separated host string used internally.

Examples:

"server.example.com"            => "server.example.com"
"server.example.com,1.2.3.4"    => "server.example.com"
"[server.example.com]:2222"      => "server.example.com"


163
164
165
# File 'lib/net/ssh/known_hosts.rb', line 163

def hostname
  @host.split(",").first.gsub(/\[|\]:\d+/, "")
end

#revoked?(key) ⇒ Boolean

Returns true if a @revoked known-hosts entry for this host matches key.

Returns:

  • (Boolean)


139
140
141
# File 'lib/net/ssh/known_hosts.rb', line 139

def revoked?(key)
  @revoked_keys.any? { |entry| entry.matches_key?(key) }
end