Class: Bard::SSHServer
- Inherits:
-
Object
- Object
- Bard::SSHServer
- Defined in:
- lib/bard/ssh_server.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssh_key ⇒ Object
readonly
Returns the value of attribute ssh_key.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #connection_string ⇒ Object
- #exec!(command) ⇒ Object
- #hostname ⇒ Object
-
#initialize(uri_string, **options) ⇒ SSHServer
constructor
A new instance of SSHServer.
- #run(command) ⇒ Object
- #run!(command) ⇒ Object
- #ssh_uri ⇒ Object
Constructor Details
#initialize(uri_string, **options) ⇒ SSHServer
Returns a new instance of SSHServer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bard/ssh_server.rb', line 8 def initialize(uri_string, **) @uri_string = uri_string @options = # Parse URI uri = parse_uri(uri_string) @user = uri.user || ENV['USER'] @host = uri.host @port = uri.port ? uri.port.to_s : "22" # Store options @path = [:path] @gateway = [:gateway] @ssh_key = [:ssh_key] @env = [:env] end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def env @env end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def gateway @gateway end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def port @port end |
#ssh_key ⇒ Object (readonly)
Returns the value of attribute ssh_key.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def ssh_key @ssh_key end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/bard/ssh_server.rb', line 6 def user @user end |
Instance Method Details
#connection_string ⇒ Object
33 34 35 |
# File 'lib/bard/ssh_server.rb', line 33 def connection_string "#{user}@#{host}" end |
#exec!(command) ⇒ Object
50 51 52 53 |
# File 'lib/bard/ssh_server.rb', line 50 def exec!(command) full_command = build_command(command) exec(full_command) end |
#hostname ⇒ Object
29 30 31 |
# File 'lib/bard/ssh_server.rb', line 29 def hostname host end |
#run(command) ⇒ Object
37 38 39 40 |
# File 'lib/bard/ssh_server.rb', line 37 def run(command) full_command = build_command(command) Open3.capture3(full_command) end |
#run!(command) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/bard/ssh_server.rb', line 42 def run!(command) output, error, status = run(command) if status.to_i.nonzero? raise Command::Error, "Command failed: #{command}\n#{error}" end output end |
#ssh_uri ⇒ Object
25 26 27 |
# File 'lib/bard/ssh_server.rb', line 25 def ssh_uri URI("ssh://#{user}@#{host}:#{port}") end |