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
- #to_s ⇒ Object
Constructor Details
#initialize(uri_string, **options) ⇒ SSHServer
Returns a new instance of SSHServer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bard/ssh_server.rb', line 9 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.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def env @env end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def gateway @gateway end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def port @port end |
#ssh_key ⇒ Object (readonly)
Returns the value of attribute ssh_key.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def ssh_key @ssh_key end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/bard/ssh_server.rb', line 7 def user @user end |
Instance Method Details
#connection_string ⇒ Object
40 41 42 |
# File 'lib/bard/ssh_server.rb', line 40 def connection_string "#{user}@#{host}" end |
#exec!(command) ⇒ Object
57 58 59 60 |
# File 'lib/bard/ssh_server.rb', line 57 def exec!(command) full_command = build_command(command) exec(full_command) end |
#hostname ⇒ Object
30 31 32 |
# File 'lib/bard/ssh_server.rb', line 30 def hostname host end |
#run(command) ⇒ Object
44 45 46 47 |
# File 'lib/bard/ssh_server.rb', line 44 def run(command) full_command = build_command(command) Open3.capture3(full_command) end |
#run!(command) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/bard/ssh_server.rb', line 49 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
26 27 28 |
# File 'lib/bard/ssh_server.rb', line 26 def ssh_uri URI("ssh://#{user}@#{host}:#{port}") end |
#to_s ⇒ Object
34 35 36 37 38 |
# File 'lib/bard/ssh_server.rb', line 34 def to_s str = "#{user}@#{host}" str += ":#{port}" if port && port != "22" str end |