opswalrus 1.0.35 → 1.0.37

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: afddda8670c4bf29ab120d6f80d89f13d6eaa1764f4068fa8fd9cd33b4e6a4a9
4
- data.tar.gz: eeac298ab64e7f77e5e589288fe4a69397d7a321ef3887ac378f25aa3060ffee
3
+ metadata.gz: ab53631e63fd44c1825e7a38721905420b063e4480ace3cb48c9d5aad922dc14
4
+ data.tar.gz: aecd03aadaab772dfae1e8379036038ed17e0c57b78c75c178f70c4b3a65afeb
5
5
  SHA512:
6
- metadata.gz: f904e63bcef6b3eb970bb3ef162186268f6e95371655cab071dcb8a7c0a1c655c1f7ade92be63fe387b676d4af80e2de985909ce7a8a1e6f0a032475041eb4f4
7
- data.tar.gz: c2d9efb14e0d063d5861e7cafa2a3a44fbeed4ca07a8e748928bfdf16cdf46dda9aabb08f3f5e259e6fbfc5a5d11ffa2254da58140fbfb40e2146214c8df27ec
6
+ metadata.gz: af2a6bc851e53a1bee7e2b1d9d7dd57f2f953661223d464f57c7e7e8157b4ab725c9db90cc835380c12c6a9f5438a515e435cf4009e753492c6304e7a3b2a750
7
+ data.tar.gz: 15fbd461e6c794325bee7def61a517b91c840318348b83e83639c175d3efb5f1a5cbd424b6a8634bfdc20c2b2805af383aee3ce1d7870a1dd222e843ef9ed509
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.35)
4
+ opswalrus (1.0.37)
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
 
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
 
@@ -224,11 +224,11 @@ module OpsWalrus
224
224
  end
225
225
 
226
226
  def desc(msg)
227
- puts msg.mustache
227
+ puts msg.mustache(2)
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
@@ -146,7 +146,7 @@ module OpsWalrus
146
146
  end
147
147
  INVOKE_METHOD
148
148
 
149
- invoke_method_line_count_prior_to_ruby_script_from_ops_file = 3
149
+ invoke_method_line_count_prior_to_ruby_script_from_ops_file = 4
150
150
  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)
151
151
 
152
152
  klass
@@ -208,7 +208,7 @@ module OpsWalrus
208
208
  # end
209
209
 
210
210
  def desc(msg)
211
- puts msg.mustache
211
+ puts msg.mustache(2)
212
212
  end
213
213
 
214
214
  # runs the given command
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.35"
2
+ VERSION = "1.0.37"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opswalrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.35
4
+ version: 1.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ellis