gofer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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', :identity_file => 'key.pem')
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
- * RDoc
80
+ * Deal with timeouts/disconnects on persistent connections
80
81
 
81
82
  ## License
82
83
 
@@ -9,9 +9,13 @@ module Gofer
9
9
 
10
10
  attr_reader :hostname
11
11
 
12
- def initialize username, _hostname, identity_file=nil
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, identity_file)
18
+ @ssh = SshWrapper.new(username, hostname, opts)
15
19
  end
16
20
 
17
21
  # Run +command+.
@@ -6,53 +6,53 @@ module Gofer
6
6
 
7
7
  attr_reader :last_output, :last_exit_status
8
8
 
9
- def initialize username, hostname, identity_file = nil
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
- response = nil
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
- a = nil
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
- with_scp do |scp|
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
- with_scp do |scp|
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 with_scp
48
- Net::SCP.start(*net_ssh_credentials) do |scp|
49
- yield scp
50
- end
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
 
@@ -1,3 +1,3 @@
1
1
  module Gofer # :nodoc:
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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.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-04-23 00:00:00 +10:00
13
+ date: 2011-05-03 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency