sshkit-sudo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85165b7a964cdf190a07333fdeccfa0bae2245cc
4
+ data.tar.gz: 4fd29dd814d0723b82820a9fb316bb07a4341700
5
+ SHA512:
6
+ metadata.gz: 235c4f129e985cdaf9c8e51c0e13ab14aaf1be7d3be5f6eb178a80861f268bbd7d8285f5e4c557ec615ae4ec91413a86fd09263beb92b82f2ecdea58ebbb1157
7
+ data.tar.gz: ab21701f75d6e67cde2bbc5c8fad306db4c2a99acf8153f835e9d3e7f7fc2db9a89d82616eec313e44451a28ee97c2c3fbfd5a5e7f2f1db3c9d77420efd9ab8e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sshkit-sudo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Kentaro Imai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # SSHKit::Sudo
2
+
3
+ SSHKit extension, for sudo operation with password input.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sshkit-sudo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ If you're using Capistrano, add the following to your Capfile:
18
+
19
+ ```ruby
20
+ require 'sshkit/sudo'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ This gem adds `sudo` command to SSHKit backends.
26
+
27
+ To execute a command with sudo, call `sudo` instead of `execute`.
28
+
29
+ ```ruby
30
+ # Executing a command with sudo in Capistrano task
31
+ desc 'hello'
32
+ task :hello do
33
+ on roles(:all) do
34
+ sudo :cp, '~/something', '/something'
35
+ end
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/[my-github-username]/sshkit-sudo/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ require "sshkit/sudo/version"
2
+ require "sshkit/sudo/backends_ext/printer"
3
+ require "sshkit/sudo/backends_ext/netssh"
4
+ require "sshkit/sudo/backends_ext/local"
@@ -0,0 +1,11 @@
1
+ require 'sshkit'
2
+
3
+ module SSHKit
4
+ module Backend
5
+ class Local < Printer
6
+ def sudo(*args)
7
+ _execute(:sudo, *args).success?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,75 @@
1
+ # require 'net/ssh'
2
+ require 'sshkit'
3
+ # require 'sshkit/backend/netssh'
4
+
5
+ module SSHKit
6
+ module Backend
7
+
8
+ class Netssh < Printer
9
+ def sudo(*args)
10
+ _sudo(*args).success?
11
+ end
12
+
13
+ private
14
+
15
+ def _sudo(*args)
16
+ command(:sudo, *args).tap do |cmd|
17
+ output << cmd
18
+ cmd.started = true
19
+ exit_status = nil
20
+ with_ssh do |ssh|
21
+ ssh.open_channel do |chan|
22
+ chan.request_pty
23
+ chan.exec cmd.to_command do |ch, success|
24
+ chan.on_data do |ch, data|
25
+ cmd.stdout = data
26
+ cmd.full_stdout += data
27
+ output << cmd
28
+
29
+ if data =~ /password.*:/
30
+ pass = $stdin.noecho(&:gets)
31
+ ch.send_data(pass)
32
+ end
33
+ end
34
+ chan.on_extended_data do |ch, type, data|
35
+ cmd.stderr = data
36
+ cmd.full_stderr += data
37
+ output << cmd
38
+ end
39
+ chan.on_request("exit-status") do |ch, data|
40
+ exit_status = data.read_long
41
+ end
42
+ #chan.on_request("exit-signal") do |ch, data|
43
+ # # TODO: This gets called if the program is killed by a signal
44
+ # # might also be a worthwhile thing to report
45
+ # exit_signal = data.read_string.to_i
46
+ # warn ">>> " + exit_signal.inspect
47
+ # output << cmd
48
+ #end
49
+ chan.on_open_failed do |ch|
50
+ # TODO: What do do here?
51
+ # I think we should raise something
52
+ end
53
+ chan.on_process do |ch|
54
+ # TODO: I don't know if this is useful
55
+ end
56
+ chan.on_eof do |ch|
57
+ # TODO: chan sends EOF before the exit status has been
58
+ # writtend
59
+ end
60
+ end
61
+ chan.wait
62
+ end
63
+ ssh.loop
64
+ end
65
+ # Set exit_status and log the result upon completion
66
+ if exit_status
67
+ cmd.exit_status = exit_status
68
+ output << cmd
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,13 @@
1
+ require 'sshkit'
2
+
3
+ module SSHKit
4
+ module Backend
5
+ class Printer < Abstract
6
+ def sudo(*args)
7
+ command(:sudo, *args).tap do |cmd|
8
+ output << cmd
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module SSHKit
2
+ module Sudo
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sshkit/sudo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sshkit-sudo"
8
+ spec.version = SSHKit::Sudo::VERSION
9
+ spec.authors = ["Kentaro Imai"]
10
+ spec.email = ["kentaroi@gmail.com"]
11
+ spec.summary = %q{SSHKit extension, for sudo operation with password input.}
12
+ spec.description = %q{SSHKit extension, for sudo operation with password input.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 1.9.3"
22
+
23
+ spec.add_dependency "sshkit"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sshkit-sudo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Imai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sshkit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: SSHKit extension, for sudo operation with password input.
56
+ email:
57
+ - kentaroi@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/sshkit/sudo.rb
68
+ - lib/sshkit/sudo/backends_ext/local.rb
69
+ - lib/sshkit/sudo/backends_ext/netssh.rb
70
+ - lib/sshkit/sudo/backends_ext/printer.rb
71
+ - lib/sshkit/sudo/version.rb
72
+ - sshkit-sudo.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 1.9.3
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: SSHKit extension, for sudo operation with password input.
97
+ test_files: []