opswalrus 1.0.94 → 1.0.96

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1feb628ace7896079569c7182d0d47da191a270f36940ee650066e5e9e5a914a
4
- data.tar.gz: c70d205d174e4bfca3ede989cc53952bddd876244ceb3795ea6274a0bdb7a240
3
+ metadata.gz: 8fb52bd8ac55bffca7f34fc6213c004bc8ccc2e01d0e0682682ce077fe273bcb
4
+ data.tar.gz: 4613f02bf1f7479eff1ab78ed2c407507f20bb546a8bd005dd469430e38b15ba
5
5
  SHA512:
6
- metadata.gz: fa9760a94e936e1498bd9cdd763f20fb31f6c15f14407b8e924de3e1a2502b64b26ea0defae96c4729c11d024dff31a0fc4712d7899d1586ac7f82d5fdd0558c
7
- data.tar.gz: d55ad916d7f17ae0d82ad0ec531129c1b6a198ff33b4ad257c08975e42c9096367d52b9bad20efcdd8510bc7f6539e68387f89759dd3201f8546fb919b874722
6
+ metadata.gz: 901644932c68e186a15f94b77e179cf8412f9a791e7981fa79b0a4a035696c80e298aabf2a6ceb362dccec370ee2f63a6e174ffe31bb67c49966b7d296a32baf
7
+ data.tar.gz: 3291a2be3c530e81bd6a0ad6706c4281de16df914d0d67aa8adc57b842e74c94305ae60c17c5556b06fe70ecc02ea19467cea323542fac9336ac43a813763abc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.94)
4
+ opswalrus (1.0.96)
5
5
  activesupport (~> 7.0)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
data/lib/opswalrus/app.rb CHANGED
@@ -25,6 +25,7 @@ require_relative "version"
25
25
 
26
26
  module OpsWalrus
27
27
  Style = Pastel.new(enabled: $stdout.tty?)
28
+ DefaultLookbackWindowCharCount = 2000
28
29
 
29
30
  class App
30
31
  def self.instance(*args)
@@ -3,6 +3,10 @@ module OpsWalrus
3
3
  end
4
4
 
5
5
  class RemoteInvocationError < Error
6
+ def initialize(msg, deserialized_invocation_error_hash)
7
+ super(msg)
8
+ @hash = deserialized_invocation_error_hash
9
+ end
6
10
  end
7
11
 
8
12
  class SymbolResolutionError < Error
@@ -9,7 +9,7 @@ module OpsWalrus
9
9
 
10
10
  attr_accessor :input_mappings # Hash[ String | Regex => (String | Proc) ]
11
11
 
12
- def initialize(mappings, lookback_window_chars = 2000)
12
+ def initialize(mappings, lookback_window_chars = DefaultLookbackWindowCharCount)
13
13
  @input_mappings = mappings
14
14
  @online_matcher = Kleene::NaiveOnlineRegex.new(mappings.keys, lookback_window_chars)
15
15
  end
@@ -42,7 +42,7 @@ module OpsWalrus
42
42
  # when the given block returns, then the temporary mapping is removed from the interaction handler
43
43
  #
44
44
  # mapping : Hash[ String | Regex => (String | Proc) ] | Nil
45
- def with_mapping(mapping = nil, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true, lookback_window_chars: 200)
45
+ def with_mapping(mapping = nil, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true, lookback_window_chars: DefaultLookbackWindowCharCount)
46
46
  new_mapping = inherit_existing_mappings ? @input_mappings.clone : {}
47
47
 
48
48
  if mapping
@@ -216,7 +216,16 @@ module OpsWalrus
216
216
  case retval
217
217
  when Hash
218
218
  if retval["type"] == 'Invocation::Error'
219
- raise RemoteInvocationError.new("Remote Invocation Error:\n #{retval["error_type"]}: #{retval["error"]}#{retval["backtrace"] && "\n Backtrace: #{retval['backtrace']}"}")
219
+ # this structure comes from OpsWalrus::Invocation::Error being serialized in App#print_script_result being called from App#run
220
+ # {
221
+ # type: "Invocation::Error",
222
+ # error_variant: self.class.name,
223
+ # error_class: value.class.name,
224
+ # error: value,
225
+ # backtrace: value.is_a?(Exception) ? value.backtrace.take(10).join("\n") : nil,
226
+ # }
227
+ # raise RemoteInvocationError.new("Remote Invocation Error:\n #{retval["error_class"]}: #{retval["error"]}#{retval["backtrace"] && "\n Backtrace: #{retval['backtrace']}"}")
228
+ raise RemoteInvocationError.new("Remote Invocation Error:\n #{retval["error_class"]}: #{retval["error"]}#{retval["backtrace"] && "\n Backtrace: #{retval['backtrace']}"}", retval)
220
229
  else
221
230
  retval.with_indifferent_access.easynav
222
231
  end
@@ -87,20 +87,20 @@ module OpsWalrus
87
87
  end
88
88
  rescue SSHKit::Command::Failed => e
89
89
  App.instance.error "Runtime error, command failed: #{e.message}"
90
- Invocation::Error.new(e)
90
+ Invocation::SshError.new(e)
91
91
  rescue Error => e
92
92
  # puts "OperationRunner#run - #{Time.now.strftime('%s%L')}"
93
93
  App.instance.error "Runtime error: Ops script crashed."
94
94
  App.instance.error e.message
95
95
  App.instance.error e.backtrace.take(10).join("\n")
96
- Invocation::Error.new(e)
96
+ Invocation::RuntimeError.new(e)
97
97
  rescue => e
98
98
  # puts "OperationRunner#run - #{Time.now.strftime('%s%L')}"
99
99
  App.instance.error "Unhandled runtime error: Ops script crashed."
100
100
  App.instance.error e.class
101
101
  App.instance.error e.message
102
102
  App.instance.error e.backtrace.take(10).join("\n")
103
- Invocation::Error.new(e)
103
+ Invocation::UnhandledError.new(e)
104
104
  end
105
105
 
106
106
  result
@@ -43,7 +43,8 @@ module OpsWalrus
43
43
  def serialize_error
44
44
  {
45
45
  type: "Invocation::Error",
46
- error_type: value.class.name,
46
+ error_variant: self.class.name,
47
+ error_class: value.class.name,
47
48
  error: value,
48
49
  backtrace: value.is_a?(Exception) ? value.backtrace.take(10).join("\n") : nil,
49
50
  }
@@ -52,6 +53,14 @@ module OpsWalrus
52
53
  true
53
54
  end
54
55
  end
56
+ class EarlyExitError < Error
57
+ end
58
+ class SshError < Error
59
+ end
60
+ class RuntimeError < Error
61
+ end
62
+ class UnhandledError < Error
63
+ end
55
64
  end
56
65
 
57
66
 
@@ -178,6 +187,8 @@ module OpsWalrus
178
187
  App.instance.error "[!] The host '#{host}' doesn't accept password authentication method."
179
188
  rescue Errno::EHOSTUNREACH => e
180
189
  App.instance.error "[!] The host '#{host}' is unreachable"
190
+ rescue RemoteInvocationError => e
191
+ results[host] = e
181
192
  # rescue => e
182
193
  # App.instance.error "[!] Command failed:"
183
194
  # App.instance.error e.class
@@ -211,7 +222,7 @@ module OpsWalrus
211
222
  result = if exit_status == 0
212
223
  Invocation::Success.new(nil)
213
224
  else
214
- Invocation::Error.new(nil, exit_status)
225
+ Invocation::EarlyExitError.new(message, exit_status)
215
226
  end
216
227
  throw :exit_now, result
217
228
  end
@@ -303,7 +314,7 @@ module OpsWalrus
303
314
  if App.instance.dry_run?
304
315
  ["", "", 0]
305
316
  else
306
- sshkit_cmd = @runtime_env.handle_input(input, inherit_existing_mappings: true, lookback_window_chars: 200) do |interaction_handler|
317
+ sshkit_cmd = @runtime_env.handle_input(input, inherit_existing_mappings: true, lookback_window_chars: DefaultLookbackWindowCharCount) do |interaction_handler|
307
318
  # puts "self=#{self.class.superclass}"
308
319
  # self is an instance of one of the dynamically defined subclasses of OpsFileScript
309
320
  App.instance.debug("OpsFileScriptDSL#shell! cmd=#{cmd} with input mappings #{interaction_handler.input_mappings.inspect} given input: #{input.inspect})")
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext/hash'
3
3
  require 'active_support/core_ext/hash/indifferent_access'
4
+ require 'active_support/core_ext/string'
4
5
  require 'json'
5
6
  require 'pathname'
6
7
 
@@ -267,7 +267,7 @@ module OpsWalrus
267
267
 
268
268
  # input_mapping : Hash[ String | Regex => String ]
269
269
  # sudo_password : String
270
- def handle_input(input_mapping, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true, lookback_window_chars: 200, &block)
270
+ def handle_input(input_mapping, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true, lookback_window_chars: DefaultLookbackWindowCharCount, &block)
271
271
  @interaction_handler.with_mapping(
272
272
  input_mapping,
273
273
  sudo_password: sudo_password,
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.94"
2
+ VERSION = "1.0.96"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opswalrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.94
4
+ version: 1.0.96
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ellis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport