Class: ServerDefinition
- Inherits:
-
Object
- Object
- ServerDefinition
- Defined in:
- lib/simple_gate/server_definition.rb
Class Attribute Summary collapse
-
.servers ⇒ Hash
Access the pre-configured servers.
Instance Attribute Summary collapse
-
#auth_methods ⇒ Object
Returns the value of attribute auth_methods.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.find(server) ⇒ ServerDefinition
Factory method that chooses between a lookup and parse.
-
.lookup(server) ⇒ ServerDefinition
Factory method that uses pre-defined server configurations.
-
.parse(ssh_string) ⇒ ServerDefinition
Factory method that parses a connection string.
Instance Method Summary collapse
-
#connection_info {|host, user, options| ... } ⇒ Object
Yield connection information.
-
#initialize(host, options = {}) ⇒ ServerDefinition
constructor
Create a new ServerDefinition.
-
#options ⇒ Hash
SSH options.
-
#to_s ⇒ String
Represent server definition as URL-like string.
Constructor Details
#initialize(host, options = {}) ⇒ ServerDefinition
Create a new ServerDefinition.
12 13 14 15 16 17 18 |
# File 'lib/simple_gate/server_definition.rb', line 12 def initialize(host, = {}) self.host = host self.user = [:user] self.password = [:password] self.port = [:port] || 22 self.auth_methods = [:auth_methods] || %w[password keyboard-interactive] end |
Class Attribute Details
.servers ⇒ Hash
Access the pre-configured servers. ~/.servers.yml is parsed for this. An example entry for the servers ‘foobar’ and ‘barfoo’ would look like:
---
foobar:
address: "127.0.0.1"
username: "foo"
password: "bar
port: 22
barfoo:
address: "192.168.0.1"
username: "bar"
password: "foo
port: 22
Since the parsed Hash of servers is cached, a value can be stored and the configuration file ignored if desired.
95 96 97 |
# File 'lib/simple_gate/server_definition.rb', line 95 def servers @servers end |
Instance Attribute Details
#auth_methods ⇒ Object
Returns the value of attribute auth_methods.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def auth_methods @auth_methods end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def port @port end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def user @user end |
Class Method Details
.find(server) ⇒ ServerDefinition
Factory method that chooses between a lookup and parse.
63 64 65 |
# File 'lib/simple_gate/server_definition.rb', line 63 def self.find(server) servers.has_key?(server) ? lookup(server) : parse(server) end |
.lookup(server) ⇒ ServerDefinition
Factory method that uses pre-defined server configurations.
49 50 51 52 53 54 55 56 |
# File 'lib/simple_gate/server_definition.rb', line 49 def self.lookup(server) server = servers[server] new(server['address'],{ :user => server['username'], :password => server['password'], :port => server['port'] }) end |
.parse(ssh_string) ⇒ ServerDefinition
Factory method that parses a connection string.
70 71 72 73 |
# File 'lib/simple_gate/server_definition.rb', line 70 def self.parse(ssh_string) user, password, host, port = ssh_string.match /\A(.*?):(.*?)@(.*?):(\d*?)\Z/ new(host, :user => user, :password => password, :port => port) end |
Instance Method Details
#connection_info {|host, user, options| ... } ⇒ Object
Yield connection information.
37 38 39 |
# File 'lib/simple_gate/server_definition.rb', line 37 def connection_info(&block) block.call(host, user, ) end |
#options ⇒ Hash
SSH options
22 23 24 25 26 27 28 29 |
# File 'lib/simple_gate/server_definition.rb', line 22 def { :user => user, :password => password, :port => port, :auth_methods => auth_methods } end |
#to_s ⇒ String
Represent server definition as URL-like string
43 44 45 |
# File 'lib/simple_gate/server_definition.rb', line 43 def to_s "#{user}:#{'*' * password.to_s.size}@#{host}:#{port}" end |