open4ssh 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26bd3a93e22a85fff7203c396a7f9a63c9370b2d
4
- data.tar.gz: 4ef5d35b8d5770e9d67c32da55e06f04552478af
3
+ metadata.gz: 8c596e78cb2d1cb9e2928862634b22b0f727645f
4
+ data.tar.gz: 143940e4d7e01d4d1f86200247787469c7384b08
5
5
  SHA512:
6
- metadata.gz: 2913a4e37a357677c7865581f6108ed91c9633e6d3f5b0160654b4a94cc51217fd8775354c3d42f45ff888ac8b9d655e1f4827ac765eac975cb148f3255f7bce
7
- data.tar.gz: a384c9dd93d1964c060be4bf1aedf3994f0530d926152db775169a552fa299b9c18f4db0277322db0f4a36063b14887c11d20e2e03eb614af62f28cbca7e035e
6
+ metadata.gz: ef404db109f30939eacf686b5a7b2814259e17f8ea9225fb59fd9631856f2c90c1dfd1603846ab16dad4024877de65d5ab5f584fb4c4813468cea7b3f7bf97a3
7
+ data.tar.gz: c5e152ec8690b969c647e61844b0b17f3eef4f602e849dfcd3ad8b5c247f897a8aa7ebfdb2898adc09dfbb8895566b0eb93bb0a98621ff873f6afac86c4ab7c4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.1.3
4
+
5
+ - Added unit tests.
6
+ - Added <code>capture3()</code> function.
7
+ - Optimized documentation.
8
+
3
9
  ## Version 0.1.2
4
10
 
5
11
  - Added <code>success(), stdout(), stderr(), console()</code> functions.
data/Rakefile CHANGED
@@ -1,8 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'yard'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/test_*.rb']
8
+ t.verbose = true
9
+ end
3
10
 
4
11
  YARD::Rake::YardocTask.new do |t|
5
- t.files = ['lib/**/*.rb', '-', 'README.md', 'LICENSE.txt', 'CHANGELOG.md']
6
- # t.options = ['--any', '--extra', '--opts']
12
+ t.files = ['lib/**/*.rb', 'test/**/*.rb', '-', 'README.md', 'LICENSE.txt', 'CHANGELOG.md']
7
13
  t.stats_options = ['--list-undoc']
8
14
  end
@@ -1,3 +1,6 @@
1
1
  module Open4ssh
2
- VERSION = "0.1.2"
2
+
3
+ # Version of Open4ssh according to {http://semver.org semantic versioning}
4
+ #
5
+ VERSION = "0.1.3"
3
6
  end
data/lib/open4ssh.rb CHANGED
@@ -1,6 +1,30 @@
1
1
  require "open4ssh/version"
2
2
  require "net/ssh"
3
3
 
4
+ # Open4ssh is a small convenience wrapper for {https://rubygems.org/gems/net-ssh net-ssh}.
5
+ # Its intended and primary purpose is to provide pragmatic
6
+ # execution of shell commands on a remote host via SSH.
7
+ #
8
+ # It provides the following functions:
9
+ #
10
+ # - {capture} to execute one command on a remote host via SSH and get the console output back.
11
+ # - {capture3} to execute one command on a remote host via SSH and get the exit code, standard out, standard error of the command back.
12
+ # - {capture4} to execute a sequence of commands on a remote host via SSH and get all return values (exit code, standard out, standard error, command) back.
13
+ # - {success} to evaluate whether a sequence of commands was successful.
14
+ # - {stdout} to get all standard out messages of a sequence of commands.
15
+ # - {stderr} to get all standard error messages of a sequence of commands.
16
+ # - {console} to get all console output (union of standard out and standard error messages) of a sequence of commands.
17
+ #
18
+ # @author Nane Kratzke
19
+ # @example
20
+ # console = Open4ssh.capture(
21
+ # host: 'remote.host.io',
22
+ # user: 'nane',
23
+ # pwd: 'secret',
24
+ # cmd: 'ls -la'
25
+ # )
26
+ # puts console
27
+ #
4
28
  module Open4ssh
5
29
 
6
30
  # Executes a shell command on a remote host via SSH and captures the console output.
@@ -27,14 +51,41 @@ module Open4ssh
27
51
  stdout = ""
28
52
  keys = [key]
29
53
 
30
- Net::SSH.start(host, user, port: 22, password: pwd, keys: keys) do |ssh|
31
- result = ssh.exec!(cmd)
32
- stdout = result
54
+ Net::SSH.start(host, user, port: port, password: pwd, keys: keys) do |ssh|
55
+ stdout = ssh.exec!(cmd)
33
56
  end
34
57
 
35
58
  return stdout
36
59
  end
37
60
 
61
+ # Executes one shell command on a remote host via SSH and captures it exit code, stdout and stderr.
62
+ #
63
+ # @param host [String] DNS name or IP address of the remote host (required)
64
+ # @param port [Integer] Port (defaults to 22)
65
+ # @param user [String] User name (required)
66
+ # @param key [Path] Path to a key file (.pem) if user logs in via keyfile (not required if password is provided)
67
+ # @param pwd [String] Password of user (not required if key is provided)
68
+ # @param cmd [String] shell command string to be executed on host (required)
69
+ # @param verbose [Bool] console outputs are plotted to stdout/stderr if set (defaults to false)
70
+ #
71
+ # @return [exit_code, std_out, std_err] exit_code, stdout, stderr of executed command
72
+ #
73
+ # @example
74
+ # exit_code, std_err, std_out = Open4ssh.capture3(
75
+ # host: 'remote.host.io',
76
+ # user: 'nane',
77
+ # pwd: 'secret',
78
+ # cmd: 'ls -la'
79
+ # )
80
+ #
81
+ def self.capture3(host: '', user: '', port: 22, key: '', pwd: '', cmd: '', verbose: false)
82
+ returns = self.capture4(host: host, user: user, port: port, key: key, pwd: pwd, cmd: [cmd], verbose: verbose)
83
+ exit_code = returns.last[0]
84
+ std_out = returns.last[1]
85
+ std_err = returns.last[2]
86
+ return exit_code, std_out, std_err
87
+ end
88
+
38
89
  # Executes a list of shell commands on a remote host via SSH and captures their exit codes, stdouts and stderrs.
39
90
  # The commands are executed sequentially until a command terminates with an exit code not equal 0 (no success).
40
91
  #
data/open4ssh.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "yard", "~> 0.8"
33
+ spec.add_development_dependency "test-unit", "~> 3.2"
33
34
 
34
35
  spec.add_runtime_dependency "net-ssh", "~> 3.2"
35
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open4ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nane Kratzke
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: net-ssh
57
71
  requirement: !ruby/object:Gem::Requirement