opswalrus 1.0.34 → 1.0.36

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: ab3f1e696e7425c7caf84aff75bc525f01d1e9d8a3f710ca16c22a1c33a17d7b
4
- data.tar.gz: 5ee348372ba6f0ae7263277ed0a5e1e22164dbeb2c0efa2db273aefa7432007d
3
+ metadata.gz: 60ed1418b527a8f5ef37e9d54055a9e9da76c6811ac9c84a0b71f9025e33b6ff
4
+ data.tar.gz: 763003e1261bb724b5ebb061b83a662a33fd0dc4f742c3fe0971a5ab1532ea57
5
5
  SHA512:
6
- metadata.gz: a5fb03f7d54471d7148e9d96139a7e7f31d90aa9eaca9001f22084ccd5ab6ced80020b08f7bfdfe6aa64e74d56624e336383e06082c95d61b76f808b0167dffe
7
- data.tar.gz: 6f8cfdbb284d986e2db323ed668dfd6546dd52dbad8ac838229d41e21a8d6b6db836df171178d297b19ffea0f88e8ce9a37edb2b6514d1ba4c38e8413c64414f
6
+ metadata.gz: ae75edcfac60e9c4a085144ba6111422c135a0737e772c75a740d51aca456861c29570344d79922c58bdf7facd94cb6eb451c3b3e3b65291bafa12c333b13c98
7
+ data.tar.gz: 57f893715ebc410018ccb00f7f048641af2ab0d0ec1d74a15a235e8df8072f450b63f98c4115c1fb9eb8c934718d4cfb52e368f9a61a0d70f035d400bd482ec1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.34)
4
+ opswalrus (1.0.36)
5
5
  amazing_print (~> 1.5)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
data/lib/opswalrus/app.rb CHANGED
@@ -189,8 +189,13 @@ module OpsWalrus
189
189
  @sudo_password
190
190
  end
191
191
 
192
- # params must be a string representation of a JSON object: '{}' | '{"key1": ... , ...}'
193
- def set_params(params)
192
+ # params is a string that specifies a file path OR it is a string representation of a JSON object: '{}' | '{"key1": ... , ...}'
193
+ def set_params(file_path_or_json_string)
194
+ params = if File.exist?(file_path_or_json_string)
195
+ File.read(file_path_or_json_string)
196
+ else
197
+ file_path_or_json_string
198
+ end
194
199
  json_hash = JSON.parse(params) rescue nil
195
200
  json_hash = json_hash.is_a?(Hash) ? json_hash : nil
196
201
 
@@ -116,6 +116,8 @@ module OpsWalrus
116
116
 
117
117
  destination_package_path = @bundle_dir.join(package_reference.import_resolution_dirname)
118
118
 
119
+ App.instance.log("Downloading #{package_reference} referenced in #{package_file.package_file_path} to #{destination_package_path}")
120
+
119
121
  # we return early here under the assumption that an already downloaded package/version combo will not
120
122
  # differ if we download it again multiple times to the same location
121
123
  if destination_package_path.exist?
data/lib/opswalrus/cli.rb CHANGED
@@ -156,11 +156,12 @@ module OpsWalrus
156
156
  long_desc 'Run the specified operation found within the specified package'
157
157
  arg 'args', :multiple
158
158
  command :run do |c|
159
- c.flag [:u, :user], desc: "Specify the user that the operation will run as"
160
159
  c.switch :pass, desc: "Prompt for a sudo password"
161
- c.flag [:p, :params], desc: "JSON string that represents the input parameters for the operation. The JSON string must conform to the params schema for the operation."
162
160
  c.switch :script, desc: "Script mode"
163
161
 
162
+ c.flag [:u, :user], desc: "Specify the user that the operation will run as"
163
+ c.flag [:p, :params], desc: "Either specify a file that contains JSON OR specify a JSON encoded string. In both cases, the JSON represents the runtime arguments (i.e. the params) for the operation. The JSON string must conform to the params schema for the operation being run."
164
+
164
165
  # dry run
165
166
  c.switch :noop, desc: "Perform a dry run"
166
167
  c.switch :dryrun, desc: "Perform a dry run"
@@ -171,18 +172,17 @@ module OpsWalrus
171
172
  $app.set_log_level(log_level)
172
173
 
173
174
  hosts = global_options[:hosts]
174
- tags = global_options[:tags]
175
-
176
175
  $app.set_inventory_hosts(hosts)
176
+
177
+ tags = global_options[:tags]
177
178
  $app.set_inventory_tags(tags)
178
179
 
179
180
  user = options[:user]
180
- params = options[:params]
181
-
182
- $app.set_params(params)
183
-
184
181
  $app.set_sudo_user(user) if user
185
182
 
183
+ params = options[:params]
184
+ $app.set_params(params) if params
185
+
186
186
  id_files = global_options[:id]
187
187
  id_files = OpsWalrus.env_specified_age_ids if id_files.empty?
188
188
 
@@ -228,7 +228,7 @@ module OpsWalrus
228
228
  end
229
229
 
230
230
  def host_prop(name)
231
- @props["name"]
231
+ @props[name] || @default_props[name]
232
232
  end
233
233
 
234
234
  end
@@ -344,11 +344,11 @@ module OpsWalrus
344
344
  def write_temp_ssh_keys_if_needed(keys)
345
345
  keys.map do |key_file_path_or_in_memory_key_text|
346
346
  if key_file_path_or_in_memory_key_text.is_a? SecretRef # we're dealing with an in-memory key file; we need to write it to a tempfile
347
- tempfile = Tempfile.new
347
+ tempfile = Tempfile.create
348
348
  @tmp_ssh_key_files << tempfile
349
349
  key_file_contents = @hosts_file.read_secret(key_file_path_or_in_memory_key_text.to_s)
350
350
  tempfile.write(key_file_contents)
351
- tempfile.close(false) # we want to close the file without unlinking so that the editor can write to it
351
+ tempfile.close # we want to close the file without unlinking so that the editor can write to it
352
352
  tempfile.path
353
353
  else # we're dealing with a reference to a keyfile - a path - so return it
354
354
  key_file_path_or_in_memory_key_text
@@ -372,7 +372,7 @@ module OpsWalrus
372
372
  @runtime_env = nil
373
373
  @sshkit_backend = nil
374
374
  @tmp_bundle_root_dir = nil
375
- @tmp_ssh_key_files.each {|tmpfile| tmpfile.close() rescue nil; tmpfile.unlink() rescue nil }
375
+ @tmp_ssh_key_files.each {|tmpfile| tmpfile.close() rescue nil; File.unlink(tmpfile) rescue nil }
376
376
  @tmp_ssh_key_files = []
377
377
  end
378
378
 
@@ -11,9 +11,9 @@ module OpsWalrus
11
11
 
12
12
  class HostsFile
13
13
  def self.edit(file_path)
14
- tempfile = Tempfile.new
14
+ tempfile = Tempfile.create
15
15
  begin
16
- tempfile.close(false) # we want to close the file without unlinking so that the editor can write to it
16
+ tempfile.close # we want to close the file without unlinking so that the editor can write to it
17
17
  HostsFile.new(file_path).decrypt(tempfile.path)
18
18
  if TTY::Editor.open(tempfile.path)
19
19
  # tempfile.open()
@@ -21,7 +21,7 @@ module OpsWalrus
21
21
  end
22
22
  ensure
23
23
  tempfile.close rescue nil
24
- tempfile.unlink # deletes the temp file
24
+ File.unlink(tempfile) # deletes the temp file
25
25
  end
26
26
  end
27
27
 
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+ require 'tempfile'
1
3
 
2
4
  module OpsWalrus
3
5
 
@@ -94,23 +96,50 @@ module OpsWalrus
94
96
  remote_run_command_args << args.join(" ")
95
97
  end
96
98
 
97
- unless kwargs.empty?
98
- remote_run_command_args << " "
99
- remote_run_command_args << kwargs.map do |k, v|
100
- case v
101
- when Array
102
- v.map {|v_element| "#{k}:#{v_element}" }
103
- else
104
- "#{k}:#{v}"
105
- end
106
- end.join(" ")
107
- end
108
-
109
- # @host_proxy.run_ops(:run, "--script", remote_run_command_args)
110
- if @prompt_for_sudo_password
111
- @host_proxy.run_ops(:run, "--pass", remote_run_command_args)
112
- else
113
- @host_proxy.run_ops(:run, remote_run_command_args)
99
+ # unless kwargs.empty?
100
+ # remote_run_command_args << " "
101
+ # remote_run_command_args << kwargs.map do |k, v|
102
+ # case v
103
+ # when Array
104
+ # v.map {|v_element| "#{k}:#{v_element}" }
105
+ # else
106
+ # "#{k}:#{v}"
107
+ # end
108
+ # end.join(" ")
109
+ # end
110
+ begin
111
+ json = JSON.dump(kwargs) unless kwargs.empty?
112
+ if json
113
+ # write the kwargs to a tempfile
114
+ json_kwargs_tempfile = Tempfile.create('ops_invoke_kwargs')
115
+ json_kwargs_tempfile.write(json)
116
+ json_kwargs_tempfile.close() # we want to close the file without unlinking so that we can copy it to the remote host before deleting it
117
+
118
+ # upload the kwargs file to the remote host
119
+ json_kwargs_tempfile_path = json_kwargs_tempfile.path.to_pathname
120
+ remote_json_kwargs_tempfile_basename = json_kwargs_tempfile_path.basename
121
+ @host_proxy.upload(json_kwargs_tempfile_path, remote_json_kwargs_tempfile_basename)
122
+ end
123
+
124
+ # invoke the ops command on the remote host to run the specified ops script on the remote host
125
+ ops_command_options = ""
126
+ ops_command_options << "--pass" if @prompt_for_sudo_password
127
+ ops_command_options << " --params #{remote_json_kwargs_tempfile_basename}" if remote_json_kwargs_tempfile_basename
128
+ retval = if ops_command_options.empty?
129
+ @host_proxy.run_ops(:run, remote_run_command_args)
130
+ else
131
+ @host_proxy.run_ops(:run, ops_command_options, remote_run_command_args)
132
+ end
133
+
134
+ retval
135
+ ensure
136
+ if json_kwargs_tempfile
137
+ json_kwargs_tempfile.close rescue nil
138
+ File.unlink(json_kwargs_tempfile) rescue nil
139
+ end
140
+ if remote_json_kwargs_tempfile_basename
141
+ @host_proxy.execute(:rm, "-f", remote_json_kwargs_tempfile_basename)
142
+ end
114
143
  end
115
144
  end
116
145
  end
@@ -55,9 +55,9 @@ module OpsWalrus
55
55
  @params[key]
56
56
  end
57
57
 
58
- def dig(*keys)
58
+ def dig(*keys, default: nil)
59
59
  # keys = keys.map {|key| key.is_a?(Integer) ? key : key.to_s }
60
- @params.dig(*keys)
60
+ @params.dig(*keys) || default
61
61
  end
62
62
 
63
63
  def method_missing(name, *args, **kwargs, &block)
@@ -141,6 +141,7 @@ module OpsWalrus
141
141
  def _invoke(runtime_env, hashlike_params)
142
142
  @runtime_env = runtime_env
143
143
  @params = InvocationParams.new(hashlike_params)
144
+ params = @params
144
145
  #{ruby_script}
145
146
  end
146
147
  INVOKE_METHOD
@@ -198,14 +198,14 @@ module OpsWalrus
198
198
  # invocation_context._invoke(*args, **kwargs)
199
199
  end
200
200
 
201
- def params(*keys, default: nil)
202
- keys = keys.map(&:to_s)
203
- if keys.empty?
204
- @params
205
- else
206
- @params.dig(*keys) || default
207
- end
208
- end
201
+ # def params(*keys, default: nil)
202
+ # keys = keys.map(&:to_s)
203
+ # if keys.empty?
204
+ # @params
205
+ # else
206
+ # @params.dig(*keys) || default
207
+ # end
208
+ # end
209
209
 
210
210
  def desc(msg)
211
211
  puts msg.mustache
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.34"
2
+ VERSION = "1.0.36"
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.34
4
+ version: 1.0.36
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-04 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print