Class: ServerDefinition
- Inherits:
-
Object
- Object
- ServerDefinition
- Defined in:
- lib/simple_gate/server_definition.rb
Class Attribute Summary collapse
-
.servers ⇒ Object
Access the pre-configured servers.
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#options ⇒ Object
Returns the value of attribute options.
-
#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
Instance Method Summary collapse
- #connection_info(&block) ⇒ Object
-
#initialize(host, options = {}) ⇒ ServerDefinition
constructor
A new instance of ServerDefinition.
- #ssh_options ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host, options = {}) ⇒ ServerDefinition
Returns a new instance of ServerDefinition.
5 6 7 8 9 10 11 |
# File 'lib/simple_gate/server_definition.rb', line 5 def initialize(host, = {}) @options = {:port => 22}.merge() self.host = host self.user = @options[:user] self.password = @options[:password] self.port = @options[:port] end |
Class Attribute Details
.servers ⇒ Object
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.
79 80 81 |
# File 'lib/simple_gate/server_definition.rb', line 79 def servers @servers end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def host @host end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/simple_gate/server_definition.rb', line 3 def @options 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) ⇒ Object
51 52 53 |
# File 'lib/simple_gate/server_definition.rb', line 51 def self.find(server) servers.has_key?(server) ? lookup(server) : parse(server) end |
.lookup(server) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/simple_gate/server_definition.rb', line 42 def self.lookup(server) server = servers[server] new(server['address'],{ :user => server['username'], :password => server['password'], :port => server['port'] }) end |
.parse(ssh_string) ⇒ Object
55 56 57 58 |
# File 'lib/simple_gate/server_definition.rb', line 55 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(&block) ⇒ Object
28 29 30 |
# File 'lib/simple_gate/server_definition.rb', line 28 def connection_info(&block) block.call(host, user, .merge()) end |
#ssh_options ⇒ Object
32 33 34 35 36 |
# File 'lib/simple_gate/server_definition.rb', line 32 def { :auth_methods => %w[password keyboard-interactive] } end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/simple_gate/server_definition.rb', line 38 def to_s "#{user}:#{'*' * password.to_s.size}@#{host}:#{port}" end |