runssh 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- runssh (0.2.0.rc.1)
4
+ runssh (0.2.2)
5
5
  highline (~> 1.6.1)
6
6
  trollop (~> 1.16.2)
7
7
 
data/README.rdoc CHANGED
@@ -87,14 +87,18 @@ This program is distributed under the GPL v2 license.
87
87
  === 0.2.1
88
88
  * Fixed docs.
89
89
 
90
+ === 0.2.2
91
+ * Enabled overriding hostname when invoking shell (Could be used to
92
+ bookmark a host with changing addresses - e.g. in EC2)
93
+ * Enabled definition of (local) ssh tunneling. Currently only in the
94
+ +shell+ command.
95
+
90
96
  == TODO
91
- * Convert to use thor as parent for RunSSHLib::CLI
97
+ * Refactor of RunSSHLib::CLI to avoid repetition of so many options between
98
+ _add_, _update_ and _shell_.
92
99
  * Create a _proper_ zsh completion script.
93
100
  * Add scp capabilities
94
- * Add tunneling support:
95
- 1. Configured tunneling
96
- 2. tunneling defined on the command line.
97
- * Remote commands (e.g, with no login).
101
+ * Add support for bookmarking tunnels
98
102
  * Shell via gateway (connect to a firewall and from there open shell to the host).
99
103
  * Rename (or move) host definition
100
104
  * Maybe replace invoking ssh from the command line with some library.
data/lib/runsshlib/cli.rb CHANGED
@@ -146,10 +146,19 @@ append "-- <remote command>" to the regular command. To list /tmp on a host
146
146
  bookmarked as "some host" run:
147
147
  runssh shell some host -- ls -l /tmp
148
148
 
149
+ (Local) tunneling can be enabled with the -L options (correspond to
150
+ ssh -L option). An abbreviated syntax could be used as the requested
151
+ port if both ports are identical and host is localhost.
152
+ e.g. -L 7070 is converted to -L 7070:localhost:7070
153
+
149
154
  Options:
150
155
  EOS
151
156
  opt :login, "override the login in the configuration",
152
157
  :type => :string
158
+ opt :host_name, 'override the name or address of the host',
159
+ :short => :n, :type => :string
160
+ opt :local_tunnel, "tunnel definition",
161
+ :short => :L, :type => :string
153
162
  stop_on "--"
154
163
  end
155
164
  # handle the case of remote command (indicated by --)
@@ -33,9 +33,20 @@ module RunSSHLib
33
33
  command = "ssh "
34
34
  command << "-l #{definition[:login]} " if definition[:login]
35
35
  command << "#{definition[:host_name]}"
36
+ command << " -L #{normalize_tunnel_definition definition[:local_tunnel]} " if
37
+ definition[:local_tunnel]
36
38
  command << %( -- "#{definition[:remote_cmd]}") if
37
39
  (definition[:remote_cmd] && (!definition[:remote_cmd].empty?))
38
40
  exec command
39
41
  end
42
+
43
+ # Accepts abbriviated or full definition of ssh tunnel definition
44
+ # and converts it to full tunnel definition. If only port is
45
+ # supplied (abbriviated form) it uses `localhost` as the hostname
46
+ # and the same port on both end of the tunnel definition.
47
+ def normalize_tunnel_definition(tunnel_definition)
48
+ tunnel_definition =~ /(^\d+$)/ ? "#{$1}:localhost:#{$1}" :
49
+ tunnel_definition
50
+ end
40
51
  end
41
52
  end
@@ -20,7 +20,7 @@ module RunSSHLib
20
20
  module Version
21
21
  MAJOR = 0
22
22
  MINOR = 2
23
- BUILD = 1
23
+ BUILD = 2
24
24
 
25
25
  STRING = [MAJOR, MINOR, BUILD].compact.join('.')
26
26
  end
@@ -186,8 +186,9 @@ describe "The CLI interface" do
186
186
  it "should have all required arguments" do
187
187
  options = @shell_cli.instance_variable_get :@options
188
188
  options.should have_key(:login)
189
+ options.should have_key(:local_tunnel)
189
190
  end
190
-
191
+
191
192
  it "should not overwrite nil arguments with saved ones when merging" do
192
193
  import_fixtures
193
194
  RunSSHLib::SshBackend.should_receive(:shell).
@@ -211,13 +212,22 @@ describe "The CLI interface" do
211
212
  cli.run
212
213
  end
213
214
 
215
+ it "should correctly allow overriding of hostname" do
216
+ import_fixtures
217
+ RunSSHLib::SshBackend.should_receive(:shell).
218
+ with(hash_including(:host_name => "overridehost"))
219
+ cli = RunSSHLib::CLI.new(
220
+ %W(-f #{TMP_FILE} shell -n overridehost cust2 dc internal somehost))
221
+ cli.run
222
+ end
223
+
214
224
  it "should correctly parse remote command (indicated by --)" do
215
225
  import_fixtures
216
226
  RunSSHLib::SshBackend.should_receive(:shell).
217
227
  with(hash_including(:remote_cmd => "ls -l /tmp")).
218
228
  and_return(nil)
219
229
  cli = RunSSHLib::CLI.new(
220
- %W(-f #{TMP_FILE} shell -l someuser cust2 dc internal somehost
230
+ %W(-f #{TMP_FILE} shell -l someuser cust2 dc internal somehost
221
231
  -- ls -l /tmp)
222
232
  )
223
233
  cli.run
@@ -20,7 +20,7 @@ require 'spec_helper'
20
20
  require 'runsshlib'
21
21
 
22
22
  describe RunSSHLib::SshBackend do
23
- context "shell" do
23
+ context "#shell" do
24
24
  let(:test_data) do
25
25
  {:host_name => "a",
26
26
  :login => "user",
@@ -66,5 +66,24 @@ describe RunSSHLib::SshBackend do
66
66
  and_return(nil)
67
67
  RunSSHLib::SshBackend.shell(data)
68
68
  end
69
+
70
+ it "should handle tunnels correctly" do
71
+ data = test_data.merge(:local_tunnel => "6000")
72
+ RunSSHLib::SshBackend.should_receive(:exec).
73
+ with(/^ssh\s+.*\s-L\s+6000:localhost:6000.*/)
74
+ RunSSHLib::SshBackend.shell(data)
75
+ end
76
+ end
77
+
78
+ context "#normalize_tunnel_definition" do
79
+ it "converts abbreviated tunnel definition correctly" do
80
+ RunSSHLib::SshBackend.normalize_tunnel_definition("7070").should ==
81
+ "7070:localhost:7070"
82
+ end
83
+
84
+ it "return full tunnel definition as it is" do
85
+ RunSSHLib::SshBackend.normalize_tunnel_definition("7070:localhost:7070").
86
+ should == "7070:localhost:7070"
87
+ end
69
88
  end
70
89
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runssh
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Haim Ashkenazi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-25 00:00:00 +02:00
18
+ date: 2011-02-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency