Class: Aspera::Plugins::Transferd::Service::Host
- Inherits:
-
Object
- Object
- Aspera::Plugins::Transferd::Service::Host
- Defined in:
- lib/aspera/plugins/transferd/service.rb
Overview
Access to the system: root folder, commands and network. Replaceable in tests.
Instance Attribute Summary collapse
- #euid ⇒ String, ... readonly
- #os ⇒ String, ... readonly
- #root ⇒ String, ... readonly
- #timeout ⇒ String, ... readonly
Instance Method Summary collapse
-
#initialize(root: '/', runner: nil, listening: nil, timeout: 30, os: nil, euid: nil, systemctl: nil) ⇒ Host
constructor
A new instance of Host.
-
#listening?(address, port) ⇒ Boolean
trueif a server listens on this address and port. -
#path(path) ⇒ String
Path below the root folder.
-
#run(*cmd) ⇒ Array(String, Boolean)
Output and success.
-
#systemctl? ⇒ Boolean
trueifsystemctlis available.
Constructor Details
#initialize(root: '/', runner: nil, listening: nil, timeout: 30, os: nil, euid: nil, systemctl: nil) ⇒ Host
Returns a new instance of Host.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aspera/plugins/transferd/service.rb', line 67 def initialize(root: '/', runner: nil, listening: nil, timeout: 30, os: nil, euid: nil, systemctl: nil) @root = root @os = os || Environment.instance.os @euid = euid || ::Process.euid @systemctl = systemctl.nil? ? ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).any? { |dir| File.executable?(File.join(dir, 'systemctl')) } : systemctl @runner = runner || lambda do |*cmd| out, err, status = Environment.secure_execute(*cmd, mode: :capture, exception: false) [out.to_s + err.to_s, status.success?] end @listening = listening || lambda do |address, port| Socket.tcp(address, port, connect_timeout: 1) { true } rescue SystemCallError, IOError false end @timeout = timeout end |
Instance Attribute Details
#euid ⇒ String, ... (readonly)
58 59 60 |
# File 'lib/aspera/plugins/transferd/service.rb', line 58 def euid @euid end |
#os ⇒ String, ... (readonly)
58 59 60 |
# File 'lib/aspera/plugins/transferd/service.rb', line 58 def os @os end |
#root ⇒ String, ... (readonly)
58 59 60 |
# File 'lib/aspera/plugins/transferd/service.rb', line 58 def root @root end |
#timeout ⇒ String, ... (readonly)
58 59 60 |
# File 'lib/aspera/plugins/transferd/service.rb', line 58 def timeout @timeout end |
Instance Method Details
#listening?(address, port) ⇒ Boolean
Returns true if a server listens on this address and port.
97 98 99 |
# File 'lib/aspera/plugins/transferd/service.rb', line 97 def listening?(address, port) @listening.call(address, port) end |
#path(path) ⇒ String
Returns Path below the root folder.
86 87 88 |
# File 'lib/aspera/plugins/transferd/service.rb', line 86 def path(path) File.join(@root, path) end |
#run(*cmd) ⇒ Array(String, Boolean)
Returns Output and success.
92 93 94 |
# File 'lib/aspera/plugins/transferd/service.rb', line 92 def run(*cmd) @runner.call(*cmd) end |
#systemctl? ⇒ Boolean
Returns true if systemctl is available.
102 103 104 |
# File 'lib/aspera/plugins/transferd/service.rb', line 102 def systemctl? @systemctl end |