opswalrus 1.0.35 → 1.0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/opswalrus/app.rb +7 -2
- data/lib/opswalrus/cli.rb +8 -8
- data/lib/opswalrus/host.rb +4 -4
- data/lib/opswalrus/hosts_file.rb +3 -3
- data/lib/opswalrus/invocation.rb +46 -17
- data/lib/opswalrus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ed1418b527a8f5ef37e9d54055a9e9da76c6811ac9c84a0b71f9025e33b6ff
|
4
|
+
data.tar.gz: 763003e1261bb724b5ebb061b83a662a33fd0dc4f742c3fe0971a5ab1532ea57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae75edcfac60e9c4a085144ba6111422c135a0737e772c75a740d51aca456861c29570344d79922c58bdf7facd94cb6eb451c3b3e3b65291bafa12c333b13c98
|
7
|
+
data.tar.gz: 57f893715ebc410018ccb00f7f048641af2ab0d0ec1d74a15a235e8df8072f450b63f98c4115c1fb9eb8c934718d4cfb52e368f9a61a0d70f035d400bd482ec1
|
data/Gemfile.lock
CHANGED
data/lib/opswalrus/app.rb
CHANGED
@@ -189,8 +189,13 @@ module OpsWalrus
|
|
189
189
|
@sudo_password
|
190
190
|
end
|
191
191
|
|
192
|
-
# params
|
193
|
-
def set_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
|
|
data/lib/opswalrus/host.rb
CHANGED
@@ -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.
|
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
|
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;
|
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
|
|
data/lib/opswalrus/hosts_file.rb
CHANGED
@@ -11,9 +11,9 @@ module OpsWalrus
|
|
11
11
|
|
12
12
|
class HostsFile
|
13
13
|
def self.edit(file_path)
|
14
|
-
tempfile = Tempfile.
|
14
|
+
tempfile = Tempfile.create
|
15
15
|
begin
|
16
|
-
tempfile.close
|
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
|
-
|
24
|
+
File.unlink(tempfile) # deletes the temp file
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/opswalrus/invocation.rb
CHANGED
@@ -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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
data/lib/opswalrus/version.rb
CHANGED