opswalrus 1.0.46 → 1.0.48

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: d9e4b15ff511cbac36450224deb5d3da970aa979be30d468ce9ac07c8b827907
4
- data.tar.gz: 531443cdca36130479513f755ef609b017cc109f339d24379f82d7b243da4891
3
+ metadata.gz: 2ccef020c9a8dbe02e313e2cea8d632bde41b4adf7d4632af26d6b86d5e52606
4
+ data.tar.gz: 5f2a6342ca5631a4e4284ebfb9a6546106dff4fbce2aa6bafad42d7e897b98e5
5
5
  SHA512:
6
- metadata.gz: c728e62baf815b1599413d2b80c6d045b4c5be510c374be1b3a6b7465c7316bc2952ab4bab91031df23bc7b56289cb8c36b320e5cf84a0a523a12a410ff538b8
7
- data.tar.gz: 8d804dd1f1b90347e7eddeb43bde790841130d1edd25b1ed632223e7a0ace968b8c80e834829e277d148f245d5bf8b964d92120849f01f8c1f0f8976bb3897c8
6
+ metadata.gz: 1100b1342196951cdaac37d5dac00a40400d5556c6d4a4fc0a9293fac65a5862639d176e18e1e9cea1230957a110a50853a561bd48f965b42aebf7734b3d0590
7
+ data.tar.gz: 9e467f0d02e86bf19fd4385ab62cb7ce739dca3096a159e648909e1d95fdd53c5519cfb98eac37748f5e4cbcb371d59f0247ea2bd51ecf92453d85852564fa3d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.46)
4
+ opswalrus (1.0.48)
5
5
  bcrypt_pbkdf (~> 1.1)
6
6
  binding_of_caller (~> 1.0)
7
7
  citrus (~> 3.0)
data/build.ops CHANGED
@@ -30,7 +30,9 @@ end
30
30
  TEMPLATE
31
31
 
32
32
  puts "Write version.rb for version #{version}"
33
- core.template.write(path: "./lib/opswalrus/version.rb", template: template, variables: {version: version})
33
+ core.template.write template: template,
34
+ variables: {version: version},
35
+ to: "./lib/opswalrus/version.rb"
34
36
 
35
37
  sh("Build gem") { 'gem build opswalrus.gemspec' }
36
38
 
data/lib/opswalrus/app.rb CHANGED
@@ -219,9 +219,7 @@ module OpsWalrus
219
219
  set_pwd(__FILE__.to_pathname.dirname)
220
220
  bootstrap_ops_file = OpsFile.new(self, __FILE__.to_pathname.dirname.join("bootstrap.ops"))
221
221
  op = OperationRunner.new(self, bootstrap_ops_file)
222
- result = op.run([], params_json_hash: @params)
223
- info "Bootstrap results:"
224
- info result
222
+ op.run([], params_json_hash: @params)
225
223
  end
226
224
 
227
225
  # args is of the form ["github.com/davidkellis/my-package/sub-package1", "operation1", "arg1:val1", "arg2:val2", "arg3:val3"]
@@ -251,6 +249,9 @@ module OpsWalrus
251
249
  puts JSON.pretty_generate(result.value)
252
250
 
253
251
  exit_status
252
+ rescue Error => e
253
+ puts "Error: #{e.message}"
254
+ 1
254
255
  ensure
255
256
  FileUtils.remove_entry(tmp_bundle_root_dir) if tmp_bundle_root_dir
256
257
  end
@@ -264,6 +264,14 @@ module OpsWalrus
264
264
  puts Style.green(msg.mustache(2)) # we use two here, because one stack frame accounts for the call from the ops script into HostProxy#desc
265
265
  end
266
266
 
267
+ def warn(msg)
268
+ puts Style.yellow(msg.mustache(2)) # we use two here, because one stack frame accounts for the call from the ops script into HostProxy#desc
269
+ end
270
+
271
+ def debug(msg)
272
+ puts msg.mustache(2) if App.instance.debug? || App.instance.trace? # we use two here, because one stack frame accounts for the call from the ops script into HostProxy#desc
273
+ end
274
+
267
275
  def env(*args, **kwargs)
268
276
  @ops_file_script.env(*args, **kwargs)
269
277
  end
@@ -419,7 +427,7 @@ module OpsWalrus
419
427
 
420
428
  def clear_ssh_session
421
429
  @runtime_env = nil
422
- ops_file_script = nil
430
+ @ops_file_script = nil
423
431
  @sshkit_backend = nil
424
432
  @tmp_bundle_root_dir = nil
425
433
  @tmp_ssh_key_files.each {|tmpfile| tmpfile.close() rescue nil; File.unlink(tmpfile) rescue nil }
@@ -99,14 +99,14 @@ module OpsWalrus
99
99
  App.instance.error "[!] Command failed: #{e.message}"
100
100
  rescue Error => e
101
101
  App.instance.error "Error: Ops script crashed."
102
- App.instance.error e
103
- # App.instance.error e.backtrace.take(5).join("\n")
102
+ App.instance.error e.message
103
+ App.instance.error e.backtrace.take(10).join("\n")
104
104
  Invocation::Error.new(e)
105
105
  rescue => e
106
106
  App.instance.error "Unhandled Error: Ops script crashed."
107
107
  App.instance.error e.class
108
- App.instance.error e
109
- # App.instance.error e.backtrace.take(10).join("\n")
108
+ App.instance.error e.message
109
+ App.instance.error e.backtrace.take(10).join("\n")
110
110
  Invocation::Error.new(e)
111
111
  end
112
112
 
@@ -139,11 +139,12 @@ module OpsWalrus
139
139
  def _invoke(runtime_env, hashlike_params)
140
140
  @runtime_env = runtime_env
141
141
  @params = InvocationParams.new(hashlike_params)
142
+ @runtime_ops_file_path = __FILE__
142
143
  #{ruby_script}
143
144
  end
144
145
  INVOKE_METHOD
145
146
 
146
- invoke_method_line_count_prior_to_ruby_script_from_ops_file = 3
147
+ invoke_method_line_count_prior_to_ruby_script_from_ops_file = 4
147
148
  klass.module_eval(invoke_method_definition, ops_file.ops_file_path.to_s, ops_file.script_line_offset - invoke_method_line_count_prior_to_ruby_script_from_ops_file)
148
149
 
149
150
  klass
@@ -157,8 +158,9 @@ module OpsWalrus
157
158
  def initialize(ops_file, ruby_script)
158
159
  @ops_file = ops_file
159
160
  @script = ruby_script
160
- @runtime_env = nil # this is set at the very first line of #_invoke
161
- @params = nil # this is set at the very first line of #_invoke
161
+ @runtime_env = nil # this is set at the very first line of #_invoke
162
+ @params = nil # this is set at the very first line of #_invoke
163
+ @runtime_ops_file_path = nil # this is set at the very first line of #_invoke
162
164
  end
163
165
 
164
166
  def backend
@@ -183,6 +185,10 @@ module OpsWalrus
183
185
  end
184
186
  end
185
187
 
188
+ def inspect
189
+ "OpsFileScript[#{ops_file.ops_file_path}]"
190
+ end
191
+
186
192
  def to_s
187
193
  @script
188
194
  end
@@ -153,6 +153,10 @@ module OpsWalrus
153
153
  end
154
154
  end
155
155
 
156
+ def current_dir
157
+ File.dirname(File.realpath(@runtime_ops_file_path)).to_pathname
158
+ end
159
+
156
160
  def inventory(*args, **kwargs)
157
161
  tags = args.map(&:to_s)
158
162
 
@@ -194,6 +198,14 @@ module OpsWalrus
194
198
  puts Style.green(msg.mustache(1))
195
199
  end
196
200
 
201
+ def warn(msg)
202
+ puts Style.yellow(msg.mustache(1))
203
+ end
204
+
205
+ def debug(msg)
206
+ puts msg.mustache(1) if App.instance.debug? || App.instance.trace?
207
+ end
208
+
197
209
  def env(*keys)
198
210
  keys = keys.map(&:to_s)
199
211
  if keys.empty?
@@ -245,10 +257,26 @@ module OpsWalrus
245
257
  end
246
258
  #cmd = Shellwords.escape(cmd)
247
259
 
260
+ report_on(@runtime_env.local_hostname, description, cmd, log_level: log_level) do
261
+ if App.instance.dry_run?
262
+ ["", "", 0]
263
+ else
264
+ sshkit_cmd = @runtime_env.handle_input(input, inherit_existing_mappings: true) do |interaction_handler|
265
+ # puts "self=#{self.class.superclass}"
266
+ # self is an instance of one of the dynamically defined subclasses of OpsFileScript
267
+ App.instance.debug("OpsFileScriptDSL#shell! cmd=#{cmd} with input mappings #{interaction_handler.input_mappings.inspect} given input: #{input.inspect})")
268
+ backend.execute_cmd(cmd, interaction_handler: interaction_handler)
269
+ end
270
+ [sshkit_cmd.full_stdout, sshkit_cmd.full_stderr, sshkit_cmd.exit_status]
271
+ end
272
+ end
273
+ end
274
+
275
+ def report_on(hostname, description = nil, cmd, log_level: nil)
248
276
  cmd_id = Random.uuid.split('-').first
249
277
 
250
278
  output_block = StringIO.open do |io|
251
- io.print Style.blue(@runtime_env.local_hostname)
279
+ io.print Style.blue(hostname)
252
280
  io.print " | #{Style.magenta(description)}" if description
253
281
  io.puts
254
282
  io.print Style.yellow(cmd_id)
@@ -258,20 +286,8 @@ module OpsWalrus
258
286
  end
259
287
  puts output_block
260
288
 
261
- return unless cmd && !cmd.strip.empty?
262
-
263
289
  t1 = Time.now
264
- out, err, exit_status = if App.instance.dry_run?
265
- ["", "", 0]
266
- else
267
- sshkit_cmd = @runtime_env.handle_input(input, inherit_existing_mappings: true) do |interaction_handler|
268
- # self is a Module instance that is serving as the evaluation context in an instance of a subclass of an Invocation; see Invocation#evaluate
269
- # backend.execute_cmd(cmd, interaction_handler: interaction_handler, verbosity: SSHKit.config.output_verbosity)
270
- App.instance.debug("OpsFileScriptDSL#shell! cmd=#{cmd} with input mappings #{interaction_handler.input_mappings.inspect} given input: #{input.inspect})")
271
- backend.execute_cmd(cmd, interaction_handler: interaction_handler)
272
- end
273
- [sshkit_cmd.full_stdout, sshkit_cmd.full_stderr, sshkit_cmd.exit_status]
274
- end
290
+ out, err, exit_status = yield
275
291
  t2 = Time.now
276
292
  seconds = t2 - t1
277
293
 
@@ -20,3 +20,72 @@ class Pathname
20
20
  self
21
21
  end
22
22
  end
23
+
24
+
25
+ class String
26
+ def boolean!(default: false)
27
+ boolean_str = strip.downcase
28
+ case boolean_str
29
+ when "true"
30
+ true
31
+ when "false"
32
+ false
33
+ else
34
+ default
35
+ end
36
+ end
37
+
38
+ def string!(default: "")
39
+ self
40
+ end
41
+ end
42
+
43
+ class Integer
44
+ def boolean!(default: false)
45
+ true
46
+ end
47
+
48
+ def string!(default: "")
49
+ to_s
50
+ end
51
+ end
52
+
53
+ class Float
54
+ def boolean!(default: false)
55
+ true
56
+ end
57
+
58
+ def string!(default: "")
59
+ to_s
60
+ end
61
+ end
62
+
63
+ class NilClass
64
+ def boolean!(default: false)
65
+ default
66
+ end
67
+
68
+ def string!(default: "")
69
+ default
70
+ end
71
+ end
72
+
73
+ class TrueClass
74
+ def boolean!(default: false)
75
+ self
76
+ end
77
+
78
+ def string!(default: "")
79
+ to_s
80
+ end
81
+ end
82
+
83
+ class FalseClass
84
+ def boolean!(default: false)
85
+ self
86
+ end
87
+
88
+ def string!(default: "")
89
+ to_s
90
+ end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.46"
2
+ VERSION = "1.0.48"
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.46
4
+ version: 1.0.48
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-09-13 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller