thor-ssh 0.1.8 → 0.1.9
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/.rpsec +0 -0
- data/.rspec +2 -0
- data/Gemfile +1 -0
- data/lib/thor-ssh/actions.rb +6 -0
- data/lib/thor-ssh/remote_file.rb +13 -2
- data/lib/thor-ssh/remote_server.rb +10 -3
- data/lib/thor-ssh/version.rb +1 -1
- data/spec/actions_spec.rb +18 -8
- data/spec/vagrant/vagrant_manager.rb +1 -0
- metadata +5 -3
data/.rpsec
ADDED
File without changes
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/lib/thor-ssh/actions.rb
CHANGED
data/lib/thor-ssh/remote_file.rb
CHANGED
@@ -11,14 +11,23 @@ module ThorSsh
|
|
11
11
|
@base = base
|
12
12
|
@connection = connection
|
13
13
|
end
|
14
|
+
|
15
|
+
# This is a workaround for bug:
|
16
|
+
# https://github.com/net-ssh/net-sftp/issues/13
|
17
|
+
def close_sftp!
|
18
|
+
connection.sftp.close_channel()
|
19
|
+
connection.instance_variable_set('@sftp', nil)
|
20
|
+
end
|
14
21
|
|
15
22
|
def exists?(path)
|
16
23
|
begin
|
17
|
-
connection.sftp.stat!(path)
|
24
|
+
res = connection.sftp.stat!(path)
|
18
25
|
rescue Net::SFTP::StatusException
|
26
|
+
close_sftp!
|
19
27
|
return false
|
20
28
|
end
|
21
29
|
|
30
|
+
close_sftp!
|
22
31
|
return true
|
23
32
|
end
|
24
33
|
|
@@ -52,10 +61,11 @@ module ThorSsh
|
|
52
61
|
connection.sftp.file.open(path, "rb") do |f|
|
53
62
|
data = f.read
|
54
63
|
end
|
64
|
+
close_sftp!
|
55
65
|
else
|
56
66
|
# We just run this as root, when reading we don't need to go back
|
57
67
|
# down to the user
|
58
|
-
data = @
|
68
|
+
data = @base.destination_server.run("cat \"#{path}\"")
|
59
69
|
end
|
60
70
|
|
61
71
|
return data
|
@@ -65,6 +75,7 @@ module ThorSsh
|
|
65
75
|
def binwrite(path, data)
|
66
76
|
io = StringIO.new(data)
|
67
77
|
connection.sftp.upload!(io, path)
|
78
|
+
close_sftp!
|
68
79
|
end
|
69
80
|
|
70
81
|
def chmod(mode, file_name)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'net/ssh'
|
2
|
-
require 'net/sftp'
|
2
|
+
# require 'net/sftp'
|
3
3
|
|
4
4
|
module ThorSsh
|
5
5
|
class RemoteServer
|
@@ -16,8 +16,8 @@ module ThorSsh
|
|
16
16
|
stderr_data = ""
|
17
17
|
exit_code = nil
|
18
18
|
exit_signal = nil
|
19
|
-
connection.open_channel do |
|
20
|
-
|
19
|
+
channel = connection.open_channel do |cha|
|
20
|
+
cha.exec(command) do |ch, success|
|
21
21
|
unless success
|
22
22
|
abort "FAILED: couldn't execute command (connection.channel.exec)"
|
23
23
|
end
|
@@ -36,8 +36,15 @@ module ThorSsh
|
|
36
36
|
channel.on_request("exit-signal") do |ch, data|
|
37
37
|
exit_signal = data.read_long
|
38
38
|
end
|
39
|
+
|
40
|
+
# channel.on_close do |ch|
|
41
|
+
# puts "Channel is Closing! #{connection.closed?}"
|
42
|
+
# channel.close
|
43
|
+
# end
|
39
44
|
end
|
40
45
|
# channel.wait
|
46
|
+
# puts "Done Loop"
|
47
|
+
# channel.close
|
41
48
|
end
|
42
49
|
connection.loop
|
43
50
|
|
data/lib/thor-ssh/version.rb
CHANGED
data/spec/actions_spec.rb
CHANGED
@@ -4,20 +4,15 @@ require 'vagrant/vagrant_manager'
|
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe "Thor SSH" do
|
8
8
|
before do
|
9
9
|
# Setup the test and connect to a test server
|
10
|
-
@remote_test = ThorTest.new
|
11
|
-
@remote_test.destination_connection = VagrantManager.connect
|
12
|
-
|
10
|
+
# @remote_test = ThorTest.new
|
13
11
|
@local_test = ThorTest.new
|
14
12
|
@local_test.destination_root = File.join(File.dirname(__FILE__), '/tmp/')
|
15
13
|
end
|
16
14
|
|
17
15
|
after do
|
18
|
-
# Close the connection
|
19
|
-
@remote_test.destination_connection.close
|
20
|
-
|
21
16
|
# Clear local tmp dir
|
22
17
|
FileUtils.rm_rf(File.join(File.dirname(__FILE__), '/tmp/test/'))
|
23
18
|
end
|
@@ -29,12 +24,17 @@ describe ThorSsh do
|
|
29
24
|
@remote_test = ThorTest.new
|
30
25
|
@remote_test.destination_connection = VagrantManager.connect
|
31
26
|
@remote_test.destination_files.rm_rf(@remote_base_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:all) do
|
30
|
+
# Close the remote connection
|
32
31
|
@remote_test.destination_connection.close
|
33
|
-
|
34
32
|
end
|
33
|
+
|
35
34
|
|
36
35
|
it 'should create an empty directory remotely' do
|
37
36
|
@remote_test.empty_directory(@remote_base_path)
|
37
|
+
@remote_test.empty_directory(@remote_base_path + '2')
|
38
38
|
@remote_test.destination_files.exists?(@remote_base_path)
|
39
39
|
end
|
40
40
|
|
@@ -182,6 +182,16 @@ describe ThorSsh do
|
|
182
182
|
stdout, stderr, exit_code, exit_signal = @local_test.exec('true', true)
|
183
183
|
exit_code.should == 0
|
184
184
|
end
|
185
|
+
|
186
|
+
it "should switch users" do
|
187
|
+
@remote_test.as_user('root') do
|
188
|
+
@remote_test.exec('whoami').strip.should == 'root'
|
189
|
+
end
|
190
|
+
|
191
|
+
@remote_test.as_root do
|
192
|
+
@remote_test.exec('whoami').strip.should == 'root'
|
193
|
+
end
|
194
|
+
end
|
185
195
|
end
|
186
196
|
|
187
197
|
|
@@ -27,6 +27,7 @@ class VagrantManager
|
|
27
27
|
# Connect to SSH, giving it a few tries
|
28
28
|
return Net::SSH.start(ssh_info[:host], ssh_info[:username], opts)
|
29
29
|
|
30
|
+
|
30
31
|
# return Net::SSH.start("127.0.0.1", "vagrant", {:port=>2222, :keys=>["/Users/ryanstout/.vagrant.d/insecure_private_key"], :keys_only=>true, :user_known_hosts_file=>[], :paranoid=>false, :config=>false, :forward_agent=>false, :verbose=>:debug, :timeout=>1})
|
31
32
|
end
|
32
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor-ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -164,6 +164,8 @@ extensions: []
|
|
164
164
|
extra_rdoc_files: []
|
165
165
|
files:
|
166
166
|
- .gitignore
|
167
|
+
- .rpsec
|
168
|
+
- .rspec
|
167
169
|
- Gemfile
|
168
170
|
- LICENSE
|
169
171
|
- README.md
|
@@ -205,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
207
|
version: '0'
|
206
208
|
segments:
|
207
209
|
- 0
|
208
|
-
hash:
|
210
|
+
hash: 2434700529121181325
|
209
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
212
|
none: false
|
211
213
|
requirements:
|
@@ -214,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
216
|
version: '0'
|
215
217
|
segments:
|
216
218
|
- 0
|
217
|
-
hash:
|
219
|
+
hash: 2434700529121181325
|
218
220
|
requirements: []
|
219
221
|
rubyforge_project:
|
220
222
|
rubygems_version: 1.8.22
|