spectre-ssh 1.0.2 → 1.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/ssh.rb +31 -13
  3. metadata +11 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 180b0db0cfa9d88522b4f4147f5b2e2e2bdb2c9da4743d6fac85599f71769ea6
4
- data.tar.gz: 7b65847ee82c04053f4ad6d1bc91aab8aa92aada3703505027bb3167a35bd5fd
3
+ metadata.gz: 471635f940f6c5c48d2d7e5645dc869d21180fb8e4aadecf3c60982fc1eb343f
4
+ data.tar.gz: 6bbbff4e6993938a834e85d50541a95ab51ce2085e61d73eb073821a85256b78
5
5
  SHA512:
6
- metadata.gz: 907a71a63ac527f78b981c5dde110ce5914361685195d7827d23e6d716dbeea7402dadbbe849e0cb13c3b63ebcb01a5c26a76fac3be14109d99ddca20858147e
7
- data.tar.gz: 1b9031c4c95d3773fe1b8fe83f310149a3c07226cc66ddce63efffabae98c27b745d54db774e80cb7801c98db298cc8139ce184508dd7ec685d767a2b5f5eb29
6
+ metadata.gz: de5f1b6829bbb9206d9d20e50bbedea9f037864e800e9fdf1bfebc1fbeacfcbadff2cd7bef9ce403687b23e22afe0a9f4ce10e1b2ee2b46b850fe3838de0237e
7
+ data.tar.gz: bd7c49933f0ef4f707261a1046dfbc0b66fc6b5c495f33d167da3b58a6fb48d23ceeb362f57638984830d4229693a145317303f5ad2d3443800266aaae6859a3
data/lib/spectre/ssh.rb CHANGED
@@ -1,16 +1,13 @@
1
1
  require 'net/ssh'
2
2
  require 'logger'
3
3
  require 'spectre'
4
-
4
+ require 'net/ssh/proxy/http'
5
5
 
6
6
  module Spectre
7
7
  module SSH
8
8
  @@cfg = {}
9
9
 
10
10
  class SSHError < Exception
11
- def initialize message
12
- super message
13
- end
14
11
  end
15
12
 
16
13
  class SSHConnection < Spectre::DslClass
@@ -26,6 +23,24 @@ module Spectre
26
23
  @__output = ''
27
24
  end
28
25
 
26
+ def username user
27
+ @__username = user
28
+ end
29
+
30
+ def password pass
31
+ @__opts[:password] = pass
32
+ @__opts[:auth_methods].push 'password' unless @__opts[:auth_methods].include? 'password'
33
+ end
34
+
35
+ def private_key file_path
36
+ @__opts[:keys] = [file_path]
37
+ @__opts[:auth_methods].push 'publickey' unless @__opts[:auth_methods].include? 'publickey'
38
+ end
39
+
40
+ def passphrase phrase
41
+ @__opts[:passphrase] = phrase
42
+ end
43
+
29
44
  def file_exists path
30
45
  exec "ls #{path}"
31
46
  exit_code == 0
@@ -38,6 +53,7 @@ module Spectre
38
53
 
39
54
  def connect!
40
55
  return unless @__session == nil or @__session.closed?
56
+
41
57
  begin
42
58
  @__session = Net::SSH.start(@__host, @__username, @__opts)
43
59
  rescue SocketError
@@ -49,6 +65,7 @@ module Spectre
49
65
 
50
66
  def close
51
67
  return unless @__session and not @__session.closed?
68
+
52
69
  @__session.close
53
70
  end
54
71
 
@@ -76,20 +93,20 @@ module Spectre
76
93
  log_str = "#{@__session.options[:user]}@#{@__session.host} -p #{@__session.options[:port]} #{command}"
77
94
 
78
95
  @channel = @__session.open_channel do |channel|
79
- channel.exec(command) do |ch, success|
96
+ channel.exec(command) do |_ch, success|
80
97
  abort "could not execute #{command} on #{@__session.host}" unless success
81
98
 
82
99
  @__output = ''
83
100
 
84
- channel.on_data do |ch, data|
101
+ channel.on_data do |_, data|
85
102
  @__output += data
86
103
  end
87
104
 
88
- channel.on_extended_data do |ch,type,data|
105
+ channel.on_extended_data do |_, _type, data|
89
106
  @__output += data
90
107
  end
91
108
 
92
- channel.on_request('exit-status') do |ch, data|
109
+ channel.on_request('exit-status') do |_, data|
93
110
  @__exit_code = data.read_long
94
111
  end
95
112
 
@@ -97,7 +114,6 @@ module Spectre
97
114
  # exit_code = data.read_long
98
115
  # end
99
116
  end
100
-
101
117
  end
102
118
 
103
119
  @channel.wait
@@ -119,8 +135,6 @@ module Spectre
119
135
 
120
136
  class << self
121
137
  def ssh name, options = {}, &block
122
- raise "SSH connection '#{name}' not configured" unless @@cfg.key?(name) or options.count > 0
123
-
124
138
  cfg = @@cfg[name] || {}
125
139
 
126
140
  host = cfg['host'] || name
@@ -139,6 +153,10 @@ module Spectre
139
153
  opts[:auth_methods].push 'publickey' unless opts[:keys].nil? or opts[:keys].empty?
140
154
  opts[:auth_methods].push 'password' unless opts[:password].nil?
141
155
 
156
+ proxy_host = options[:proxy_host] || cfg['proxy_host']
157
+ proxy_port = options[:proxy_port] || cfg['proxy_port']
158
+ opts[:proxy] = Net::SSH::Proxy::HTTP.new(proxy_host, proxy_port) unless proxy_host.nil?
159
+
142
160
  ssh_con = SSHConnection.new(host, username, opts, @@logger)
143
161
 
144
162
  begin
@@ -150,7 +168,7 @@ module Spectre
150
168
  end
151
169
 
152
170
  Spectre.register do |config|
153
- @@logger = ::Logger.new config['log_file'], progname: 'spectre/ssh'
171
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/ssh')
154
172
 
155
173
  if config.key? 'ssh'
156
174
  config['ssh'].each do |name, cfg|
@@ -161,4 +179,4 @@ module Spectre
161
179
 
162
180
  Spectre.delegate :ssh, to: self
163
181
  end
164
- end
182
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.0
33
+ version: 7.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.0
40
+ version: 7.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: spectre-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.8.0
47
+ version: 1.14.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.8.0
54
+ version: 1.14.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ed25519
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,11 +92,10 @@ homepage: https://github.com/ionos-spectre/spectre-ssh
92
92
  licenses:
93
93
  - MIT
94
94
  metadata:
95
- allowed_push_host: https://rubygems.org/
96
95
  homepage_uri: https://github.com/ionos-spectre/spectre-ssh
97
96
  source_code_uri: https://github.com/ionos-spectre/spectre-ssh
98
97
  changelog_uri: https://github.com/ionos-spectre/spectre-ssh/blob/master/CHANGELOG.md
99
- post_install_message:
98
+ post_install_message:
100
99
  rdoc_options: []
101
100
  require_paths:
102
101
  - lib
@@ -104,15 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
103
  requirements:
105
104
  - - ">="
106
105
  - !ruby/object:Gem::Version
107
- version: 2.5.0
106
+ version: 3.0.0
108
107
  required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  requirements:
110
109
  - - ">="
111
110
  - !ruby/object:Gem::Version
112
111
  version: '0'
113
112
  requirements: []
114
- rubygems_version: 3.3.7
115
- signing_key:
113
+ rubygems_version: 3.3.26
114
+ signing_key:
116
115
  specification_version: 4
117
116
  summary: SSH module for spectre
118
117
  test_files: []