opswalrus 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/opswalrus/app.rb +12 -0
- data/lib/opswalrus/cli.rb +10 -4
- data/lib/opswalrus/host.rb +23 -12
- data/lib/opswalrus/ops_file.rb +5 -0
- data/lib/opswalrus/ops_file_script.rb +5 -3
- data/lib/opswalrus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa4d06b1bc87888397e4509eda913a1a5ad0cf4f069762852282de9c1cd7c6a0
|
4
|
+
data.tar.gz: 605d4b7e09d3fe47b2fa5106d5cd27e8255ba5265dff1bcfe8fbda3fb380195d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cce83e3128b0d19d7ccec3d0fe85411d19959229fc8cd3ad9fdf47b40c739e598f3dd2020078492361df9d309b15e0c82824901ff2511b434adea09c9484d246
|
7
|
+
data.tar.gz: 7bc58a62f322c543e2aa57b5a75611d4984c3b72454c4ac52fbd91bfa074efde217fa8355bfc38718d13b0ac839fbe13c8c567307e0c1516e3067cea351f4594
|
data/Gemfile.lock
CHANGED
data/lib/opswalrus/app.rb
CHANGED
@@ -64,6 +64,14 @@ module OpsWalrus
|
|
64
64
|
"" # return empty string because we won't want anyone accidentally printing or inspecting @sudo_password
|
65
65
|
end
|
66
66
|
|
67
|
+
def emit_json_output!
|
68
|
+
@emit_json_output = true
|
69
|
+
end
|
70
|
+
|
71
|
+
def emit_json_output?
|
72
|
+
@emit_json_output
|
73
|
+
end
|
74
|
+
|
67
75
|
def set_local_hostname(hostname)
|
68
76
|
hostname = hostname.strip
|
69
77
|
@local_hostname = hostname.empty? ? "localhost" : hostname
|
@@ -186,6 +194,10 @@ module OpsWalrus
|
|
186
194
|
puts JSON.pretty_generate(result.value)
|
187
195
|
end
|
188
196
|
|
197
|
+
if emit_json_output?
|
198
|
+
puts JSON.pretty_generate(result.value)
|
199
|
+
end
|
200
|
+
|
189
201
|
exit_status
|
190
202
|
ensure
|
191
203
|
FileUtils.remove_entry(tmp_dir) if tmp_dir
|
data/lib/opswalrus/cli.rb
CHANGED
@@ -15,10 +15,10 @@ module OpsWalrus
|
|
15
15
|
|
16
16
|
# this is invoked on an unhandled exception or a call to exit_now!
|
17
17
|
on_error do |exception|
|
18
|
-
puts "*" * 80
|
19
|
-
puts "catchall exception handler:"
|
20
|
-
puts exception.message
|
21
|
-
puts exception.backtrace.join("\n")
|
18
|
+
# puts "*" * 80
|
19
|
+
# puts "catchall exception handler:"
|
20
|
+
# puts exception.message
|
21
|
+
# puts exception.backtrace.join("\n")
|
22
22
|
false # disable built-in exception handling
|
23
23
|
end
|
24
24
|
|
@@ -53,6 +53,7 @@ module OpsWalrus
|
|
53
53
|
c.flag [:u, :user], desc: "Specify the user that the operation will run as"
|
54
54
|
c.switch :pass, desc: "Prompt for a sudo password"
|
55
55
|
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."
|
56
|
+
c.switch :json, desc: "Emit JSON output"
|
56
57
|
|
57
58
|
c.action do |global_options, options, args|
|
58
59
|
hosts = global_options[:hosts] || []
|
@@ -80,6 +81,10 @@ module OpsWalrus
|
|
80
81
|
$app.prompt_sudo_password
|
81
82
|
end
|
82
83
|
|
84
|
+
if options[:json]
|
85
|
+
$app.emit_json_output!
|
86
|
+
end
|
87
|
+
|
83
88
|
# puts "verbose"
|
84
89
|
# puts verbose.inspect
|
85
90
|
# puts "user"
|
@@ -132,6 +137,7 @@ module OpsWalrus
|
|
132
137
|
|
133
138
|
c.default_command :status
|
134
139
|
end
|
140
|
+
|
135
141
|
end
|
136
142
|
end
|
137
143
|
|
data/lib/opswalrus/host.rb
CHANGED
@@ -54,13 +54,17 @@ module OpsWalrus
|
|
54
54
|
# end
|
55
55
|
|
56
56
|
# runs the specified ops command with the specified command arguments
|
57
|
-
def run_ops(command, command_arguments, in_bundle_root_dir: true)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
def run_ops(command, command_arguments, in_bundle_root_dir: true, verbose: false)
|
58
|
+
# e.g. /home/linuxbrew/.linuxbrew/bin/gem exec -g opswalrus ops bundle unzip tmpops.zip
|
59
|
+
# e.g. /home/linuxbrew/.linuxbrew/bin/gem exec -g opswalrus ops run echo.ops args:foo args:bar
|
60
|
+
|
61
|
+
cmd = "/home/linuxbrew/.linuxbrew/bin/gem exec -g opswalrus ops"
|
62
|
+
cmd << " -v" if verbose
|
63
|
+
cmd << " #{command.to_s}"
|
64
|
+
cmd << " #{@tmp_bundle_root_dir}" if in_bundle_root_dir
|
65
|
+
cmd << " #{command_arguments}" unless command_arguments.empty?
|
66
|
+
|
67
|
+
shell!(cmd)
|
64
68
|
end
|
65
69
|
|
66
70
|
end
|
@@ -82,19 +86,26 @@ module OpsWalrus
|
|
82
86
|
# so we want to build up a command and send it to the remote host via HostDSL#run_ops
|
83
87
|
@method_chain.unshift(Bundler::BUNDLE_DIR) if @is_invocation_a_call_to_package_in_bundle_dir
|
84
88
|
|
85
|
-
|
86
|
-
# remote_run_command_args << path_to_ops_file_basename
|
89
|
+
remote_run_command_args = "--json"
|
87
90
|
|
88
|
-
remote_run_command_args
|
91
|
+
remote_run_command_args << " "
|
92
|
+
remote_run_command_args << @method_chain.join(" ")
|
89
93
|
|
90
94
|
unless args.empty?
|
91
95
|
remote_run_command_args << " "
|
92
96
|
remote_run_command_args << args.join(" ")
|
93
97
|
end
|
94
98
|
|
95
|
-
unless
|
99
|
+
unless kwargs.empty?
|
96
100
|
remote_run_command_args << " "
|
97
|
-
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(" ")
|
98
109
|
end
|
99
110
|
|
100
111
|
@host_proxy.run_ops(:run, remote_run_command_args)
|
data/lib/opswalrus/ops_file.rb
CHANGED
@@ -27,6 +27,10 @@ module OpsWalrus
|
|
27
27
|
@yaml || (load_file && @yaml)
|
28
28
|
end
|
29
29
|
|
30
|
+
def script_line_offset
|
31
|
+
@script_line_offset || (load_file && @script_line_offset)
|
32
|
+
end
|
33
|
+
|
30
34
|
def script
|
31
35
|
@script || (load_file && @script)
|
32
36
|
end
|
@@ -35,6 +39,7 @@ module OpsWalrus
|
|
35
39
|
yaml, ruby_script = if @ops_file_path.exist?
|
36
40
|
parse(File.read(@ops_file_path))
|
37
41
|
end || ["", ""]
|
42
|
+
@script_line_offset = yaml.lines.size + 1 # +1 to account for the ... line
|
38
43
|
@yaml = YAML.load(yaml) || {} # post_invariant: @yaml is a Hash
|
39
44
|
@script = OpsFileScript.new(self, ruby_script)
|
40
45
|
end
|
@@ -148,9 +148,11 @@ module OpsWalrus
|
|
148
148
|
# we run the block in the context of the host, s.t. `self` within the block evaluates to `host`
|
149
149
|
retval = host.instance_exec(local_host, &block) # host is passed as the argument to the block
|
150
150
|
|
151
|
+
puts retval.inspect
|
152
|
+
|
151
153
|
# cleanup
|
152
|
-
if
|
153
|
-
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip",
|
154
|
+
if tmp_bundle_root_dir =~ /tmp/ # sanity check the temp path before we blow away something we don't intend
|
155
|
+
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip", tmp_bundle_root_dir)
|
154
156
|
else
|
155
157
|
host.execute(:rm, "-rf", "tmpopsbootstrap.sh", "tmpops.zip")
|
156
158
|
end
|
@@ -475,7 +477,7 @@ module OpsWalrus
|
|
475
477
|
|
476
478
|
def evaluate
|
477
479
|
# catch(:exit_now) do
|
478
|
-
eval(@ops_file_script.script)
|
480
|
+
eval(@ops_file_script.script, nil, @ops_file_script.ops_file.ops_file_path.to_s, @ops_file_script.ops_file.script_line_offset)
|
479
481
|
# end
|
480
482
|
end
|
481
483
|
|
data/lib/opswalrus/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.4
|
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-08-
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: citrus
|