mixlib-shellout 3.0.7-universal-mingw32 → 3.1.4-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: 186751ae841fbb1870c136daba95716c5d0a8bbe4c4809e6ea72b8c2c6775159
4
- data.tar.gz: 1d0ba8b3836b296a9c4ad3382f4e2cc4031e855d7258ac48eb1a1febfb70f1dc
3
+ metadata.gz: 15cf083a72ce549add81eded313d884cd178385d8fe28c5e3d7d93b40a728b21
4
+ data.tar.gz: 619c1ffb3a1c8e78215c97acbf850e5908106e187b4cabc42b0132a4d94a86b7
5
5
  SHA512:
6
- metadata.gz: 156a332c90e03429eeaef5c4bda0c79f311d774846b8a4baf38a6ed8a8f801e139349862e37471d85dc8a4d5e5bcb9e45dea76cac251639d10eaeac5adea5c91
7
- data.tar.gz: 37d380bf516a9c4f703094d35eb2aea69cde10fec676ed0d9eb80a2b82c20057205781d57d02b74165a9ddffaea36025af39ae609250738da6e9aaaabb05dc8b
6
+ metadata.gz: 0c973fdde62a84ab9a62a37f66ec022aed6ca32011e8855e7d9d6a54e4970ded0d59537dd147c3b830428745dfa60ac546edc63cd99f5f2dc6e8cf565a592cba
7
+ data.tar.gz: 9771450ddf8fca070cb8013d623e605fb35476a2472d7d2ac1a5b8ed6e6cd00b19b4c13b284e5f6d435c901bfbed5f8f1952076131966196b1484f6279706ad5
@@ -16,10 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "etc"
20
- require "tmpdir"
19
+ require "etc" unless defined?(Etc)
20
+ require "tmpdir" unless defined?(Dir.mktmpdir)
21
21
  require "fcntl"
22
- require "mixlib/shellout/exceptions"
22
+ require_relative "shellout/exceptions"
23
23
 
24
24
  module Mixlib
25
25
 
@@ -29,10 +29,10 @@ module Mixlib
29
29
  DEFAULT_READ_TIMEOUT = 600
30
30
 
31
31
  if RUBY_PLATFORM =~ /mswin|mingw32|windows/
32
- require "mixlib/shellout/windows"
32
+ require_relative "shellout/windows"
33
33
  include ShellOut::Windows
34
34
  else
35
- require "mixlib/shellout/unix"
35
+ require_relative "shellout/unix"
36
36
  include ShellOut::Unix
37
37
  end
38
38
 
@@ -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
@@ -122,7 +122,7 @@ module Mixlib
122
122
  # === Options:
123
123
  # If the last argument is a Hash, it is removed from the list of args passed
124
124
  # to exec and used as an options hash. The following options are available:
125
- # * +user+: the user the commmand should run as. if an integer is given, it is
125
+ # * +user+: the user the command should run as. if an integer is given, it is
126
126
  # used as a uid. A string is treated as a username and resolved to a uid
127
127
  # with Etc.getpwnam
128
128
  # * +group+: the group the command should run as. works similarly to +user+
@@ -0,0 +1,197 @@
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" unless defined?(ChefUtils)
20
+ require "chef-utils/dsl/default_paths"
21
+ require "chef-utils/internal"
22
+
23
+ module Mixlib
24
+ class ShellOut
25
+ module Helper
26
+ include ChefUtils::Internal
27
+ include ChefUtils::DSL::DefaultPaths
28
+
29
+ #
30
+ # These APIs are considered public for use in ohai and chef (by cookbooks and plugins, etc)
31
+ # but are considered private/experimental for now for the direct users of mixlib-shellout.
32
+ #
33
+ # You can see an example of how to handle the "dependency injection" in the rspec unit test.
34
+ # That backend API is left deliberately undocumented for now and may not follow SemVer and may
35
+ # break at any time (at least for the rest of 2020).
36
+ #
37
+
38
+ def shell_out(*args, **options)
39
+ options = options.dup
40
+ options = __maybe_add_timeout(self, options)
41
+ if options.empty?
42
+ shell_out_compacted(*__clean_array(*args))
43
+ else
44
+ shell_out_compacted(*__clean_array(*args), **options)
45
+ end
46
+ end
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
+ private
59
+
60
+ # helper sugar for resources that support passing timeouts to shell_out
61
+ #
62
+ # module method to not pollute namespaces, but that means we need self injected as an arg
63
+ # @api private
64
+ def __maybe_add_timeout(obj, options)
65
+ options = options.dup
66
+ # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here
67
+ default_val = 900
68
+ return options if options.key?(:timeout)
69
+
70
+ # FIXME: need to nuke descendent tracker out of Chef::Provider so we can just define that class here without requiring the
71
+ # world, and then just use symbol lookup
72
+ if obj.class.ancestors.map(&:name).include?("Chef::Provider") && obj.respond_to?(:new_resource) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout)
73
+ options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : default_val
74
+ end
75
+ options
76
+ end
77
+
78
+ # helper function to mangle options when `default_env` is true
79
+ #
80
+ # @api private
81
+ def __apply_default_env(options)
82
+ options = options.dup
83
+ default_env = options.delete(:default_env)
84
+ default_env = true if default_env.nil?
85
+ if default_env
86
+ env_key = options.key?(:env) ? :env : :environment
87
+ options[env_key] = {
88
+ "LC_ALL" => __config[:internal_locale],
89
+ "LANGUAGE" => __config[:internal_locale],
90
+ "LANG" => __config[:internal_locale],
91
+ __env_path_name => default_paths,
92
+ }.update(options[env_key] || {})
93
+ end
94
+ options
95
+ end
96
+
97
+ # The shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
98
+ # in rspec tests. They should always be used in rspec tests instead of shell_out to allow
99
+ # for less brittle rspec tests.
100
+ #
101
+ # This expectation:
102
+ #
103
+ # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
104
+ #
105
+ # Is met by many different possible calling conventions that mean the same thing:
106
+ #
107
+ # provider.shell_out!("foo", [ "bar", nil, "baz"])
108
+ # provider.shell_out!(["foo", nil, "bar" ], ["baz"])
109
+ #
110
+ # Note that when setting `default_env: false` that you should just setup an expectation on
111
+ # :shell_out_compacted for `default_env: false`, rather than the expanded env settings so
112
+ # that the default_env implementation can change without breaking unit tests.
113
+ #
114
+ def shell_out_compacted(*args, **options)
115
+ options = __apply_default_env(options)
116
+ if options.empty?
117
+ __shell_out_command(*args)
118
+ else
119
+ __shell_out_command(*args, **options)
120
+ end
121
+ end
122
+
123
+ def shell_out_compacted!(*args, **options)
124
+ options = __apply_default_env(options)
125
+ cmd = if options.empty?
126
+ __shell_out_command(*args)
127
+ else
128
+ __shell_out_command(*args, **options)
129
+ end
130
+ cmd.error!
131
+ cmd
132
+ end
133
+
134
+ # Helper for subclasses to reject nil out of an array. It allows using the array form of
135
+ # shell_out (which avoids the need to surround arguments with quote marks to deal with shells).
136
+ #
137
+ # @param args [String] variable number of string arguments
138
+ # @return [Array] array of strings with nil and null string rejection
139
+ #
140
+ def __clean_array(*args)
141
+ args.flatten.compact.map(&:to_s)
142
+ end
143
+
144
+ def __shell_out_command(*args, **options)
145
+ if __transport_connection
146
+ FakeShellOut.new(args, options, __transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
147
+ else
148
+ cmd = if options.empty?
149
+ Mixlib::ShellOut.new(*args)
150
+ else
151
+ Mixlib::ShellOut.new(*args, **options)
152
+ end
153
+ cmd.live_stream ||= __io_for_live_stream
154
+ cmd.run_command
155
+ cmd
156
+ end
157
+ end
158
+
159
+ def __io_for_live_stream
160
+ if STDOUT.tty? && !__config[:daemon] && __log.debug?
161
+ STDOUT
162
+ else
163
+ nil
164
+ end
165
+ end
166
+
167
+ def __env_path_name
168
+ if ChefUtils.windows?
169
+ "Path"
170
+ else
171
+ "PATH"
172
+ end
173
+ end
174
+
175
+ class FakeShellOut
176
+ attr_reader :stdout, :stderr, :exitstatus, :status
177
+
178
+ def initialize(args, options, result)
179
+ @args = args
180
+ @options = options
181
+ @stdout = result.stdout
182
+ @stderr = result.stderr
183
+ @exitstatus = result.exit_status
184
+ @status = OpenStruct.new(success?: ( exitstatus == 0 ))
185
+ end
186
+
187
+ def error?
188
+ exitstatus != 0
189
+ end
190
+
191
+ def error!
192
+ raise Mixlib::ShellOut::ShellCommandFailed, "Unexpected exit status of #{exitstatus} running #{@args}" if error?
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.0.7".freeze
3
+ VERSION = "3.1.4".freeze
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@
19
19
  #
20
20
 
21
21
  require "win32/process"
22
- require "mixlib/shellout/windows/core_ext"
22
+ require_relative "windows/core_ext"
23
23
 
24
24
  module Mixlib
25
25
  class ShellOut
@@ -208,7 +208,7 @@ module Mixlib
208
208
  # 4. if the argument must be quoted by #1 and terminates in a sequence of backslashes then all the backlashes must themselves
209
209
  # be backslash excaped (double the backslashes).
210
210
  # 5. if an interior quote that must be escaped by #2 has a sequence of backslashes before it then all the backslashes must
211
- # themselves be backslash excaped along with the backslash ecape of the interior quote (double plus one backslashes).
211
+ # themselves be backslash excaped along with the backslash escape of the interior quote (double plus one backslashes).
212
212
  #
213
213
  # And to restate. We are constructing a string which will be parsed by the windows parser into arguments, and we want those
214
214
  # arguments to match the *args array we are passed here. So call the windows parser operation A then we need to apply A^-1 to
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.7
4
+ version: 3.1.4
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-07-30 00:00:00.000000000 Z
11
+ date: 2020-08-13 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
  - - ">="