gofer 0.1.1 → 0.1.2
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.
- data/HISTORY.md +5 -1
- data/README.md +3 -2
- data/lib/gofer/host.rb +6 -2
- data/lib/gofer/ssh_wrapper.rb +24 -24
- data/lib/gofer/version.rb +1 -1
- data/spec/gofer/integration_spec.rb +11 -1
- metadata +2 -2
data/HISTORY.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Revision History
|
2
2
|
|
3
|
+
### v0.1.2 03/05/2011
|
4
|
+
|
5
|
+
* Pass through Gofer::Host instantiation options straight through to Net::SSH.
|
6
|
+
|
3
7
|
### v0.1.1 23/04/2011
|
4
8
|
|
5
9
|
* Minimal RDoc added.
|
@@ -11,4 +15,4 @@
|
|
11
15
|
|
12
16
|
### v0.0.1 03/04/2011
|
13
17
|
|
14
|
-
* Initial release
|
18
|
+
* Initial release
|
data/README.md
CHANGED
@@ -8,12 +8,13 @@
|
|
8
8
|
* print and capture STDOUT and STDERR automatically
|
9
9
|
* allow you to access captured STDOUT and STDERR individually or as a combined string
|
10
10
|
* override the above: return non-zero exit status instead of raising an error, suppress output
|
11
|
+
* persist the SSH connection so that multiple commands don't incur connection penalties
|
11
12
|
|
12
13
|
## Examples
|
13
14
|
|
14
15
|
### Instantiation
|
15
16
|
|
16
|
-
h = Gofer::Host.new('ubuntu', 'my.host.com', :
|
17
|
+
h = Gofer::Host.new('ubuntu', 'my.host.com', :keys => ['key.pem'])
|
17
18
|
|
18
19
|
### Run a command
|
19
20
|
|
@@ -76,7 +77,7 @@
|
|
76
77
|
|
77
78
|
* ls, exists?, directory? should use sftp if available rather than shell commands
|
78
79
|
* wrap STDOUT with host prefix for easy identification of system output
|
79
|
-
*
|
80
|
+
* Deal with timeouts/disconnects on persistent connections
|
80
81
|
|
81
82
|
## License
|
82
83
|
|
data/lib/gofer/host.rb
CHANGED
@@ -9,9 +9,13 @@ module Gofer
|
|
9
9
|
|
10
10
|
attr_reader :hostname
|
11
11
|
|
12
|
-
|
12
|
+
# Create a new Host connection
|
13
|
+
#
|
14
|
+
# +opts+ is passed through directly to Net::SSH.start
|
15
|
+
# See http://net-ssh.github.com/ssh/v2/api/index.html for valid arguments.
|
16
|
+
def initialize username, _hostname, opts={}
|
13
17
|
@hostname = _hostname
|
14
|
-
@ssh = SshWrapper.new(username, hostname,
|
18
|
+
@ssh = SshWrapper.new(username, hostname, opts)
|
15
19
|
end
|
16
20
|
|
17
21
|
# Run +command+.
|
data/lib/gofer/ssh_wrapper.rb
CHANGED
@@ -6,53 +6,53 @@ module Gofer
|
|
6
6
|
|
7
7
|
attr_reader :last_output, :last_exit_status
|
8
8
|
|
9
|
-
def initialize username, hostname,
|
9
|
+
def initialize username, hostname, opts={}
|
10
10
|
@username = username
|
11
11
|
@hostname = hostname
|
12
|
-
@identity_file = identity_file
|
13
12
|
@last_exit_status = nil
|
14
13
|
@last_output = nil
|
14
|
+
|
15
|
+
# support legacy positional argument use
|
16
|
+
if opts.is_a? String
|
17
|
+
opts = { :keys => [opts]}
|
18
|
+
end
|
19
|
+
|
20
|
+
# support legacy identity_file argument
|
21
|
+
if opts[:identity_file]
|
22
|
+
opts[:keys] = [opts.delete(:identity_file)]
|
23
|
+
end
|
24
|
+
|
25
|
+
@net_ssh_options = opts
|
15
26
|
end
|
16
27
|
|
17
28
|
def run command, opts={}
|
18
|
-
|
19
|
-
Net::SSH.start(*net_ssh_credentials) do |ssh|
|
20
|
-
response = ssh_execute(ssh, command, opts)
|
21
|
-
end
|
22
|
-
response
|
29
|
+
ssh_execute(ssh, command, opts)
|
23
30
|
end
|
24
31
|
|
25
32
|
def read_file path
|
26
|
-
|
27
|
-
with_scp do |scp|
|
28
|
-
a = scp.download! path
|
29
|
-
end
|
30
|
-
a
|
33
|
+
scp.download! path
|
31
34
|
end
|
32
35
|
|
33
36
|
def download from, to, opts={}
|
34
|
-
|
35
|
-
scp.download! from, to, opts
|
36
|
-
end
|
37
|
+
scp.download! from, to, opts
|
37
38
|
end
|
38
39
|
|
39
40
|
def upload from, to, opts={}
|
40
|
-
|
41
|
-
scp.upload! from, to, opts
|
42
|
-
end
|
41
|
+
scp.upload! from, to, opts
|
43
42
|
end
|
44
43
|
|
45
44
|
private
|
46
45
|
|
47
|
-
def
|
48
|
-
Net::
|
49
|
-
|
50
|
-
|
46
|
+
def ssh
|
47
|
+
@ssh ||= Net::SSH.start(*net_ssh_credentials)
|
48
|
+
end
|
49
|
+
|
50
|
+
def scp
|
51
|
+
@scp ||= Net::SCP.new(ssh)
|
51
52
|
end
|
52
53
|
|
53
54
|
def net_ssh_credentials
|
54
|
-
creds = [@hostname, @username]
|
55
|
-
creds << {:keys => [@identity_file] } if @identity_file
|
55
|
+
creds = [@hostname, @username, @net_ssh_options]
|
56
56
|
creds
|
57
57
|
end
|
58
58
|
|
data/lib/gofer/version.rb
CHANGED
@@ -30,7 +30,7 @@ describe Gofer do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
before :all do
|
33
|
-
@host = Gofer::Host.new(USERNAME, HOSTNAME, IDENTITY_FILE)
|
33
|
+
@host = Gofer::Host.new(USERNAME, HOSTNAME, :keys => [IDENTITY_FILE])
|
34
34
|
@tmpdir = raw_ssh("mktemp -d /tmp/gofertest.XXXXX").chomp
|
35
35
|
end
|
36
36
|
|
@@ -42,6 +42,16 @@ describe Gofer do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe :new do
|
46
|
+
it "should support the legacy positional argument" do
|
47
|
+
Gofer::Host.new(USERNAME, HOSTNAME, IDENTITY_FILE).run("echo hello", :quiet => true).should == "hello\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should support the legacy identity_file key" do
|
51
|
+
Gofer::Host.new(USERNAME, HOSTNAME, :identity_file => IDENTITY_FILE).run("echo hello", :quiet => true).should == "hello\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
45
55
|
describe :hostname do
|
46
56
|
it "should be the hostname of the host we're connecting to" do
|
47
57
|
@host.hostname.should == HOSTNAME
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gofer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Pearson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-03 00:00:00 +10:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|