opswalrus 1.0.63 → 1.0.65

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: d6e2b6b9ba0610010ba57293457a77331d9c9a93f7b692d47876df0646c5d68f
4
- data.tar.gz: 10bcd65544195a67259995a95485bf55cc851710665810365d823bfa6ea473c5
3
+ metadata.gz: 63fc3b8a4e8f06f774016d99a2bce30efd96ea1b855eb3a0e9e4161497d7a04a
4
+ data.tar.gz: 5da3169682554eb3d37534d1c522e1479c9e76371fb61670a96c540786df334b
5
5
  SHA512:
6
- metadata.gz: 9e8856211f18735ad966a78d6078a361071a5e352e4184ffba04d9cfc05944040f2a2a059760d013c285dccc37ef9735fe6951cf6d175795076c1a60f6205da1
7
- data.tar.gz: d011ec4eb7311e1a76c625e3156c36652cf23abfee071d5fb1b3dffffde7e8c92ec0d1442e229d804375390c99eaafe442e12f170b69161d75bddb0b272468a5
6
+ metadata.gz: ba8d018fe2ba343298a1a22b3df163a014a784381b5a6dda7ac7e5c21ec332a7941aac300429456447f6f97a8238fa0a82c439fe85fbcad63b332b57bccaf419
7
+ data.tar.gz: 80709f6efa368371241a19e33c53623b20db978da43a832e3da09477aff5f97b34953549a8d76a7ce9b945e12ed5a520057182218a0d0c91732844f17fe77934
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.63)
4
+ opswalrus (1.0.65)
5
5
  activesupport (~> 7.0)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
data/build.ops CHANGED
@@ -8,7 +8,7 @@ imports:
8
8
 
9
9
  # when you run this script, it should do something like:
10
10
  # ~/sync/projects/ops/opswalrus on  main via 💎 v3.2.2
11
- # ❯ ../ops.sh run build.ops version:1.0.7
11
+ # ❯ ops run build.ops version:1.0.7
12
12
  # Write version.rb for version 1.0.7
13
13
  # [localhost] Build gem: gem build opswalrus.gemspec
14
14
  # [localhost] Check whether Bitwarden is locked or not: bw status
@@ -38,8 +38,10 @@ sh("Build gem") { 'gem build opswalrus.gemspec' }
38
38
 
39
39
  sh("Commit Gemfile.lock and version.rb and git push changes") { 'git commit -am "gem {{ version }}" && git push' }
40
40
 
41
- bw_status_output = sh("Check whether Bitwarden is locked or not") { 'bw status' }
42
- # the status command currently exhibits an error in which it emits 'mac failed.' some number of times, so we need to filter that out
41
+ # bw_status_output = sh("Check whether Bitwarden is locked or not") { 'bw status' }
42
+ is_unlocked = sh? "Check whether Bitwarden is locked or not",
43
+ 'rbw unlocked'
44
+ # the `bw status`` command currently exhibits an error in which it emits 'mac failed.' some number of times, so we need to filter that out
43
45
  # see:
44
46
  # - https://community.bitwarden.com/t/what-does-mac-failed-mean-exactly/29208
45
47
  # - https://github.com/bitwarden/cli/issues/88
@@ -47,14 +49,17 @@ bw_status_output = sh("Check whether Bitwarden is locked or not") { 'bw status'
47
49
  # ❯ bw status
48
50
  # mac failed.
49
51
  # {"serverUrl":"...","lastSync":"2023-08-17T19:14:09.384Z","userEmail":"...","userId":"...","status":"locked"}
50
- bw_status_output = bw_status_output.gsub('mac failed.', '').strip
51
- bw_status_json = bw_status_output.parse_json
52
+ # bw_status_output = bw_status_output.gsub('mac failed.', '').strip
53
+ # bw_status_json = bw_status_output.parse_json
52
54
 
53
- if bw_status_json['status'] != 'unlocked'
54
- exit 1, "Bitwarden is not unlocked. Please unlock bitwarden with: bw unlock"
55
- end
55
+ # if bw_status_json['status'] != 'unlocked'
56
+ # exit 1, "Bitwarden is not unlocked. Please unlock bitwarden with: bw unlock"
57
+ # end
58
+ exit 1, "Bitwarden is not unlocked. Please unlock bitwarden with: bw unlock" unless is_unlocked
56
59
 
57
- totp = sh("Get Rubygems OTP") { 'bw get totp Rubygems' }
60
+ # totp = sh("Get Rubygems OTP") { 'bw get totp Rubygems' }
61
+ totp = sh "Get Rubygems OTP",
62
+ 'rbw get -f totp Rubygems'
58
63
  sh("Push gem", input: {/You have enabled multi-factor authentication. Please enter OTP code./ => "#{totp}\n"}) { 'gem push opswalrus-{{ version }}.gem' }
59
64
  sh("Build docker image") { 'docker build -t ghcr.io/opswalrus/ops:latest -t ghcr.io/opswalrus/ops:{{ version }} -t opswalrus/ops:latest -t opswalrus/ops:{{ version }} .' }
60
65
  sh("Push docker image to ghcr.io/opswalrus/ops") { 'docker push ghcr.io/opswalrus/ops:latest' }
data/lib/opswalrus/app.rb CHANGED
@@ -255,7 +255,7 @@ module OpsWalrus
255
255
 
256
256
  ops_file = load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir)
257
257
 
258
- bundler.update if update_bundle
258
+ bundler.update(true) if update_bundle
259
259
 
260
260
  debug "Running: #{ops_file.ops_file_path}"
261
261
 
@@ -287,7 +287,7 @@ module OpsWalrus
287
287
 
288
288
  ops_file = load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir)
289
289
 
290
- bundler.update if update_bundle
290
+ bundler.update(true) if update_bundle
291
291
 
292
292
  debug "Running: #{ops_file.ops_file_path}"
293
293
 
@@ -134,7 +134,7 @@ module OpsWalrus
134
134
 
135
135
  App.instance.debug("Remote invocation failed:\n cmd: ops run #{ops_command_options.to_s} #{remote_run_command_args.to_s}\n stdout: #{output}\n") unless exit_status == 0
136
136
 
137
- JSON.parse(output)
137
+ RemoteInvocation.parse_remote_script_invocation_result(output)
138
138
  ensure
139
139
  if json_kwargs_tempfile
140
140
  json_kwargs_tempfile.close rescue nil
@@ -201,9 +201,19 @@ module OpsWalrus
201
201
 
202
202
 
203
203
 
204
-
205
-
206
204
  class RemoteInvocation
205
+ def self.parse_remote_script_invocation_result(json_string)
206
+ retval = JSON.parse(json_string)
207
+ case retval
208
+ when Hash
209
+ retval.with_indifferent_access.easynav
210
+ when Array
211
+ retval.easynav
212
+ else
213
+ retval
214
+ end
215
+ end
216
+
207
217
  def initialize(host_proxy, ops_file, ops_prompt_for_sudo_password: nil)
208
218
  @host_proxy = host_proxy
209
219
  @ops_file = ops_file
@@ -247,7 +257,7 @@ module OpsWalrus
247
257
 
248
258
  App.instance.debug("Remote invocation failed:\n cmd: ops run #{ops_command_options.to_s} #{remote_run_command_args.to_s}\n stdout: #{output}\n") unless exit_status == 0
249
259
 
250
- JSON.parse(output)
260
+ RemoteInvocation.parse_remote_script_invocation_result(output)
251
261
  ensure
252
262
  if json_kwargs_tempfile
253
263
  json_kwargs_tempfile.close rescue nil
@@ -5,82 +5,81 @@ require_relative 'ops_file_script_dsl'
5
5
 
6
6
  module OpsWalrus
7
7
 
8
- class ArrayOrHashNavigationProxy
9
- extend Forwardable
10
-
11
- def initialize(array_or_hash)
12
- @obj = array_or_hash
13
- end
14
-
15
- def_delegators :@obj, :to_s, :inspect, :hash, :===, :eql?, :kind_of?, :is_a?, :instance_of?, :respond_to?, :<=>
16
-
17
- def [](index, *args, **kwargs, &block)
18
- @obj.method(:[]).call(index, *args, **kwargs, &block)
19
- end
20
- def respond_to_missing?(method, *)
21
- @obj.is_a?(Hash) && @obj.respond_to?(method)
22
- end
23
- def method_missing(name, *args, **kwargs, &block)
24
- case @obj
25
- when Array
26
- @obj.method(name).call(*args, **kwargs, &block)
27
- when Hash
28
- if @obj.respond_to?(name)
29
- @obj.method(name).call(*args, **kwargs, &block)
30
- else
31
- value = self[name.to_s]
32
- case value
33
- when Array, Hash
34
- ArrayOrHashNavigationProxy.new(value)
35
- else
36
- value
37
- end
38
- end
39
- end
40
- end
41
- end
42
-
43
- class InvocationParams
44
- # @params : Hash
45
-
46
- # params : Hash | ArrayOrHashNavigationProxy
47
- def initialize(hashlike_params)
48
- # this doesn't seem to make any difference
49
- @params = hashlike_params.to_h
50
- # @params = hashlike_params
51
- end
52
-
53
- def [](key)
54
- key = key.to_s if key.is_a? Symbol
55
- @params[key]
56
- end
57
-
58
- def dig(*keys, default: nil)
59
- # keys = keys.map {|key| key.is_a?(Integer) ? key : key.to_s }
60
- @params.dig(*keys) || default
61
- end
62
-
63
- def method_missing(name, *args, **kwargs, &block)
64
- if @params.respond_to?(name)
65
- @params.method(name).call(*args, **kwargs, &block)
66
- else
67
- value = self[name]
68
- case value
69
- when Array, Hash
70
- ArrayOrHashNavigationProxy.new(value)
71
- else
72
- value
73
- end
74
- end
75
- end
76
- end
77
-
78
- class EnvParams < InvocationParams
79
- # params : Hash | ArrayOrHashNavigationProxy
80
- def initialize(hashlike_params = ENV)
81
- super(hashlike_params)
82
- end
83
- end
8
+ # class ArrayOrHashNavigationProxy
9
+ # extend Forwardable
10
+
11
+ # def initialize(array_or_hash)
12
+ # @obj = array_or_hash
13
+ # end
14
+
15
+ # def_delegators :@obj, :[], :to_s, :inspect, :hash, :===, :eql?, :kind_of?, :is_a?, :instance_of?, :respond_to?, :<=>
16
+
17
+ # # def [](index, *args, **kwargs, &block)
18
+ # # @obj.method(:[]).call(index, *args, **kwargs, &block)
19
+ # # end
20
+ # def respond_to_missing?(method, *)
21
+ # @obj.is_a?(Hash) && @obj.respond_to?(method)
22
+ # end
23
+ # def method_missing(name, *args, **kwargs, &block)
24
+ # case @obj
25
+ # when Array
26
+ # @obj.method(name).call(*args, **kwargs, &block)
27
+ # when Hash
28
+ # if @obj.respond_to?(name)
29
+ # @obj.method(name).call(*args, **kwargs, &block)
30
+ # else
31
+ # value = self[name.to_s]
32
+ # case value
33
+ # when Array, Hash
34
+ # ArrayOrHashNavigationProxy.new(value)
35
+ # else
36
+ # value
37
+ # end
38
+ # end
39
+ # end
40
+ # end
41
+ # end
42
+
43
+ # class InvocationParams
44
+ # # @params : Hash
45
+
46
+ # # params : Hash | ArrayOrHashNavigationProxy
47
+ # def initialize(hashlike_params)
48
+ # # this doesn't seem to make any difference
49
+ # @params = hashlike_params.to_h
50
+ # # @params = hashlike_params
51
+ # end
52
+
53
+ # def [](key)
54
+ # @params[key]
55
+ # end
56
+
57
+ # def dig(*keys, default: nil)
58
+ # # keys = keys.map {|key| key.is_a?(Integer) ? key : key.to_s }
59
+ # @params.dig(*keys) || default
60
+ # end
61
+
62
+ # def method_missing(name, *args, **kwargs, &block)
63
+ # if @params.respond_to?(name)
64
+ # @params.method(name).call(*args, **kwargs, &block)
65
+ # else
66
+ # value = self[name]
67
+ # case value
68
+ # when Array, Hash
69
+ # ArrayOrHashNavigationProxy.new(value)
70
+ # else
71
+ # value
72
+ # end
73
+ # end
74
+ # end
75
+ # end
76
+
77
+ # class EnvParams < InvocationParams
78
+ # # params : Hash | ArrayOrHashNavigationProxy
79
+ # def initialize(hashlike_params = ENV)
80
+ # super(hashlike_params)
81
+ # end
82
+ # end
84
83
 
85
84
  class OpsFileScript
86
85
 
@@ -135,16 +134,27 @@ module OpsWalrus
135
134
  # - #host_proxy_class
136
135
  # - #backend
137
136
  # - all the dynamically defined methods in the subclass of Invocation
137
+ #
138
+ # Return value is whatever the script returned with one exception:
139
+ # - if the script returns a Hash or an Array, the return value is an EasyNavProxy
138
140
  invoke_method_definition = <<~INVOKE_METHOD
139
141
  def _invoke(runtime_env, hashlike_params)
140
142
  @runtime_env = runtime_env
141
- @params = InvocationParams.new(hashlike_params)
143
+ @params = hashlike_params.easynav
142
144
  @runtime_ops_file_path = __FILE__
143
- #{ruby_script}
145
+ _retval = begin
146
+ #{ruby_script}
147
+ end
148
+ case _retval
149
+ when Hash, Array
150
+ _retval.easynav
151
+ else
152
+ _retval
153
+ end
144
154
  end
145
155
  INVOKE_METHOD
146
156
 
147
- invoke_method_line_count_prior_to_ruby_script_from_ops_file = 4
157
+ invoke_method_line_count_prior_to_ruby_script_from_ops_file = 5
148
158
  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)
149
159
 
150
160
  klass
@@ -366,7 +366,7 @@ module OpsWalrus
366
366
  end
367
367
 
368
368
  def parse_stdout_and_script_return_value(command_output)
369
- output_sections = command_output.split(/^#{::OpsWalrus::App::SCRIPT_RESULT_HEADER}$/)
369
+ output_sections = command_output.split(/#{::OpsWalrus::App::SCRIPT_RESULT_HEADER}/)
370
370
  case output_sections.count
371
371
  when 1
372
372
  stdout, ops_script_retval = output_sections.first, nil
@@ -1,7 +1,54 @@
1
- require 'json'
2
- require 'pathname'
3
1
  require 'active_support'
4
2
  require 'active_support/core_ext/hash'
3
+ require 'json'
4
+ require 'pathname'
5
+
6
+ class EasyNavProxy
7
+ extend Forwardable
8
+
9
+ # indexable_obj must implement #respond_to? and #has_key?
10
+ def initialize(indexable_obj)
11
+ @obj = indexable_obj
12
+ end
13
+
14
+ def_delegators :@obj, :[], :to_s, :inspect, :hash, :===, :==, :eql?, :kind_of?, :is_a?, :instance_of?, :respond_to?, :<=>
15
+
16
+ def easynav
17
+ self
18
+ end
19
+
20
+ def respond_to_missing?(method, *)
21
+ @obj.respond_to?(method) || @obj.has_key?(method)
22
+ end
23
+ def method_missing(method, *args, **kwargs, &block)
24
+ if @obj.respond_to?(method)
25
+ @obj.method(method).call(*args, **kwargs, &block)
26
+ elsif @obj.has_key?(method)
27
+ value = self[method]
28
+ case value
29
+ when Array, Hash
30
+ EasyNavProxy.new(value)
31
+ else
32
+ value
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ class Hash
39
+ def easynav
40
+ EasyNavProxy.new(self.with_indifferent_access)
41
+ end
42
+ end
43
+
44
+ class Array
45
+ def has_key?(key)
46
+ key.is_a?(Integer) && key < size
47
+ end
48
+ def easynav
49
+ EasyNavProxy.new(self)
50
+ end
51
+ end
5
52
 
6
53
  class String
7
54
  def escape_single_quotes
@@ -23,7 +70,6 @@ class Pathname
23
70
  end
24
71
  end
25
72
 
26
-
27
73
  class String
28
74
  def boolean!(default: false)
29
75
  boolean_str = strip.downcase
@@ -1,3 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/hash'
1
3
  require 'json'
2
4
  require 'shellwords'
3
5
  require 'socket'
@@ -238,7 +240,8 @@ module OpsWalrus
238
240
 
239
241
  def initialize(app)
240
242
  @app = app
241
- @env = EnvParams.new(ENV)
243
+ # @env = EnvParams.new(ENV)
244
+ @env = ENV.to_h.with_indifferent_access.easynav
242
245
  @bundle_load_path = LoadPath.new(self, @app.bundle_dir)
243
246
  @app_load_path = LoadPath.new(self, @app.pwd)
244
247
 
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.63"
2
+ VERSION = "1.0.65"
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.63
4
+ version: 1.0.65
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-26 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport