Narnach-simple_gate 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -0
- data/bin/gate_cp +9 -11
- data/bin/simple_gate +3 -8
- data/lib/simple_gate.rb +13 -5
- data/simple_gate.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -50,6 +50,13 @@ connection.
|
|
50
50
|
|
51
51
|
== Recent changes
|
52
52
|
|
53
|
+
=== Version 0.5.2
|
54
|
+
|
55
|
+
* Added -V verbose flag to gate_cp
|
56
|
+
* Use STDERR for status messages. STDOUT is used to output SSH responses
|
57
|
+
* Updated executables to support direct server connections
|
58
|
+
* SimpleGate#through_to can connect directly to a server without gateways
|
59
|
+
|
53
60
|
=== Version 0.5.1
|
54
61
|
|
55
62
|
* Updated readme and simple_gate documentation
|
data/bin/gate_cp
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Copy a single local file to a remote server.
|
3
|
-
# Syntax: gate_cp <server> <source_file> <target_file>
|
3
|
+
# Syntax: gate_cp [-V] <server> <source_file> <target_file>
|
4
4
|
# server: a server listed in ~/.servers.yml and reachable by a
|
5
5
|
# series of connections described in ~/.servers.connections.yml
|
6
6
|
# source_file: filename or full path+filename of local source file
|
7
7
|
# target_file: filename or full path+filename of target file
|
8
|
+
# Set -V for verbose output.
|
8
9
|
#
|
9
10
|
# Example: gate_cp foobar ~/foo.txt foo.txt
|
10
11
|
# This copies ~/foo.txt too the server foobar as foo.txt in the home dir
|
@@ -15,38 +16,35 @@ require 'simple_gate'
|
|
15
16
|
require 'simple_gate/router'
|
16
17
|
require 'net/sftp'
|
17
18
|
|
19
|
+
verbose = !ARGV.delete('-V').nil?
|
20
|
+
|
18
21
|
connections = YAML.load_file(File.expand_path('~/.servers.connections.yml'))
|
19
22
|
from = 'local'
|
20
23
|
target = ARGV.shift.to_s.strip
|
21
24
|
|
22
25
|
cmd = ARGV.join(" ")
|
23
26
|
if cmd.strip.size == 0
|
24
|
-
puts "No command was given"
|
27
|
+
STDERR.puts "No command was given"
|
25
28
|
exit 1
|
26
29
|
end
|
27
30
|
|
28
31
|
router = Router.new(connections)
|
29
32
|
route = router.find(from, target)
|
30
33
|
if route.nil?
|
31
|
-
puts "No route to #{target}"
|
34
|
+
STDERR.puts "No route to #{target}"
|
32
35
|
exit 1
|
33
36
|
end
|
34
37
|
|
35
38
|
route.shift if route.first == 'local'
|
36
39
|
|
37
|
-
if route.size==1
|
38
|
-
puts "No gateway needed to reach #{route.last}"
|
39
|
-
exit 2
|
40
|
-
end
|
41
|
-
|
42
40
|
source = File.expand_path(ARGV.shift.to_s.strip)
|
43
41
|
target = ARGV.shift.to_s.strip
|
44
42
|
|
45
|
-
puts "Connecting to #{route.last}, using #{route.size - 1} gateway(s)"
|
43
|
+
STDERR.puts "Connecting to #{route.last}, using #{route.size - 1} gateway(s)" if verbose
|
46
44
|
|
47
|
-
gate = SimpleGate.new
|
45
|
+
gate = SimpleGate.new(:verbose=>verbose)
|
48
46
|
gate.through_to(route) do |ssh|
|
49
|
-
puts "Transferring: #{source} => #{target}"
|
47
|
+
STDERR.puts "Transferring: #{source} => #{target}" if verbose
|
50
48
|
ssh.sftp.upload!(source, target)
|
51
49
|
end
|
52
50
|
|
data/bin/simple_gate
CHANGED
@@ -34,25 +34,20 @@ target = ARGV.shift.to_s.strip
|
|
34
34
|
|
35
35
|
cmd = ARGV.join(" ")
|
36
36
|
if cmd.strip.size == 0
|
37
|
-
puts "No command was given"
|
37
|
+
STDERR.puts "No command was given"
|
38
38
|
exit 1
|
39
39
|
end
|
40
40
|
|
41
41
|
router = Router.new(connections)
|
42
42
|
route = router.find(from, target)
|
43
43
|
if route.nil?
|
44
|
-
puts "No route to #{target}"
|
44
|
+
STDERR.puts "No route to #{target}"
|
45
45
|
exit 1
|
46
46
|
end
|
47
47
|
|
48
48
|
route.shift if route.first == 'local'
|
49
49
|
|
50
|
-
|
51
|
-
puts "No gateway needed to reach #{route.last}"
|
52
|
-
exit 2
|
53
|
-
end
|
54
|
-
|
55
|
-
puts "Executing '#{cmd}' in #{route.last}, using #{route.size - 1} gateway(s)" if verbose
|
50
|
+
STDERR.puts "Executing '#{cmd}' in #{route.last}, using #{route.size - 1} gateway(s)" if verbose
|
56
51
|
|
57
52
|
gate = SimpleGate.new(:verbose=>verbose)
|
58
53
|
gate.through_to(route) do |ssh|
|
data/lib/simple_gate.rb
CHANGED
@@ -17,11 +17,18 @@ class SimpleGate
|
|
17
17
|
|
18
18
|
# Connect through a list of gateways to the real server.
|
19
19
|
# Treats the last 'gateway' as the real server and the others as gateways.
|
20
|
-
# Needs at least one real gateway and a real server.
|
21
20
|
def through_to(*gateways) # :yields: ssh session
|
22
21
|
gateways = gateways.flatten
|
23
|
-
raise ArgumentError.new("
|
22
|
+
raise ArgumentError.new("No target chosen") if gateways.size == 0
|
24
23
|
target = ServerDefinition.find(gateways.pop)
|
24
|
+
if gateways.size == 0
|
25
|
+
target.connection_info do |host, user, options|
|
26
|
+
Net::SSH.start(host,user,options) do |session|
|
27
|
+
yield(session)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return
|
31
|
+
end
|
25
32
|
through(gateways) do |gate|
|
26
33
|
target.connection_info do |host, user, options|
|
27
34
|
gate.ssh(host, user, options) do |session|
|
@@ -29,6 +36,7 @@ class SimpleGate
|
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
39
|
+
nil
|
32
40
|
end
|
33
41
|
|
34
42
|
# Most of the code was taken from Capistrano and then changed to work
|
@@ -38,18 +46,18 @@ class SimpleGate
|
|
38
46
|
@open_connections ||= []
|
39
47
|
@gateways = gateways.flatten.collect { |g| ServerDefinition.find(g) }
|
40
48
|
tunnel = @gateways[0].connection_info do |host, user, connect_options|
|
41
|
-
puts "Setting up tunnel #{@gateways[0]}" if verbose?
|
49
|
+
STDERR.puts "Setting up tunnel #{@gateways[0]}" if verbose?
|
42
50
|
gw = Net::SSH::Gateway.new(host, user, connect_options)
|
43
51
|
@open_connections << gw
|
44
52
|
gw
|
45
53
|
end
|
46
54
|
@gateway = (@gateways[1..-1]).inject(tunnel) do |tunnel, destination|
|
47
|
-
puts "Connecting to #{destination}" if verbose?
|
55
|
+
STDERR.puts "Connecting to #{destination}" if verbose?
|
48
56
|
tunnel_port = tunnel.open(destination.host, (destination.port || 22))
|
49
57
|
localhost_options = {:user => destination.user, :port => tunnel_port, :password => destination.password}
|
50
58
|
local_host = ServerDefinition.new("127.0.0.1", localhost_options)
|
51
59
|
local_host.connection_info do |host, user, connect_options|
|
52
|
-
puts "Connecting using local info #{local_host}" if verbose?
|
60
|
+
STDERR.puts "Connecting using local info #{local_host}" if verbose?
|
53
61
|
gw = Net::SSH::Gateway.new(host, user, connect_options)
|
54
62
|
@open_connections << gw
|
55
63
|
gw
|
data/simple_gate.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'simple_gate'
|
4
4
|
s.summary = "SimpleGate makes it possible to use net/ssh/gateway's capabilities in a simple to use way."
|
5
5
|
s.description = s.summary
|
6
|
-
s.version = '0.5.
|
6
|
+
s.version = '0.5.2'
|
7
7
|
s.date = '2009-04-18'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|