libssh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.clang-format +3 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +30 -0
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/exec.rb +52 -0
- data/example/sshkit.rb +22 -0
- data/example/write.rb +54 -0
- data/ext/libssh_ruby/channel.c +350 -0
- data/ext/libssh_ruby/error.c +25 -0
- data/ext/libssh_ruby/extconf.rb +9 -0
- data/ext/libssh_ruby/key.c +98 -0
- data/ext/libssh_ruby/libssh_ruby.c +27 -0
- data/ext/libssh_ruby/libssh_ruby.h +34 -0
- data/ext/libssh_ruby/session.c +281 -0
- data/lib/libssh.rb +7 -0
- data/lib/libssh/key.rb +9 -0
- data/lib/libssh/version.rb +4 -0
- data/lib/sshkit/backends/libssh.rb +92 -0
- data/libssh.gemspec +29 -0
- metadata +142 -0
data/lib/libssh.rb
ADDED
data/lib/libssh/key.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'libssh'
|
2
|
+
require 'sshkit/backends/abstract'
|
3
|
+
require 'sshkit/backends/connection_pool'
|
4
|
+
|
5
|
+
module SSHKit
|
6
|
+
module Backend
|
7
|
+
class Libssh < Abstract
|
8
|
+
class Configuration
|
9
|
+
attr_accessor :pty, :connection_timeout, :ssh_options
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
self.pty = false
|
14
|
+
self.connection_timeout = 30
|
15
|
+
self.ssh_options = {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
BUFSIZ = 16384
|
20
|
+
|
21
|
+
@pool = SSHKit::Backend::ConnectionPool.new
|
22
|
+
|
23
|
+
class << self
|
24
|
+
attr_accessor :pool
|
25
|
+
|
26
|
+
# @override
|
27
|
+
def config
|
28
|
+
@config ||= Configuration.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def execute_command(cmd)
|
35
|
+
output.log_command_start(cmd)
|
36
|
+
cmd.started = true
|
37
|
+
|
38
|
+
with_session do |session|
|
39
|
+
channel = LibSSH::Channel.new(session)
|
40
|
+
channel.open_session do
|
41
|
+
if Libssh.config.pty
|
42
|
+
channel.request_pty
|
43
|
+
end
|
44
|
+
channel.request_exec(cmd.to_command)
|
45
|
+
until channel.eof?
|
46
|
+
stdout_avail = channel.poll(timeout: 1)
|
47
|
+
if stdout_avail && stdout_avail > 0
|
48
|
+
buf = channel.read(BUFSIZ)
|
49
|
+
cmd.on_stdout(channel, buf)
|
50
|
+
output.log_command_data(cmd, :stdout, buf)
|
51
|
+
end
|
52
|
+
|
53
|
+
stderr_avail = channel.poll(stderr: true, timeout: 1)
|
54
|
+
if stderr_avail && stderr_avail > 0
|
55
|
+
buf = channel.read(BUFSIZ, stderr: true)
|
56
|
+
cmd.on_stderr(channel, buf)
|
57
|
+
output.log_command_data(cmd, :stderr, buf)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
cmd.exit_status = channel.get_exit_status
|
62
|
+
output.log_command_exit(cmd)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def with_session
|
68
|
+
entry = self.class.pool.checkout(host.hostname) do
|
69
|
+
LibSSH::Session.new.tap do |session|
|
70
|
+
session.host = host.hostname
|
71
|
+
session.parse_config
|
72
|
+
session.add_identity('%d/id_ed25519')
|
73
|
+
|
74
|
+
session.connect
|
75
|
+
if session.server_known != LibSSH::SERVER_KNOWN_OK
|
76
|
+
raise 'unknown host'
|
77
|
+
end
|
78
|
+
if session.userauth_publickey_auto != LibSSH::AUTH_SUCCESS
|
79
|
+
raise 'authorization failed'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
begin
|
85
|
+
yield entry.connection
|
86
|
+
ensure
|
87
|
+
self.class.pool.checkin(entry)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/libssh.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'libssh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'libssh'
|
8
|
+
spec.version = LibSSH::VERSION
|
9
|
+
spec.authors = ['Kohei Suzuki']
|
10
|
+
spec.email = ['eagletmt@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Ruby binding for libssh.'
|
13
|
+
spec.description = 'Ruby binding for libssh.'
|
14
|
+
spec.homepage = 'https://github.com/eagletmt/libssh-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = '>= 2.2.0'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
spec.extensions = ['ext/libssh_ruby/extconf.rb']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rake-compiler'
|
27
|
+
spec.add_development_dependency 'sshkit'
|
28
|
+
spec.add_development_dependency 'rubocop', '>= 0.36.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libssh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kohei Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sshkit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.36.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.36.0
|
83
|
+
description: Ruby binding for libssh.
|
84
|
+
email:
|
85
|
+
- eagletmt@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions:
|
88
|
+
- ext/libssh_ruby/extconf.rb
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".clang-format"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".rubocop_todo.yml"
|
95
|
+
- ".travis.yml"
|
96
|
+
- CHANGELOG.md
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- example/exec.rb
|
104
|
+
- example/sshkit.rb
|
105
|
+
- example/write.rb
|
106
|
+
- ext/libssh_ruby/channel.c
|
107
|
+
- ext/libssh_ruby/error.c
|
108
|
+
- ext/libssh_ruby/extconf.rb
|
109
|
+
- ext/libssh_ruby/key.c
|
110
|
+
- ext/libssh_ruby/libssh_ruby.c
|
111
|
+
- ext/libssh_ruby/libssh_ruby.h
|
112
|
+
- ext/libssh_ruby/session.c
|
113
|
+
- lib/libssh.rb
|
114
|
+
- lib/libssh/key.rb
|
115
|
+
- lib/libssh/version.rb
|
116
|
+
- lib/sshkit/backends/libssh.rb
|
117
|
+
- libssh.gemspec
|
118
|
+
homepage: https://github.com/eagletmt/libssh-ruby
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 2.2.0
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.5.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Ruby binding for libssh.
|
142
|
+
test_files: []
|