spectre-ssh 1.0.1 → 1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/ssh.rb +46 -18
  3. metadata +43 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 774fafd0f95bfcbac2c96ffbb732918f1d7beb56c4045fcd5e0468c429664ff2
4
- data.tar.gz: 280800cbaf572c48ded2db30090484bed91df9605ed3f3d046e366d21ff42552
3
+ metadata.gz: 8548d3d2c8b5cf86005bc9c9884e8ffad6250783c997af68a9c37b5b1577d759
4
+ data.tar.gz: 70d690e4e1c0e16a5fcd8f9b3c05c3b00721933a374e6550410558aa0927742d
5
5
  SHA512:
6
- metadata.gz: 45c553eaeaaf6334e3ce12cae5a0c56fa022564436ea5368d7a94a61d35c4f0d8c09ee9972c5f36706ad85975984ce92ae4c489997790ec9a97911c8b1865241
7
- data.tar.gz: caf6aacbc8313f0a1d9e500ffe7861b39a423b61a873af078aff96262b5a95aea69ffb0b6d300a2b736ca5ae1706739f6771a8489d9b544c36b96adc6c6a8059
6
+ metadata.gz: ef75af4b62cfd54b508b3ab2b0d974a811dc68f7c270ed2bb214720984f8d421bd90727e207f8208c402a1a0f7e83df3b7ac1c1081f7cfc07a993b02b81458a2
7
+ data.tar.gz: 9da77291b02ed303bd09273b5e85b073646fbd4cce4d17019d1230fd2bb32c279f6b76b55d13088e5674bc154ec48e52da33853a11e09b8cec85e854748d8ea6
data/lib/spectre/ssh.rb CHANGED
@@ -7,6 +7,9 @@ module Spectre
7
7
  module SSH
8
8
  @@cfg = {}
9
9
 
10
+ class SSHError < Exception
11
+ end
12
+
10
13
  class SSHConnection < Spectre::DslClass
11
14
  def initialize host, username, opts, logger
12
15
  opts[:non_interactive] = true
@@ -20,6 +23,24 @@ module Spectre
20
23
  @__output = ''
21
24
  end
22
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
+
23
44
  def file_exists path
24
45
  exec "ls #{path}"
25
46
  exit_code == 0
@@ -32,11 +53,19 @@ module Spectre
32
53
 
33
54
  def connect!
34
55
  return unless @__session == nil or @__session.closed?
35
- @__session = Net::SSH.start(@__host, @__username, @__opts)
56
+
57
+ begin
58
+ @__session = Net::SSH.start(@__host, @__username, @__opts)
59
+ rescue SocketError
60
+ raise SSHError.new("Unable to connect to #{@__host} with user #{@__username}")
61
+ rescue Net::SSH::AuthenticationFailed
62
+ raise SSHError.new("Authentication failed for #{@__username}@#{@__host}. Please check password, SSH keys and passphrases.")
63
+ end
36
64
  end
37
65
 
38
66
  def close
39
67
  return unless @__session and not @__session.closed?
68
+
40
69
  @__session.close
41
70
  end
42
71
 
@@ -64,20 +93,20 @@ module Spectre
64
93
  log_str = "#{@__session.options[:user]}@#{@__session.host} -p #{@__session.options[:port]} #{command}"
65
94
 
66
95
  @channel = @__session.open_channel do |channel|
67
- channel.exec(command) do |ch, success|
96
+ channel.exec(command) do |_ch, success|
68
97
  abort "could not execute #{command} on #{@__session.host}" unless success
69
98
 
70
99
  @__output = ''
71
100
 
72
- channel.on_data do |ch, data|
101
+ channel.on_data do |_, data|
73
102
  @__output += data
74
103
  end
75
104
 
76
- channel.on_extended_data do |ch,type,data|
105
+ channel.on_extended_data do |_, _type, data|
77
106
  @__output += data
78
107
  end
79
108
 
80
- channel.on_request('exit-status') do |ch, data|
109
+ channel.on_request('exit-status') do |_, data|
81
110
  @__exit_code = data.read_long
82
111
  end
83
112
 
@@ -85,7 +114,6 @@ module Spectre
85
114
  # exit_code = data.read_long
86
115
  # end
87
116
  end
88
-
89
117
  end
90
118
 
91
119
  @channel.wait
@@ -106,24 +134,24 @@ module Spectre
106
134
 
107
135
 
108
136
  class << self
109
- def ssh name, config = {}, &block
110
- raise "SSH connection '#{name}' not configured" unless @@cfg.key?(name) or config.count > 0
111
-
137
+ def ssh name, options = {}, &block
112
138
  cfg = @@cfg[name] || {}
113
139
 
114
140
  host = cfg['host'] || name
115
- username = config[:username] || cfg['username']
116
- password = config[:password] || cfg['password']
141
+ username = options[:username] || cfg['username']
142
+ password = options[:password] || cfg['password']
117
143
 
118
144
  opts = {}
119
145
  opts[:password] = password
120
- opts[:port] = config[:port] || cfg['port'] || 22
121
- opts[:keys] = [cfg['key']] if cfg.key? 'key'
122
- opts[:passphrase] = cfg['passphrase'] if cfg.key? 'passphrase'
146
+ opts[:port] = options[:port] || cfg['port'] || 22
147
+
148
+ ssh_key = options[:key] || cfg['key']
149
+ opts[:keys] = [ssh_key] unless ssh_key.nil?
150
+ opts[:passphrase] = options[:passphrase] || cfg['passphrase']
123
151
 
124
152
  opts[:auth_methods] = []
125
- opts[:auth_methods].push 'publickey' if opts[:keys]
126
- opts[:auth_methods].push 'password' if opts[:password]
153
+ opts[:auth_methods].push 'publickey' unless opts[:keys].nil? or opts[:keys].empty?
154
+ opts[:auth_methods].push 'password' unless opts[:password].nil?
127
155
 
128
156
  ssh_con = SSHConnection.new(host, username, opts, @@logger)
129
157
 
@@ -136,7 +164,7 @@ module Spectre
136
164
  end
137
165
 
138
166
  Spectre.register do |config|
139
- @@logger = ::Logger.new config['log_file'], progname: 'spectre/ssh'
167
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/ssh')
140
168
 
141
169
  if config.key? 'ssh'
142
170
  config['ssh'].each do |name, cfg|
@@ -147,4 +175,4 @@ module Spectre
147
175
 
148
176
  Spectre.delegate :ssh, to: self
149
177
  end
150
- end
178
+ 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.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl
@@ -16,58 +16,85 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ssh
29
29
  requirement: !ruby/object:Gem::Requirement
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.4
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.4
54
+ version: 1.14.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: ed25519
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bcrypt_pbkdf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
55
83
  description: Adds SSH access functionality to the spectre framework
56
84
  email:
57
- - me@christianneubauer.de
85
+ - christian.neubauer@ionos.com
58
86
  executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - lib/spectre/ssh.rb
63
- homepage: https://github.com/cneubauer/spectre-ssh
91
+ homepage: https://github.com/ionos-spectre/spectre-ssh
64
92
  licenses:
65
93
  - MIT
66
94
  metadata:
67
- allowed_push_host: https://rubygems.org/
68
- homepage_uri: https://github.com/cneubauer/spectre-ssh
69
- source_code_uri: https://github.com/cneubauer/spectre-ssh
70
- changelog_uri: https://github.com/cneubauer/spectre-ssh/blob/master/CHANGELOG.md
95
+ homepage_uri: https://github.com/ionos-spectre/spectre-ssh
96
+ source_code_uri: https://github.com/ionos-spectre/spectre-ssh
97
+ changelog_uri: https://github.com/ionos-spectre/spectre-ssh/blob/master/CHANGELOG.md
71
98
  post_install_message:
72
99
  rdoc_options: []
73
100
  require_paths:
@@ -76,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
103
  requirements:
77
104
  - - ">="
78
105
  - !ruby/object:Gem::Version
79
- version: 2.5.0
106
+ version: 3.0.0
80
107
  required_rubygems_version: !ruby/object:Gem::Requirement
81
108
  requirements:
82
109
  - - ">="
83
110
  - !ruby/object:Gem::Version
84
111
  version: '0'
85
112
  requirements: []
86
- rubygems_version: 3.0.8
113
+ rubygems_version: 3.3.26
87
114
  signing_key:
88
115
  specification_version: 4
89
116
  summary: SSH module for spectre