chloride 0.2.3 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b1d9fd43afd86f217fe0f203debb0324a911c42
4
- data.tar.gz: d5fb4c549711b927d82f6419ab6603ef6285e571
3
+ metadata.gz: e24a2f7403f140127b82edf1f43edd11ba20ab57
4
+ data.tar.gz: 646409f9f55efbcd716d5edc14a7ff75c7240450
5
5
  SHA512:
6
- metadata.gz: c0955bc1e67f7a11640e060e07306f0c04c54c3568e1486d599fa027e30f92ba9fb33cfdeafc7379ea0591ea9bd28d075920617414b39b4d9b84461b80f887ce
7
- data.tar.gz: e092bb897e35bbf3183b81f90fca58cf10c23614b225dad3809a2088d7ed9218c1355f76e040913e7230b7fec7f8a15170a12c3cbf3c00958fb611d2940774bb
6
+ metadata.gz: 28e0249d6903a4b9722f3d29f99e3e46c15efa13ed1adac113749a6de581f9d3ada1d0bfe35c7fdec76bcefcd2d93447b0797c606fde8810b4730f8804033d98
7
+ data.tar.gz: 55f7169cd62cbde0153bb53f9047c7755eba4c6cfaefdba107f3e87fb41c76842952db5288b9287b8ca718f70ea1877945bce2f6551e46ca4695e614ad921a4f
@@ -6,6 +6,9 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
+ AllCops:
10
+ TargetRubyVersion: 2.4
11
+
9
12
  # Offense count: 6
10
13
  # Configuration parameters: AllowSafeAssignment.
11
14
  Lint/AssignmentInCondition:
@@ -169,12 +172,12 @@ Style/Documentation:
169
172
  - 'lib/chloride/step/noop.rb'
170
173
 
171
174
  # Cop supports --auto-correct.
172
- Style/EmptyLines:
175
+ Layout/EmptyLines:
173
176
  AutoCorrect: true
174
177
 
175
178
  # Cop supports --auto-correct.
176
179
  # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
177
- Style/ExtraSpacing:
180
+ Layout/ExtraSpacing:
178
181
  AutoCorrect: true
179
182
 
180
183
  # Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -204,22 +207,22 @@ Style/IfUnlessModifier:
204
207
 
205
208
  # Configuration parameters: EnforcedStyle, SupportedStyles.
206
209
  # SupportedStyles: normal, rails
207
- Style/IndentationConsistency:
210
+ Layout/IndentationConsistency:
208
211
  Enabled: true
209
212
 
210
213
  # Cop supports --auto-correct.
211
214
  # Configuration parameters: Width.
212
- Style/IndentationWidth:
215
+ Layout/IndentationWidth:
213
216
  AutoCorrect: true
214
217
 
215
218
  # Cop supports --auto-correct.
216
- Style/LeadingCommentSpace:
219
+ Layout/LeadingCommentSpace:
217
220
  AutoCorrect: true
218
221
 
219
222
  # Cop supports --auto-correct.
220
223
  # Configuration parameters: EnforcedStyle, SupportedStyles.
221
224
  # SupportedStyles: symmetrical, new_line, same_line
222
- Style/MultilineMethodCallBraceLayout:
225
+ Layout/MultilineMethodCallBraceLayout:
223
226
  AutoCorrect: true
224
227
 
225
228
  # Cop supports --auto-correct.
@@ -270,40 +273,40 @@ Style/RedundantSelf:
270
273
  AutoCorrect: true
271
274
 
272
275
  # Cop supports --auto-correct.
273
- Style/SpaceAfterComma:
276
+ Layout/SpaceAfterComma:
274
277
  AutoCorrect: true
275
278
 
276
279
  # Cop supports --auto-correct.
277
- Style/SpaceAfterNot:
280
+ Layout/SpaceAfterNot:
278
281
  AutoCorrect: true
279
282
 
280
283
  # Cop supports --auto-correct.
281
284
  # Configuration parameters: EnforcedStyle, SupportedStyles.
282
285
  # SupportedStyles: space, no_space
283
- Style/SpaceAroundEqualsInParameterDefault:
286
+ Layout/SpaceAroundEqualsInParameterDefault:
284
287
  AutoCorrect: true
285
288
 
286
289
  # Cop supports --auto-correct.
287
290
  # Configuration parameters: AllowForAlignment.
288
- Style/SpaceAroundOperators:
291
+ Layout/SpaceAroundOperators:
289
292
  AutoCorrect: true
290
293
 
291
294
  # Cop supports --auto-correct.
292
295
  # Configuration parameters: EnforcedStyle, SupportedStyles.
293
296
  # SupportedStyles: space, no_space
294
- Style/SpaceBeforeBlockBraces:
297
+ Layout/SpaceBeforeBlockBraces:
295
298
  Enabled: true
296
299
 
297
300
  # Cop supports --auto-correct.
298
301
  # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
299
302
  # SupportedStyles: space, no_space
300
- Style/SpaceInsideBlockBraces:
303
+ Layout/SpaceInsideBlockBraces:
301
304
  AutoCorrect: true
302
305
 
303
306
  # Cop supports --auto-correct.
304
307
  # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
305
308
  # SupportedStyles: space, no_space, compact
306
- Style/SpaceInsideHashLiteralBraces:
309
+ Layout/SpaceInsideHashLiteralBraces:
307
310
  AutoCorrect: true
308
311
 
309
312
  # Cop supports --auto-correct.
@@ -313,6 +316,9 @@ Style/StringLiterals:
313
316
  Enabled: true
314
317
  AutoCorrect: true
315
318
 
319
+ Style/FrozenStringLiteralComment:
320
+ Enabled: false
321
+
316
322
  # Configuration parameters: EnforcedStyle, SupportedStyles.
317
323
  # SupportedStyles: single_quotes, double_quotes
318
324
  Style/StringLiteralsInInterpolation:
@@ -327,7 +333,9 @@ Style/TernaryParentheses:
327
333
  # Cop supports --auto-correct.
328
334
  # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
329
335
  # SupportedStyles: comma, consistent_comma, no_comma
330
- Style/TrailingCommaInLiteral:
336
+ Style/TrailingCommaInArrayLiteral:
337
+ AutoCorrect: true
338
+ Style/TrailingCommaInHashLiteral:
331
339
  AutoCorrect: true
332
340
 
333
341
  # Cop supports --auto-correct.
@@ -359,3 +367,20 @@ Style/WordArray:
359
367
  # Cop supports --auto-correct.
360
368
  Style/ZeroLengthPredicate:
361
369
  AutoCorrect: true
370
+
371
+ # I'll be a terse as I want to
372
+ Naming/UncommunicativeMethodParamName:
373
+ Enabled: false
374
+
375
+ # Don't like the %i style.
376
+ Style/SymbolArray:
377
+ Enabled: false
378
+
379
+ # if code_is_poetry
380
+ # make_a_block_if_you_want_to
381
+ # end
382
+ Style/IfUnlessModifier:
383
+ Enabled: false
384
+
385
+ Metrics/LineLength:
386
+ Enabled: false
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- - 2.1
3
+ - 2.4
4
+ - 2.5
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Chloride [![Build Status](https://travis-ci.org/puppetlabs/chloride.svg?branch=master)](https://travis-ci.org/puppetlabs/chloride)
1
+ # Chloride
2
+ [![Gem Version](https://badge.fury.io/rb/chloride.svg)](https://badge.fury.io/rb/chloride)
3
+ [![Build Status](https://travis-ci.org/puppetlabs/chloride.svg?branch=master)](https://travis-ci.org/puppetlabs/chloride)
4
+ [![Issue Count](https://codeclimate.com/github/puppetlabs/chloride/badges/issue_count.svg)](https://codeclimate.com/github/puppetlabs/chloride)
2
5
 
3
6
  A simple abstraction layer around NetSSH.
4
7
 
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require 'rubocop/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new(:lint)
7
7
 
8
- task default: [:lint, :spec]
8
+ task default: [:spec, :lint]
@@ -17,7 +17,7 @@ opt_parse = OptionParser.new do |opts|
17
17
  end
18
18
 
19
19
  if ARGV.length < 2
20
- opt_parse.parse!(%w(--help))
20
+ opt_parse.parse!(%w[--help])
21
21
  else
22
22
  hostname = ARGV[0]
23
23
  command = ARGV[1]
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'chloride/version'
5
4
 
@@ -21,13 +20,14 @@ Gem::Specification.new do |spec|
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ['lib']
23
22
 
23
+ spec.required_ruby_version = '~> 2.4'
24
+
24
25
  spec.add_development_dependency 'bundler', '~> 1'
26
+ spec.add_development_dependency 'pry'
25
27
  spec.add_development_dependency 'rake', '~> 11'
26
28
  spec.add_development_dependency 'rspec', '~> 3'
27
- spec.add_development_dependency 'simplecov', '~> 0.12'
28
- spec.add_development_dependency 'pry', '~> 0.10'
29
- spec.add_development_dependency 'pry-coolline', '~> 0.2'
30
- spec.add_development_dependency 'rubocop', '~> 0.44'
31
- spec.add_dependency 'net-ssh', '~> 2'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'simplecov'
32
31
  spec.add_dependency 'net-scp', '~> 1'
32
+ spec.add_dependency 'net-ssh', '~> 4'
33
33
  end
@@ -5,6 +5,7 @@ require 'chloride/action/mkdir'
5
5
  require 'chloride/action/mktmp'
6
6
  require 'chloride/action/resolve_dns'
7
7
  require 'chloride/host'
8
+ require 'chloride/ssh_known_hosts'
8
9
 
9
10
  module Chloride
10
11
  def self.go_execute(hostname, command)
@@ -29,4 +30,31 @@ module Chloride
29
30
  puts "We failed to run '#{command}' with error code #{remote_command.status} on #{hostname}"
30
31
  end
31
32
  end
33
+
34
+ def self.go_action(hostname, action, opts)
35
+ host = Chloride::Host.new(hostname)
36
+ host.ssh_connect
37
+
38
+ action_class = case action
39
+ when 'file_copy'
40
+ opts[:to_host] = host
41
+ Chloride::Action::FileCopy
42
+ else
43
+ raise "Unknown or unsupported action #{action_class}"
44
+ end
45
+
46
+ remote_action = action_class.new(opts)
47
+
48
+ remote_action.go do |event|
49
+ event.data[:messages].each do |data|
50
+ puts "[#{data.severity}:#{data.hostname}]: #{data.message}"
51
+ end
52
+ end
53
+
54
+ if remote_action.success?
55
+ puts "We were successful at running '#{action}' on #{hostname}"
56
+ else
57
+ puts "We failed to run '#{action}' with error code #{remote_action.status} on #{hostname}"
58
+ end
59
+ end
32
60
  end
@@ -127,7 +127,7 @@ class Chloride::Action::DetectPlatform < Chloride::Action
127
127
  if (suse_release[:exit_status]).zero?
128
128
  stdout = suse_release[:stdout]
129
129
 
130
- if /Enterprise Server/ =~ stdout
130
+ if stdout.match?(/Enterprise Server/)
131
131
  distribution = :sles
132
132
  release = /^VERSION = (\d*)/m.match(stdout)[1]
133
133
  end
@@ -141,7 +141,7 @@ class Chloride::Action::DetectPlatform < Chloride::Action
141
141
  if (system_release[:exit_status]).zero?
142
142
  stdout = system_release[:stdout]
143
143
 
144
- if /amazon linux/im =~ stdout
144
+ if stdout.match?(/amazon linux/im)
145
145
  distribution = :amazon
146
146
  # How is this safe to assume?
147
147
  release = '6'
@@ -6,7 +6,7 @@ class Chloride::Executor
6
6
 
7
7
  def publish(event, action_id = nil)
8
8
  event.action_id = action_id if action_id
9
- @stream_block.call(event) if @stream_block
9
+ @stream_block&.call(event)
10
10
  end
11
11
 
12
12
  def execute(steps)
@@ -5,9 +5,10 @@ require 'strscan'
5
5
  require 'open3'
6
6
  require 'timeout'
7
7
  require 'json'
8
+ require 'chloride/ssh_known_hosts'
8
9
 
9
10
  class Chloride::Host
10
- attr_reader :data, :remote_conn, :hostname, :username, :ssh_key_file, :ssh_key_passphrase, :localhost
11
+ attr_reader :remote_conn, :hostname, :username, :ssh_key_file, :ssh_key_passphrase, :localhost
11
12
  attr_accessor :data
12
13
 
13
14
  def initialize(hostname, config = {})
@@ -26,6 +27,7 @@ class Chloride::Host
26
27
  @data = {}
27
28
  @timeout = 60
28
29
  @ssh_status = nil
30
+ @known_hosts_file = config[:known_hosts] || 'known_hosts'
29
31
  end
30
32
 
31
33
  # Initializes SSH connection/session to host. Must be called before {#ssh} or {#scp}.
@@ -44,7 +46,8 @@ class Chloride::Host
44
46
  passphrase: @ssh_key_passphrase,
45
47
  password: @sudo_password,
46
48
  logger: logger,
47
- verbose: :warn
49
+ verbose: :warn,
50
+ known_hosts: Chloride::SSHKnownHosts.new(@known_hosts_file)
48
51
  }.reject { |_, v| v.nil? }
49
52
 
50
53
  ssh_opts[:keys] = [@ssh_key_file] if @ssh_key_file
@@ -55,7 +58,7 @@ class Chloride::Host
55
58
  @ssh_status = :connected
56
59
  }
57
60
  end
58
- rescue Net::SSH::AuthenticationFailed => err
61
+ rescue Net::SSH::AuthenticationFailed => _
59
62
  @ssh_status = :error
60
63
  log.rewind
61
64
  raise("Authentication failed while attempting to SSH to #{@username}@#{@hostname}: \n#{log.read}")
@@ -149,6 +152,7 @@ class Chloride::Host
149
152
  buffers = { stdout: StringScanner.new(''), stderr: StringScanner.new('') }
150
153
  buffer_proc = proc do |info, stream, data|
151
154
  raise NotImplementedError, "Unknown stream #{stream}" unless [:stdout, :stderr].include? stream
155
+
152
156
  buffers[stream] << data
153
157
  while l = buffers[stream].scan_until(/\n/)
154
158
  send.call(info, stream, l)
@@ -268,12 +272,12 @@ class Chloride::Host
268
272
  ch.wait
269
273
 
270
274
  true
271
- elsif data =~ /^#{@username} is not in the sudoers file./
275
+ elsif data.match?(/^#{@username} is not in the sudoers file./)
272
276
  # Sudo failed, wrong user. Bail out.
273
277
  stream_block.call(info, :stderr, "Cannot proceed: User #{@username} does not have sudo permission.")
274
278
  raise Chloride::RemoteError, "User #{@username} does not have sudo permission"
275
279
  # This could be a terrible bug.
276
- elsif data =~ /Sorry, try again./
280
+ elsif data.match?(/Sorry, try again./)
277
281
  # Sudo failed, wrong password. Bail out.
278
282
  stream_block.call(info, :stderr, 'Cannot proceed: Sudo password not recognized.')
279
283
  raise Chloride::RemoteError, 'Sudo password not recognized'
@@ -0,0 +1,20 @@
1
+ # Dummy KnownHosts implementation
2
+ #
3
+ # This exists to stop Net::SSH from writing to the user's known_hosts file
4
+ # Instead, new host signatures are saved to a library-specific file.
5
+ class Chloride::SSHKnownHosts < Net::SSH::KnownHosts
6
+ # Method signatures inherited from Net::SSH::KnownHosts
7
+ # def initialize(source)
8
+ # def hostfiles(options, which=:all)
9
+ # def search_in(files, host)
10
+ # def keys_for(host)
11
+ # def known_host_hash?(hostlist, entries, scanner)
12
+ # def add(host, key)
13
+ # def add(host, key, options={})
14
+
15
+ # Must be implemented
16
+ def search_for(host, options = {})
17
+ opts = {}.merge(options).merge(user_known_hosts_file: source)
18
+ Net::SSH::KnownHosts.search_for(host, opts)
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Chloride
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chloride
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon High
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-02-13 00:00:00.000000000 Z
13
+ date: 2018-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -27,117 +27,103 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '1'
29
29
  - !ruby/object:Gem::Dependency
30
- name: rake
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '11'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '11'
43
- - !ruby/object:Gem::Dependency
44
- name: rspec
30
+ name: pry
45
31
  requirement: !ruby/object:Gem::Requirement
46
32
  requirements:
47
- - - "~>"
33
+ - - ">="
48
34
  - !ruby/object:Gem::Version
49
- version: '3'
35
+ version: '0'
50
36
  type: :development
51
37
  prerelease: false
52
38
  version_requirements: !ruby/object:Gem::Requirement
53
39
  requirements:
54
- - - "~>"
40
+ - - ">="
55
41
  - !ruby/object:Gem::Version
56
- version: '3'
42
+ version: '0'
57
43
  - !ruby/object:Gem::Dependency
58
- name: simplecov
44
+ name: rake
59
45
  requirement: !ruby/object:Gem::Requirement
60
46
  requirements:
61
47
  - - "~>"
62
48
  - !ruby/object:Gem::Version
63
- version: '0.12'
49
+ version: '11'
64
50
  type: :development
65
51
  prerelease: false
66
52
  version_requirements: !ruby/object:Gem::Requirement
67
53
  requirements:
68
54
  - - "~>"
69
55
  - !ruby/object:Gem::Version
70
- version: '0.12'
56
+ version: '11'
71
57
  - !ruby/object:Gem::Dependency
72
- name: pry
58
+ name: rspec
73
59
  requirement: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - "~>"
76
62
  - !ruby/object:Gem::Version
77
- version: '0.10'
63
+ version: '3'
78
64
  type: :development
79
65
  prerelease: false
80
66
  version_requirements: !ruby/object:Gem::Requirement
81
67
  requirements:
82
68
  - - "~>"
83
69
  - !ruby/object:Gem::Version
84
- version: '0.10'
70
+ version: '3'
85
71
  - !ruby/object:Gem::Dependency
86
- name: pry-coolline
72
+ name: rubocop
87
73
  requirement: !ruby/object:Gem::Requirement
88
74
  requirements:
89
- - - "~>"
75
+ - - ">="
90
76
  - !ruby/object:Gem::Version
91
- version: '0.2'
77
+ version: '0'
92
78
  type: :development
93
79
  prerelease: false
94
80
  version_requirements: !ruby/object:Gem::Requirement
95
81
  requirements:
96
- - - "~>"
82
+ - - ">="
97
83
  - !ruby/object:Gem::Version
98
- version: '0.2'
84
+ version: '0'
99
85
  - !ruby/object:Gem::Dependency
100
- name: rubocop
86
+ name: simplecov
101
87
  requirement: !ruby/object:Gem::Requirement
102
88
  requirements:
103
- - - "~>"
89
+ - - ">="
104
90
  - !ruby/object:Gem::Version
105
- version: '0.44'
91
+ version: '0'
106
92
  type: :development
107
93
  prerelease: false
108
94
  version_requirements: !ruby/object:Gem::Requirement
109
95
  requirements:
110
- - - "~>"
96
+ - - ">="
111
97
  - !ruby/object:Gem::Version
112
- version: '0.44'
98
+ version: '0'
113
99
  - !ruby/object:Gem::Dependency
114
- name: net-ssh
100
+ name: net-scp
115
101
  requirement: !ruby/object:Gem::Requirement
116
102
  requirements:
117
103
  - - "~>"
118
104
  - !ruby/object:Gem::Version
119
- version: '2'
105
+ version: '1'
120
106
  type: :runtime
121
107
  prerelease: false
122
108
  version_requirements: !ruby/object:Gem::Requirement
123
109
  requirements:
124
110
  - - "~>"
125
111
  - !ruby/object:Gem::Version
126
- version: '2'
112
+ version: '1'
127
113
  - !ruby/object:Gem::Dependency
128
- name: net-scp
114
+ name: net-ssh
129
115
  requirement: !ruby/object:Gem::Requirement
130
116
  requirements:
131
117
  - - "~>"
132
118
  - !ruby/object:Gem::Version
133
- version: '1'
119
+ version: '4'
134
120
  type: :runtime
135
121
  prerelease: false
136
122
  version_requirements: !ruby/object:Gem::Requirement
137
123
  requirements:
138
124
  - - "~>"
139
125
  - !ruby/object:Gem::Version
140
- version: '1'
126
+ version: '4'
141
127
  description:
142
128
  email:
143
129
  - brandon.high@puppet.com
@@ -173,6 +159,7 @@ files:
173
159
  - lib/chloride/event/message.rb
174
160
  - lib/chloride/executor.rb
175
161
  - lib/chloride/host.rb
162
+ - lib/chloride/ssh_known_hosts.rb
176
163
  - lib/chloride/step.rb
177
164
  - lib/chloride/step/noop.rb
178
165
  - lib/chloride/version.rb
@@ -186,9 +173,9 @@ require_paths:
186
173
  - lib
187
174
  required_ruby_version: !ruby/object:Gem::Requirement
188
175
  requirements:
189
- - - ">="
176
+ - - "~>"
190
177
  - !ruby/object:Gem::Version
191
- version: '0'
178
+ version: '2.4'
192
179
  required_rubygems_version: !ruby/object:Gem::Requirement
193
180
  requirements:
194
181
  - - ">="
@@ -196,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
183
  version: '0'
197
184
  requirements: []
198
185
  rubyforge_project:
199
- rubygems_version: 2.2.5
186
+ rubygems_version: 2.6.14.1
200
187
  signing_key:
201
188
  specification_version: 4
202
189
  summary: A simple streaming NetSSH implementation