Class: Microsandbox::SshOps
- Inherits:
-
Object
- Object
- Microsandbox::SshOps
- Defined in:
- lib/microsandbox/ssh.rb
Overview
The SSH namespace for a sandbox, returned by Microsandbox::Sandbox#ssh. Use it to open a native in-process SSH client or prepare a reusable server endpoint.
Instance Method Summary collapse
-
#initialize(native) ⇒ SshOps
constructor
A new instance of SshOps.
-
#open_client(user: "root", term: nil, sftp: true) {|client| ... } ⇒ SshClient, Object
Open a native in-process SSH client to the sandbox.
-
#prepare_server(host_key_path: nil, authorized_keys_path: nil, user: nil, sftp: true) ⇒ SshServer
Prepare a reusable SSH server endpoint for the sandbox.
Constructor Details
#initialize(native) ⇒ SshOps
Returns a new instance of SshOps.
209 210 211 |
# File 'lib/microsandbox/ssh.rb', line 209 def initialize(native) @native = native end |
Instance Method Details
#open_client(user: "root", term: nil, sftp: true) {|client| ... } ⇒ SshClient, Object
Open a native in-process SSH client to the sandbox. With a block, the client is yielded and closed when the block returns.
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/microsandbox/ssh.rb', line 220 def open_client(user: "root", term: nil, sftp: true) opts = { "user" => user.to_s, "sftp" => sftp ? true : false } opts["term"] = term.to_s if term client = SshClient.new(@native.ssh_open_client(opts)) return client unless block_given? begin yield client ensure client.close end end |
#prepare_server(host_key_path: nil, authorized_keys_path: nil, user: nil, sftp: true) ⇒ SshServer
Prepare a reusable SSH server endpoint for the sandbox.
239 240 241 242 243 244 245 |
# File 'lib/microsandbox/ssh.rb', line 239 def prepare_server(host_key_path: nil, authorized_keys_path: nil, user: nil, sftp: true) opts = { "sftp" => sftp ? true : false } opts["host_key_path"] = host_key_path.to_s if host_key_path opts["authorized_keys_path"] = .to_s if opts["user"] = user.to_s if user SshServer.new(@native.ssh_prepare_server(opts)) end |