chef 16.7.61 → 16.9.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -5
  3. data/README.md +2 -2
  4. data/chef.gemspec +12 -2
  5. data/lib/chef/application/base.rb +1 -1
  6. data/lib/chef/client.rb +3 -0
  7. data/lib/chef/compliance/default_attributes.rb +93 -0
  8. data/lib/chef/compliance/fetcher/automate.rb +69 -0
  9. data/lib/chef/compliance/fetcher/chef_server.rb +134 -0
  10. data/lib/chef/compliance/reporter/automate.rb +201 -0
  11. data/lib/chef/compliance/reporter/chef_server_automate.rb +94 -0
  12. data/lib/chef/compliance/reporter/compliance_enforcer.rb +20 -0
  13. data/lib/chef/compliance/reporter/json_file.rb +19 -0
  14. data/lib/chef/compliance/runner.rb +262 -0
  15. data/lib/chef/cookbook_manifest.rb +1 -0
  16. data/lib/chef/encrypted_data_bag_item/assertions.rb +1 -1
  17. data/lib/chef/exceptions.rb +4 -0
  18. data/lib/chef/http/ssl_policies.rb +33 -14
  19. data/lib/chef/knife/bootstrap/train_connector.rb +1 -1
  20. data/lib/chef/knife/core/formatting_options.rb +49 -0
  21. data/lib/chef/knife/core/node_presenter.rb +0 -25
  22. data/lib/chef/knife/core/status_presenter.rb +1 -26
  23. data/lib/chef/knife/core/ui.rb +4 -1
  24. data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/node_show.rb +2 -1
  26. data/lib/chef/knife/search.rb +2 -1
  27. data/lib/chef/knife/ssh.rb +3 -1
  28. data/lib/chef/knife/status.rb +8 -11
  29. data/lib/chef/mixin/powershell_exec.rb +3 -1
  30. data/lib/chef/platform/query_helpers.rb +4 -4
  31. data/lib/chef/policy_builder/policyfile.rb +1 -1
  32. data/lib/chef/powershell.rb +2 -0
  33. data/lib/chef/provider/dsc_resource.rb +12 -24
  34. data/lib/chef/provider/dsc_script.rb +16 -20
  35. data/lib/chef/provider/git.rb +5 -5
  36. data/lib/chef/provider/package.rb +53 -19
  37. data/lib/chef/provider/package/dnf.rb +39 -12
  38. data/lib/chef/provider/package/dnf/dnf_helper.py +18 -5
  39. data/lib/chef/provider/package/dnf/python_helper.rb +6 -6
  40. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  41. data/lib/chef/provider/yum_repository.rb +2 -2
  42. data/lib/chef/resource/chef_client_config.rb +1 -1
  43. data/lib/chef/resource/chef_gem.rb +2 -2
  44. data/lib/chef/resource/cron/cron_d.rb +1 -0
  45. data/lib/chef/resource/dsc_script.rb +8 -1
  46. data/lib/chef/resource/file.rb +1 -1
  47. data/lib/chef/resource/gem_package.rb +2 -2
  48. data/lib/chef/resource/homebrew_cask.rb +3 -3
  49. data/lib/chef/resource/hostname.rb +3 -3
  50. data/lib/chef/resource/http_request.rb +1 -1
  51. data/lib/chef/resource/locale.rb +1 -1
  52. data/lib/chef/resource/mdadm.rb +2 -2
  53. data/lib/chef/resource/osx_profile.rb +7 -7
  54. data/lib/chef/resource/remote_directory.rb +1 -1
  55. data/lib/chef/resource/ruby.rb +1 -5
  56. data/lib/chef/resource/ruby_block.rb +1 -1
  57. data/lib/chef/resource/template.rb +2 -2
  58. data/lib/chef/resource/user/windows_user.rb +5 -0
  59. data/lib/chef/resource/windows_certificate.rb +9 -13
  60. data/lib/chef/resource/yum_repository.rb +5 -0
  61. data/lib/chef/resource_collection/resource_set.rb +1 -1
  62. data/lib/chef/util/dsc/configuration_generator.rb +52 -11
  63. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -4
  64. data/lib/chef/util/dsc/local_configuration_manager.rb +17 -14
  65. data/lib/chef/util/dsc/resource_store.rb +5 -11
  66. data/lib/chef/version.rb +1 -1
  67. data/lib/chef/win32/api/file.rb +4 -0
  68. data/spec/data/rubygems.org/latest_specs.4.8.gz +0 -0
  69. data/spec/data/rubygems.org/nonexistent_gem +0 -0
  70. data/spec/data/rubygems.org/sexp_processor +0 -0
  71. data/spec/data/rubygems.org/sexp_processor-4.15.1.gemspec.rz +0 -0
  72. data/spec/data/ssl/binary/chef-rspec-der.cert +0 -0
  73. data/spec/data/ssl/binary/chef-rspec-der.key +0 -0
  74. data/spec/functional/resource/dnf_package_spec.rb +319 -16
  75. data/spec/functional/resource/dsc_script_spec.rb +3 -6
  76. data/spec/functional/resource/windows_certificate_spec.rb +204 -384
  77. data/spec/integration/client/client_spec.rb +2 -1
  78. data/spec/integration/compliance/compliance_spec.rb +81 -0
  79. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -0
  80. data/spec/spec_helper.rb +1 -1
  81. data/spec/unit/client_spec.rb +1 -0
  82. data/spec/unit/compliance/fetcher/automate_spec.rb +134 -0
  83. data/spec/unit/compliance/fetcher/chef_server_spec.rb +93 -0
  84. data/spec/unit/compliance/reporter/automate_spec.rb +427 -0
  85. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +177 -0
  86. data/spec/unit/compliance/reporter/compliance_enforcer_spec.rb +48 -0
  87. data/spec/unit/compliance/runner_spec.rb +167 -0
  88. data/spec/unit/http/ssl_policies_spec.rb +107 -68
  89. data/spec/unit/knife/bootstrap_spec.rb +5 -17
  90. data/spec/unit/knife/core/node_editor_spec.rb +1 -1
  91. data/spec/unit/knife/core/status_presenter_spec.rb +54 -0
  92. data/spec/unit/mixin/openssl_helper_spec.rb +0 -7
  93. data/spec/unit/mixin/powershell_exec_spec.rb +1 -1
  94. data/spec/unit/platform/query_helpers_spec.rb +11 -12
  95. data/spec/unit/provider/dsc_resource_spec.rb +10 -27
  96. data/spec/unit/provider/dsc_script_spec.rb +1 -1
  97. data/spec/unit/provider/mount/windows_spec.rb +1 -0
  98. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  99. data/spec/unit/provider/package/rubygems_spec.rb +39 -7
  100. data/spec/unit/provider/systemd_unit_spec.rb +1 -1
  101. data/spec/unit/resource/user/windows_user_spec.rb +36 -0
  102. data/spec/unit/resource/windows_certificate_spec.rb +12 -0
  103. data/spec/unit/util/dsc/configuration_generator_spec.rb +79 -0
  104. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +27 -35
  105. metadata +55 -18
  106. data/lib/chef/util/powershell/cmdlet.rb +0 -169
  107. data/lib/chef/util/powershell/cmdlet_result.rb +0 -61
  108. data/spec/data/trusted_certs_empty/.gitkeep +0 -0
  109. data/spec/data/trusted_certs_empty/README.md +0 -1
  110. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -111
  111. data/spec/scripts/ssl-serve.rb +0 -47
  112. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -285,7 +285,7 @@ class Chef
285
285
  # Train.unpack_target_from_uri only works for complete URIs in
286
286
  # form of proto://[user[:pass]@]host[:port]/
287
287
  # So we'll add the protocol prefix if it's not supplied.
288
- uri_to_check = if URI.regexp.match(uri)
288
+ uri_to_check = if URI::DEFAULT_PARSER.make_regexp.match(uri)
289
289
  uri
290
290
  else
291
291
  "#{default_protocol}://#{uri}"
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Nicolas DUPEUX (<nicolas.dupeux@arkea.com>)
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
+
19
+ class Chef
20
+ class Knife
21
+ module Core
22
+
23
+ # This module may be included into a knife subcommand class to automatically
24
+ # add configuration options used by the StatusPresenter and NodePresenter.
25
+ module FormattingOptions
26
+ # @private
27
+ # Would prefer to do this in a rational way, but can't be done b/c of
28
+ # Mixlib::CLI's design :(
29
+ def self.included(includer)
30
+ includer.class_eval do
31
+ option :medium_output,
32
+ short: "-m",
33
+ long: "--medium",
34
+ boolean: true,
35
+ default: false,
36
+ description: "Include normal attributes in the output"
37
+
38
+ option :long_output,
39
+ short: "-l",
40
+ long: "--long",
41
+ boolean: true,
42
+ default: false,
43
+ description: "Include all attributes in the output"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,31 +23,6 @@ class Chef
23
23
  class Knife
24
24
  module Core
25
25
 
26
- # This module may be included into a knife subcommand class to automatically
27
- # add configuration options used by the NodePresenter
28
- module NodeFormattingOptions
29
- # @private
30
- # Would prefer to do this in a rational way, but can't be done b/c of
31
- # Mixlib::CLI's design :(
32
- def self.included(includer)
33
- includer.class_eval do
34
- option :medium_output,
35
- short: "-m",
36
- long: "--medium",
37
- boolean: true,
38
- default: false,
39
- description: "Include normal attributes in the output"
40
-
41
- option :long_output,
42
- short: "-l",
43
- long: "--long",
44
- boolean: true,
45
- default: false,
46
- description: "Include all attributes in the output"
47
- end
48
- end
49
- end
50
-
51
26
  # A customized presenter for Chef::Node objects. Supports variable-length
52
27
  # output formats for displaying node data
53
28
  class NodePresenter < GenericPresenter
@@ -23,31 +23,6 @@ class Chef
23
23
  class Knife
24
24
  module Core
25
25
 
26
- # This module may be included into a knife subcommand class to automatically
27
- # add configuration options used by the StatusPresenter
28
- module StatusFormattingOptions
29
- # @private
30
- # Would prefer to do this in a rational way, but can't be done b/c of
31
- # Mixlib::CLI's design :(
32
- def self.included(includer)
33
- includer.class_eval do
34
- option :medium_output,
35
- short: "-m",
36
- long: "--medium",
37
- boolean: true,
38
- default: false,
39
- description: "Include normal attributes in the output"
40
-
41
- option :long_output,
42
- short: "-l",
43
- long: "--long",
44
- boolean: true,
45
- default: false,
46
- description: "Include all attributes in the output"
47
- end
48
- end
49
- end
50
-
51
26
  # A customized presenter for Chef::Node objects. Supports variable-length
52
27
  # output formats for displaying node data
53
28
  class StatusPresenter < GenericPresenter
@@ -67,7 +42,7 @@ class Chef
67
42
 
68
43
  result["name"] = node["name"] || node.name
69
44
  result["chef_environment"] = node["chef_environment"]
70
- ip = (node["cloud"] && node["cloud"]["public_ipv4_addrs"].first) || node["ipaddress"]
45
+ ip = (node["cloud"] && node["cloud"]["public_ipv4_addrs"]&.first) || node["ipaddress"]
71
46
  fqdn = (node["cloud"] && node["cloud"]["public_hostname"]) || node["fqdn"]
72
47
  result["ip"] = ip if ip
73
48
  result["fqdn"] = fqdn if fqdn
@@ -64,7 +64,10 @@ class Chef
64
64
  # Creates a new object of class TTY::Prompt
65
65
  # with interrupt as exit so that it can be terminated with status code.
66
66
  def prompt
67
- @prompt ||= TTY::Prompt.new(interrupt: :exit)
67
+ @prompt ||= begin
68
+ require "tty-prompt"
69
+ TTY::Prompt.new(interrupt: :exit)
70
+ end
68
71
  end
69
72
 
70
73
  # pastel.decorate is a lightweight replacement for highline.color
@@ -140,7 +140,7 @@ class Chef
140
140
  end
141
141
 
142
142
  unless trusted_certs_script.empty?
143
- client_rb << %Q{trusted_certs_dir "#{ChefConfig::Config.etc_chef_dir(windows: true)}/trusted_certs"\n}
143
+ client_rb << %Q{trusted_certs_dir "#{ChefConfig::PathHelper.escapepath(ChefConfig::Config.etc_chef_dir(windows: true))}\\\\trusted_certs"\n}
144
144
  end
145
145
 
146
146
  if chef_config[:fips]
@@ -18,13 +18,14 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
21
22
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
22
23
 
23
24
  class Chef
24
25
  class Knife
25
26
  class NodeShow < Knife
26
27
 
27
- include Knife::Core::NodeFormattingOptions
28
+ include Knife::Core::FormattingOptions
28
29
  include Knife::Core::MultiAttributeReturnOption
29
30
 
30
31
  deps do
@@ -18,6 +18,7 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
21
22
 
22
23
  class Chef
23
24
  class Knife
@@ -32,7 +33,7 @@ class Chef
32
33
  require_relative "../search/query"
33
34
  end
34
35
 
35
- include Knife::Core::NodeFormattingOptions
36
+ include Knife::Core::FormattingOptions
36
37
 
37
38
  banner "knife search INDEX QUERY (options)"
38
39
 
@@ -289,7 +289,7 @@ class Chef
289
289
  opts[:port] = port unless port.nil?
290
290
  opts[:logger] = Chef::Log.with_child(subsystem: "net/ssh") if Chef::Log.level == :trace
291
291
  unless config[:host_key_verify]
292
- opts[:verify_host_key] = false
292
+ opts[:verify_host_key] = :never
293
293
  opts[:user_known_hosts_file] = "/dev/null"
294
294
  end
295
295
  if ssh_config[:keepalive]
@@ -385,6 +385,8 @@ class Chef
385
385
  end
386
386
 
387
387
  ch.on_extended_data do |_, _type, data|
388
+ raise ArgumentError if data.eql?("sudo: no tty present and no askpass program specified\n")
389
+
388
390
  stderr += data
389
391
  end
390
392
 
@@ -18,13 +18,13 @@
18
18
 
19
19
  require_relative "../knife"
20
20
  require_relative "core/status_presenter"
21
- require_relative "core/node_presenter"
21
+ require_relative "core/formatting_options"
22
22
  require "chef-utils/dist" unless defined?(ChefUtils::Dist)
23
23
 
24
24
  class Chef
25
25
  class Knife
26
26
  class Status < Knife
27
- include Knife::Core::NodeFormattingOptions
27
+ include Knife::Core::FormattingOptions
28
28
 
29
29
  deps do
30
30
  require_relative "../search/query"
@@ -68,11 +68,11 @@ class Chef
68
68
  append_to_query("chef_environment:#{config[:environment]}") if config[:environment]
69
69
 
70
70
  if config[:hide_by_mins]
71
- hidemins = config[:hide_by_mins].to_i
71
+ hide_by_mins = config[:hide_by_mins].to_i
72
72
  time = Time.now.to_i
73
73
  # AND NOT is not valid lucene syntax, so don't use append_to_query
74
74
  @query << " " unless @query.empty?
75
- @query << "NOT ohai_time:[#{(time - hidemins * 60)} TO #{time}]"
75
+ @query << "NOT ohai_time:[#{(time - hide_by_mins * 60)} TO #{time}]"
76
76
  end
77
77
 
78
78
  @query = @query.empty? ? "*:*" : @query
@@ -84,13 +84,10 @@ class Chef
84
84
  all_nodes << node
85
85
  end
86
86
 
87
- output(all_nodes.sort do |n1, n2|
88
- if config[:sort_reverse] || config[:sort_status_reverse]
89
- (n2["ohai_time"] || 0) <=> (n1["ohai_time"] || 0)
90
- else
91
- (n1["ohai_time"] || 0) <=> (n2["ohai_time"] || 0)
92
- end
93
- end)
87
+ all_nodes.sort_by! { |n| n["ohai_time"] || 0 }
88
+ all_nodes.reverse! if config[:sort_reverse] || config[:sort_status_reverse]
89
+
90
+ output(all_nodes)
94
91
  end
95
92
 
96
93
  end
@@ -23,10 +23,12 @@ require_relative "../pwsh"
23
23
  # powershell_exec is initialized with a string that should be set to the script
24
24
  # to run and also takes an optional interpreter argument which must be either
25
25
  # :powershell (Windows PowerShell which is the default) or :pwsh (PowerShell
26
- # Core). It will return a Chef::PowerShell object that provides 4 methods:
26
+ # Core). It will return a Chef::PowerShell object that provides 5 methods:
27
27
  #
28
28
  # .result - returns a hash representing the results returned by executing the
29
29
  # PowerShell script block
30
+ # .verbose - this is an array of string containing any messages written to the
31
+ # PowerShell verbose stream during execution
30
32
  # .errors - this is an array of string containing any messages written to the
31
33
  # PowerShell error stream during execution
32
34
  # .error? - returns true if there were error messages written to the PowerShell
@@ -58,10 +58,10 @@ class Chef
58
58
  end
59
59
 
60
60
  def dsc_refresh_mode_disabled?(node)
61
- require_relative "../util/powershell/cmdlet"
62
- cmdlet = Chef::Util::Powershell::Cmdlet.new(node, "Get-DscLocalConfigurationManager", :object)
63
- metadata = cmdlet.run!.return_value
64
- metadata["RefreshMode"] == "Disabled"
61
+ require_relative "../powershell"
62
+ exec = Chef::PowerShell.new("Get-DscLocalConfigurationManager")
63
+ exec.error!
64
+ exec.result["RefreshMode"] == "Disabled"
65
65
  end
66
66
 
67
67
  def supported_powershell_version?(node, version_string)
@@ -475,7 +475,7 @@ class Chef
475
475
  end
476
476
 
477
477
  # @api private
478
- # Fetches the CookbookVersion object for the given name and identifer
478
+ # Fetches the CookbookVersion object for the given name and identifier
479
479
  # specified in the lock_data.
480
480
  # TODO: This only implements Chef 11 compatibility mode, which means that
481
481
  # cookbooks are fetched by the "dotted_decimal_identifier": a
@@ -24,6 +24,7 @@ class Chef
24
24
 
25
25
  attr_reader :result
26
26
  attr_reader :errors
27
+ attr_reader :verbose
27
28
 
28
29
  # Run a command under PowerShell via FFI
29
30
  # This implementation requires the managed dll and native wrapper to be in the library search
@@ -72,6 +73,7 @@ class Chef
72
73
  hashed_outcome = Chef::JSONCompat.parse(execution)
73
74
  @result = Chef::JSONCompat.parse(hashed_outcome["result"])
74
75
  @errors = hashed_outcome["errors"]
76
+ @verbose = hashed_outcome["verbose"]
75
77
  end
76
78
  end
77
79
  end
@@ -15,7 +15,8 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
- require_relative "../util/powershell/cmdlet"
18
+ require "timeout" unless defined?(Timeout)
19
+ require_relative "../mixin/powershell_exec"
19
20
  require_relative "../util/dsc/local_configuration_manager"
20
21
  require_relative "../mixin/powershell_type_coercions"
21
22
  require_relative "../util/dsc/resource_store"
@@ -130,27 +131,27 @@ class Chef
130
131
  def test_resource
131
132
  result = invoke_resource(:test)
132
133
  add_dsc_verbose_log(result)
133
- return_dsc_resource_result(result, "InDesiredState")
134
+ result.result["InDesiredState"]
134
135
  end
135
136
 
136
137
  def set_resource
137
138
  result = invoke_resource(:set)
138
139
  add_dsc_verbose_log(result)
139
- create_reboot_resource if return_dsc_resource_result(result, "RebootRequired")
140
- result.return_value
140
+ create_reboot_resource if result.result["RebootRequired"]
141
+ result
141
142
  end
142
143
 
143
144
  def add_dsc_verbose_log(result)
144
145
  # We really want this information from the verbose stream,
145
146
  # however in some versions of WMF, Invoke-DscResource is not correctly
146
147
  # writing to that stream and instead just dumping to stdout
147
- verbose_output = result.stream(:verbose)
148
- verbose_output = result.stdout if verbose_output.empty?
148
+ verbose_output = result.verbose.join("\n")
149
+ verbose_output = result.result if verbose_output.empty?
149
150
 
150
151
  if @converge_description.nil? || @converge_description.empty?
151
152
  @converge_description = verbose_output
152
153
  else
153
- @converge_description << "\n"
154
+ @converge_description << "\n\n"
154
155
  @converge_description << verbose_output
155
156
  end
156
157
  end
@@ -159,26 +160,13 @@ class Chef
159
160
  @module_version.nil? ? module_name : "@{ModuleName='#{module_name}';ModuleVersion='#{@module_version}'}"
160
161
  end
161
162
 
162
- def invoke_resource(method, output_format = :object)
163
+ def invoke_resource(method)
163
164
  properties = translate_type(new_resource.properties)
164
165
  switches = "-Method #{method} -Name #{new_resource.resource}"\
165
166
  " -Property #{properties} -Module #{module_info_object} -Verbose"
166
- cmdlet = Chef::Util::Powershell::Cmdlet.new(
167
- node,
168
- "Invoke-DscResource #{switches}",
169
- output_format
170
- )
171
- cmdlet.run!({}, { timeout: new_resource.timeout })
172
- end
173
-
174
- def return_dsc_resource_result(result, property_name)
175
- if result.return_value.is_a?(Array)
176
- # WMF Feb 2015 Preview
177
- result.return_value[0][property_name]
178
- else
179
- # WMF April 2015 Preview
180
- result.return_value[property_name]
181
- end
167
+ Timeout.timeout(new_resource.timeout) {
168
+ powershell_exec!("Invoke-DscResource #{switches}")
169
+ }
182
170
  end
183
171
 
184
172
  def create_reboot_resource
@@ -16,7 +16,6 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../util/powershell/cmdlet"
20
19
  require_relative "../util/dsc/configuration_generator"
21
20
  require_relative "../util/dsc/local_configuration_manager"
22
21
  require_relative "../util/path_helper"
@@ -32,11 +31,11 @@ class Chef
32
31
  @dsc_resource = dsc_resource
33
32
  @resource_converged = false
34
33
  @operations = {
35
- set: Proc.new do |config_manager, document, shellout_flags|
36
- config_manager.set_configuration(document, shellout_flags)
34
+ set: Proc.new do |config_manager, document|
35
+ config_manager.set_configuration(document)
37
36
  end,
38
- test: Proc.new do |config_manager, document, shellout_flags|
39
- config_manager.test_configuration(document, shellout_flags)
37
+ test: Proc.new do |config_manager, document|
38
+ config_manager.test_configuration(document)
40
39
  end }
41
40
  end
42
41
 
@@ -85,20 +84,23 @@ class Chef
85
84
 
86
85
  config_manager = Chef::Util::DSC::LocalConfigurationManager.new(@run_context.node, config_directory)
87
86
 
88
- shellout_flags = {
89
- cwd: @dsc_resource.cwd,
90
- environment: @dsc_resource.environment,
91
- timeout: @dsc_resource.timeout,
92
- }
87
+ cwd = @dsc_resource.cwd || Dir.pwd
88
+ original_env = ENV.to_hash
93
89
 
94
90
  begin
95
- configuration_document = generate_configuration_document(config_directory, configuration_flags)
96
- @operations[operation].call(config_manager, configuration_document, shellout_flags)
91
+ ENV.update(@dsc_resource.environment) if @dsc_resource.environment
92
+ Dir.chdir(cwd) do
93
+ Timeout.timeout(@dsc_resource.timeout) do
94
+ configuration_document = generate_configuration_document(config_directory, configuration_flags)
95
+ @operations[operation].call(config_manager, configuration_document)
96
+ end
97
+ end
97
98
  rescue Exception => e
98
99
  logger.error("DSC operation failed: #{e.message}")
99
100
  raise e
100
101
  ensure
101
102
  ::FileUtils.rm_rf(config_directory)
103
+ ENV.replace(original_env)
102
104
  end
103
105
  end
104
106
 
@@ -112,20 +114,14 @@ class Chef
112
114
  end
113
115
 
114
116
  def generate_configuration_document(config_directory, configuration_flags)
115
- shellout_flags = {
116
- cwd: @dsc_resource.cwd,
117
- environment: @dsc_resource.environment,
118
- timeout: @dsc_resource.timeout,
119
- }
120
-
121
117
  generator = Chef::Util::DSC::ConfigurationGenerator.new(@run_context.node, config_directory)
122
118
 
123
119
  if @dsc_resource.command
124
- generator.configuration_document_from_script_path(@dsc_resource.command, configuration_name, configuration_flags, shellout_flags)
120
+ generator.configuration_document_from_script_path(@dsc_resource.command, configuration_name, configuration_flags)
125
121
  else
126
122
  # If code is also not provided, we mimic what the other script resources do (execute nothing)
127
123
  logger.warn("Neither code or command were provided for dsc_resource[#{@dsc_resource.name}].") unless @dsc_resource.code
128
- generator.configuration_document_from_script_code(@dsc_resource.code || "", configuration_flags, @dsc_resource.imports, shellout_flags)
124
+ generator.configuration_document_from_script_code(@dsc_resource.code || "", configuration_flags, @dsc_resource.imports)
129
125
  end
130
126
  end
131
127