sshkit-interact 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c52924fccff016cd1667f603a179b0a43f86bf0
4
+ data.tar.gz: fe0fe8ba30373b27f14efd89b4bbe000f067b4ff
5
+ SHA512:
6
+ metadata.gz: 8bf995142ce2fe540ac9a471c6a806386343ad3cde62492b233c1ecf38e1dbd4e2db1976d1edf07d2d76a6df3d57d09a0546853b28299838103579a0a688b5c8
7
+ data.tar.gz: 7b140b2070304c18efab433193e0df3478d3bc24cb5436456468ab11b720314d642ddf4e1c8c64c03f0a23868618e9d228701fa6735a3787e29e02b59a823fdb
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ # Change Log
2
+
3
+ ## Unreleased
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sshkit-interact.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Florian Schwab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/sshkit-interact.svg)](https://rubygems.org/gems/sshkit-interact)
2
+ [![Dependencies](https://img.shields.io/gemnasium/ydkn/sshkit-interact.svg)](https://gemnasium.com/ydkn/sshkit-interact)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/sshkit-interact.svg)](https://codeclimate.com/github/ydkn/sshkit-interact)
4
+
5
+ [![Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ydkn/sshkit-interact)
6
+
7
+
8
+ # SSHKIT::Interact
9
+
10
+ Interactive command execution for SSHKit.
11
+
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'sshkit-interact'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install sshkit-interact
28
+
29
+
30
+ ## Usage
31
+
32
+ Switch SSHKit backend:
33
+
34
+ ```ruby
35
+ require 'sshkit/interact'
36
+
37
+ SSHKit.backend = SSHKit::Interact::Backend
38
+ ```
39
+
40
+ And use _interact_ instead of _execute_:
41
+
42
+ ```ruby
43
+ within '/foo/bar' do
44
+ interact(:bash)
45
+ end
46
+ ```
47
+
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydkn/sshkit-interact.
52
+
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'sshkit/interact'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'sshkit/interact/backend'
@@ -0,0 +1,15 @@
1
+ require 'sshkit/backends/netssh'
2
+ require 'sshkit/interact/command'
3
+
4
+ module SSHKit
5
+ module Interact
6
+ # Backend with interactivity
7
+ class Backend < SSHKit::Backend::Netssh
8
+ @pool = SSHKit::Backend::ConnectionPool.new
9
+
10
+ def interact(*args)
11
+ SSHKit::Interact::Command.new(host, command(*args)).execute
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ module SSHKit
2
+ module Interact
3
+ # Command wrapper
4
+ class Command
5
+ def initialize(host, command)
6
+ @host = host
7
+ @command = command
8
+ end
9
+
10
+ def to_cmd
11
+ [
12
+ :ssh,
13
+ *ssh_cmd_args,
14
+ @host.hostname,
15
+ %Q{'$SHELL -l -c "#{@command.to_command}"'}
16
+ ].join(' ')
17
+ end
18
+
19
+ def execute
20
+ exec(to_cmd)
21
+ end
22
+
23
+ private
24
+
25
+ def ssh_option(attr_name)
26
+ (@host.netssh_options || {})[attr_name] || (@host.respond_to?(attr_name) ? @host.send(attr_name) : nil)
27
+ end
28
+
29
+ def host_name
30
+ ssh_option(:host_name)
31
+ end
32
+
33
+ def port
34
+ ssh_option(:port)
35
+ end
36
+
37
+ def user
38
+ ssh_option(:user)
39
+ end
40
+
41
+ def forward_agent?
42
+ !!ssh_option(:forward_agent)
43
+ end
44
+
45
+ def proxy_command
46
+ ssh_option(:proxy) ? ssh_option(:proxy).command_line_template : nil
47
+ end
48
+
49
+ def keys
50
+ Array(ssh_option(:keys))
51
+ end
52
+
53
+ def ssh_cmd_args
54
+ args = []
55
+
56
+ args << '-t'
57
+ args << '-A' if forward_agent?
58
+ args << "-p #{port}" if port
59
+ args << "-l #{user}"
60
+ args << %Q{-o "ProxyCommand #{proxy_command}"} if proxy_command
61
+ args << %Q{-o "HostName #{host_name}"} if host_name
62
+
63
+ keys.each do |key|
64
+ args << "-i #{key}"
65
+ end
66
+
67
+ args
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ # SSHKit
2
+ module SSHKit
3
+ # Interact
4
+ module Interact
5
+ # Gem version
6
+ VERSION = '0.1.0'
7
+ end
8
+ 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/interact/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sshkit-interact'
8
+ spec.version = SSHKit::Interact::VERSION
9
+ spec.authors = ['Florian Schwab']
10
+ spec.email = ['me@ydkn.de']
11
+
12
+ spec.summary = %q{Interactive command execution for SSHKit}
13
+ spec.description = %q{Interactive command execution for SSHKit}
14
+ spec.homepage = 'https://github.com/ydkn/sshkit-interact'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'sshkit', '~> 1.7.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sshkit-interact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Schwab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-12 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: 1.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: Interactive command execution for SSHKit
56
+ email:
57
+ - me@ydkn.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/sshkit/interact.rb
71
+ - lib/sshkit/interact/backend.rb
72
+ - lib/sshkit/interact/command.rb
73
+ - lib/sshkit/interact/version.rb
74
+ - sshkit-interact.gemspec
75
+ homepage: https://github.com/ydkn/sshkit-interact
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.8
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Interactive command execution for SSHKit
99
+ test_files: []
100
+ has_rdoc: