mixlib-shellout 3.0.9-universal-mingw32 → 3.1.0-universal-mingw32

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: 3bccf795560a590295f3efb38b5febff8d1a949809cbd399f8610d14a51f56aa
4
- data.tar.gz: e223541817b4f3c367b75ea1d4dfe52ba1036734785e60f937aad283b575d32d
3
+ metadata.gz: 4e9ef2568108758a0de4328dd5e40736062733f3a06641bc34dd47a330422d71
4
+ data.tar.gz: 06c07cb6c17162df072184d0d95bc8287589bf8a6c0555949ab2fb2ee8c3b0af
5
5
  SHA512:
6
- metadata.gz: 6e20eac99960f5a53cc7626bc0e8d8595e61058488d0aff1dfbbecbed8bca74277b1c342a64784624ff027d63c80c68cfe231ff6a5e5b2ff608ae1cdde045b06
7
- data.tar.gz: 58ab5e2fb4911c5a7d3bab6a7a5d314270351a355601d9971382a8bbc321885f92223983e3850e259b701f90d2ef584d88f0a14e8f36cf3a80e5bf00e95d5b1b
6
+ metadata.gz: 47825a0e3e931f5b44965da2bb6a10c61077e11416bbea404e0dd89ddfaa602d2f6aea050ebd97780e064bee49816d63bfe003f3bfa056950b1e25502a543678
7
+ data.tar.gz: 3cc0041e90f6f123437bf2a818bcf50ee70708bda1a606703bdae5dce277977add506eeebef625780b8a75ea585dfc65c6699391956ede076c110b1d096b263c
@@ -65,7 +65,7 @@ module Mixlib
65
65
  # as the subprocess is running.
66
66
  attr_accessor :live_stderr
67
67
 
68
- # ShellOut will push data from :input down the stdin of the subprocss.
68
+ # ShellOut will push data from :input down the stdin of the subprocess.
69
69
  # Normally set via options passed to new.
70
70
  # Default: nil
71
71
  attr_accessor :input
@@ -0,0 +1,209 @@
1
+ #--
2
+ # Author:: Daniel DeLeo (<dan@chef.io>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require_relative "../shellout"
19
+ require "chef-utils"
20
+ require "chef-utils/dsl/path_sanity"
21
+ require "chef-utils/internal"
22
+
23
+ module Mixlib
24
+ class ShellOut
25
+ module Helper
26
+ include ChefUtils::Internal
27
+ include ChefUtils::DSL::PathSanity
28
+
29
+ # PREFERRED APIS:
30
+ #
31
+ # all consumers should now call shell_out!/shell_out.
32
+ #
33
+ # the shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
34
+ # in rspec tests, and should ideally always be used to make code refactoring that do not
35
+ # change behavior easier:
36
+ #
37
+ # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
38
+ # provider.shell_out!("foo", [ "bar", nil, "baz"])
39
+ # provider.shell_out!(["foo", nil, "bar" ], ["baz"])
40
+ #
41
+ # note that shell_out_compacted also includes adding the magical timeout option to force
42
+ # people to setup expectations on that value explicitly. it does not include the default_env
43
+ # mangling in order to avoid users having to setup an expectation on anything other than
44
+ # setting `default_env: false` and allow us to make tweak to the default_env without breaking
45
+ # a thousand unit tests.
46
+ #
47
+
48
+ def shell_out(*args, **options)
49
+ options = options.dup
50
+ options = __maybe_add_timeout(self, options)
51
+ if options.empty?
52
+ shell_out_compacted(*__clean_array(*args))
53
+ else
54
+ shell_out_compacted(*__clean_array(*args), **options)
55
+ end
56
+ end
57
+
58
+ def shell_out!(*args, **options)
59
+ options = options.dup
60
+ options = __maybe_add_timeout(self, options)
61
+ if options.empty?
62
+ shell_out_compacted!(*__clean_array(*args))
63
+ else
64
+ shell_out_compacted!(*__clean_array(*args), **options)
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ # helper sugar for resources that support passing timeouts to shell_out
71
+ #
72
+ # module method to not pollute namespaces, but that means we need self injected as an arg
73
+ # @api private
74
+ def __maybe_add_timeout(obj, options)
75
+ options = options.dup
76
+ # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here
77
+ default_val = 900
78
+ return options if options.key?(:timeout)
79
+
80
+ # FIXME: need to nuke descendent tracker out of Chef::Provider so we can just define that class here without requiring the
81
+ # world, and then just use symbol lookup
82
+ if obj.class.ancestors.map(&:name).include?("Chef::Provider") && obj.respond_to?(:new_resource) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout)
83
+ options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : default_val
84
+ end
85
+ options
86
+ end
87
+
88
+ # helper function to mangle options when `default_env` is true
89
+ #
90
+ # @api private
91
+ def __apply_default_env(options)
92
+ options = options.dup
93
+ default_env = options.delete(:default_env)
94
+ default_env = true if default_env.nil?
95
+ if default_env
96
+ env_key = options.key?(:env) ? :env : :environment
97
+ options[env_key] = {
98
+ "LC_ALL" => __config[:internal_locale],
99
+ "LANGUAGE" => __config[:internal_locale],
100
+ "LANG" => __config[:internal_locale],
101
+ __env_path_name => sanitized_path,
102
+ }.update(options[env_key] || {})
103
+ end
104
+ options
105
+ end
106
+
107
+ # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
108
+ #
109
+ # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
110
+ #
111
+ def shell_out_compacted(*args, **options)
112
+ options = __apply_default_env(options)
113
+ if options.empty?
114
+ __shell_out_command(*args)
115
+ else
116
+ __shell_out_command(*args, **options)
117
+ end
118
+ end
119
+
120
+ # this SHOULD be used for setting up expectations in rspec, see banner comment at top.
121
+ #
122
+ # the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
123
+ #
124
+ def shell_out_compacted!(*args, **options)
125
+ options = __apply_default_env(options)
126
+ cmd = if options.empty?
127
+ __shell_out_command(*args)
128
+ else
129
+ __shell_out_command(*args, **options)
130
+ end
131
+ cmd.error!
132
+ cmd
133
+ end
134
+
135
+ # Helper for subclasses to reject nil out of an array. It allows
136
+ # using the array form of shell_out (which avoids the need to surround arguments with
137
+ # quote marks to deal with shells).
138
+ #
139
+ # Usage:
140
+ # shell_out!(*clean_array("useradd", universal_options, useradd_options, new_resource.username))
141
+ #
142
+ # universal_options and useradd_options can be nil, empty array, empty string, strings or arrays
143
+ # and the result makes sense.
144
+ #
145
+ # keeping this separate from shell_out!() makes it a bit easier to write expectations against the
146
+ # shell_out args and be able to omit nils and such in the tests (and to test that the nils are
147
+ # being rejected correctly).
148
+ #
149
+ # @param args [String] variable number of string arguments
150
+ # @return [Array] array of strings with nil and null string rejection
151
+
152
+ def __clean_array(*args)
153
+ args.flatten.compact.map(&:to_s)
154
+ end
155
+
156
+ def __shell_out_command(*args, **options)
157
+ if __transport_connection
158
+ FakeShellOut.new(args, options, __transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
159
+ else
160
+ cmd = if options.empty?
161
+ Mixlib::ShellOut.new(*args)
162
+ else
163
+ Mixlib::ShellOut.new(*args, **options)
164
+ end
165
+ cmd.live_stream ||= __io_for_live_stream
166
+ cmd.run_command
167
+ cmd
168
+ end
169
+ end
170
+
171
+ def __io_for_live_stream
172
+ if STDOUT.tty? && !__config[:daemon] && __log.debug?
173
+ STDOUT
174
+ else
175
+ nil
176
+ end
177
+ end
178
+
179
+ def __env_path_name
180
+ if ChefUtils.windows?
181
+ "Path"
182
+ else
183
+ "PATH"
184
+ end
185
+ end
186
+
187
+ class FakeShellOut
188
+ attr_reader :stdout, :stderr, :exitstatus, :status
189
+
190
+ def initialize(args, options, result)
191
+ @args = args
192
+ @options = options
193
+ @stdout = result.stdout
194
+ @stderr = result.stderr
195
+ @exitstatus = result.exit_status
196
+ @status = OpenStruct.new(success?: ( exitstatus == 0 ))
197
+ end
198
+
199
+ def error?
200
+ exitstatus != 0
201
+ end
202
+
203
+ def error!
204
+ raise Mixlib::ShellOut::ShellCommandFailed, "Unexpected exit status of #{exitstatus} running #{@args}" if error?
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.0.9".freeze
3
+ VERSION = "3.1.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.1.0
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Chef Software Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chef-utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: win32-process
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -47,6 +61,7 @@ files:
47
61
  - LICENSE
48
62
  - lib/mixlib/shellout.rb
49
63
  - lib/mixlib/shellout/exceptions.rb
64
+ - lib/mixlib/shellout/helper.rb
50
65
  - lib/mixlib/shellout/unix.rb
51
66
  - lib/mixlib/shellout/version.rb
52
67
  - lib/mixlib/shellout/windows.rb
@@ -62,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
77
  requirements:
63
78
  - - ">="
64
79
  - !ruby/object:Gem::Version
65
- version: '2.2'
80
+ version: '2.4'
66
81
  required_rubygems_version: !ruby/object:Gem::Requirement
67
82
  requirements:
68
83
  - - ">="