chef 16.7.61-universal-mingw32 → 16.9.20-universal-mingw32

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.
Files changed (122) 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/distro/ruby_bin_folder/AMD64/Chef.PowerShell.Wrapper.dll +0 -0
  6. data/distro/ruby_bin_folder/AMD64/Chef.PowerShell.dll +0 -0
  7. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.PowerShell.Wrapper.Core.dll +0 -0
  8. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.dll +0 -0
  9. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.pdb +0 -0
  10. data/distro/ruby_bin_folder/x86/Chef.PowerShell.dll +0 -0
  11. data/distro/ruby_bin_folder/x86/Chef.Powershell.Wrapper.dll +0 -0
  12. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.PowerShell.Wrapper.Core.dll +0 -0
  13. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.dll +0 -0
  14. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.pdb +0 -0
  15. data/lib/chef/application/base.rb +1 -1
  16. data/lib/chef/client.rb +3 -0
  17. data/lib/chef/compliance/default_attributes.rb +93 -0
  18. data/lib/chef/compliance/fetcher/automate.rb +69 -0
  19. data/lib/chef/compliance/fetcher/chef_server.rb +134 -0
  20. data/lib/chef/compliance/reporter/automate.rb +201 -0
  21. data/lib/chef/compliance/reporter/chef_server_automate.rb +94 -0
  22. data/lib/chef/compliance/reporter/compliance_enforcer.rb +20 -0
  23. data/lib/chef/compliance/reporter/json_file.rb +19 -0
  24. data/lib/chef/compliance/runner.rb +262 -0
  25. data/lib/chef/cookbook_manifest.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +1 -1
  27. data/lib/chef/exceptions.rb +4 -0
  28. data/lib/chef/http/ssl_policies.rb +33 -14
  29. data/lib/chef/knife/bootstrap/train_connector.rb +1 -1
  30. data/lib/chef/knife/core/formatting_options.rb +49 -0
  31. data/lib/chef/knife/core/node_presenter.rb +0 -25
  32. data/lib/chef/knife/core/status_presenter.rb +1 -26
  33. data/lib/chef/knife/core/ui.rb +4 -1
  34. data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -1
  35. data/lib/chef/knife/node_show.rb +2 -1
  36. data/lib/chef/knife/search.rb +2 -1
  37. data/lib/chef/knife/ssh.rb +3 -1
  38. data/lib/chef/knife/status.rb +8 -11
  39. data/lib/chef/mixin/powershell_exec.rb +3 -1
  40. data/lib/chef/platform/query_helpers.rb +4 -4
  41. data/lib/chef/policy_builder/policyfile.rb +1 -1
  42. data/lib/chef/powershell.rb +2 -0
  43. data/lib/chef/provider/dsc_resource.rb +12 -24
  44. data/lib/chef/provider/dsc_script.rb +16 -20
  45. data/lib/chef/provider/git.rb +5 -5
  46. data/lib/chef/provider/package.rb +53 -19
  47. data/lib/chef/provider/package/dnf.rb +39 -12
  48. data/lib/chef/provider/package/dnf/dnf_helper.py +18 -5
  49. data/lib/chef/provider/package/dnf/python_helper.rb +6 -6
  50. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  51. data/lib/chef/provider/yum_repository.rb +2 -2
  52. data/lib/chef/resource/chef_client_config.rb +1 -1
  53. data/lib/chef/resource/chef_gem.rb +2 -2
  54. data/lib/chef/resource/cron/cron_d.rb +1 -0
  55. data/lib/chef/resource/dsc_script.rb +8 -1
  56. data/lib/chef/resource/file.rb +1 -1
  57. data/lib/chef/resource/gem_package.rb +2 -2
  58. data/lib/chef/resource/homebrew_cask.rb +3 -3
  59. data/lib/chef/resource/hostname.rb +3 -3
  60. data/lib/chef/resource/http_request.rb +1 -1
  61. data/lib/chef/resource/locale.rb +1 -1
  62. data/lib/chef/resource/mdadm.rb +2 -2
  63. data/lib/chef/resource/osx_profile.rb +7 -7
  64. data/lib/chef/resource/remote_directory.rb +1 -1
  65. data/lib/chef/resource/ruby.rb +1 -5
  66. data/lib/chef/resource/ruby_block.rb +1 -1
  67. data/lib/chef/resource/template.rb +2 -2
  68. data/lib/chef/resource/user/windows_user.rb +5 -0
  69. data/lib/chef/resource/windows_certificate.rb +9 -13
  70. data/lib/chef/resource/yum_repository.rb +5 -0
  71. data/lib/chef/resource_collection/resource_set.rb +1 -1
  72. data/lib/chef/util/dsc/configuration_generator.rb +52 -11
  73. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -4
  74. data/lib/chef/util/dsc/local_configuration_manager.rb +17 -14
  75. data/lib/chef/util/dsc/resource_store.rb +5 -11
  76. data/lib/chef/version.rb +1 -1
  77. data/lib/chef/win32/api/file.rb +4 -0
  78. data/spec/data/rubygems.org/latest_specs.4.8.gz +0 -0
  79. data/spec/data/rubygems.org/nonexistent_gem +0 -0
  80. data/spec/data/rubygems.org/sexp_processor +0 -0
  81. data/spec/data/rubygems.org/sexp_processor-4.15.1.gemspec.rz +0 -0
  82. data/spec/data/ssl/binary/chef-rspec-der.cert +0 -0
  83. data/spec/data/ssl/binary/chef-rspec-der.key +0 -0
  84. data/spec/functional/resource/dnf_package_spec.rb +319 -16
  85. data/spec/functional/resource/dsc_script_spec.rb +3 -6
  86. data/spec/functional/resource/windows_certificate_spec.rb +204 -384
  87. data/spec/integration/client/client_spec.rb +2 -1
  88. data/spec/integration/compliance/compliance_spec.rb +81 -0
  89. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -0
  90. data/spec/spec_helper.rb +1 -1
  91. data/spec/unit/client_spec.rb +1 -0
  92. data/spec/unit/compliance/fetcher/automate_spec.rb +134 -0
  93. data/spec/unit/compliance/fetcher/chef_server_spec.rb +93 -0
  94. data/spec/unit/compliance/reporter/automate_spec.rb +427 -0
  95. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +177 -0
  96. data/spec/unit/compliance/reporter/compliance_enforcer_spec.rb +48 -0
  97. data/spec/unit/compliance/runner_spec.rb +167 -0
  98. data/spec/unit/http/ssl_policies_spec.rb +107 -68
  99. data/spec/unit/knife/bootstrap_spec.rb +5 -17
  100. data/spec/unit/knife/core/node_editor_spec.rb +1 -1
  101. data/spec/unit/knife/core/status_presenter_spec.rb +54 -0
  102. data/spec/unit/mixin/openssl_helper_spec.rb +0 -7
  103. data/spec/unit/mixin/powershell_exec_spec.rb +1 -1
  104. data/spec/unit/platform/query_helpers_spec.rb +11 -12
  105. data/spec/unit/provider/dsc_resource_spec.rb +10 -27
  106. data/spec/unit/provider/dsc_script_spec.rb +1 -1
  107. data/spec/unit/provider/mount/windows_spec.rb +1 -0
  108. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  109. data/spec/unit/provider/package/rubygems_spec.rb +39 -7
  110. data/spec/unit/provider/systemd_unit_spec.rb +1 -1
  111. data/spec/unit/resource/user/windows_user_spec.rb +36 -0
  112. data/spec/unit/resource/windows_certificate_spec.rb +12 -0
  113. data/spec/unit/util/dsc/configuration_generator_spec.rb +79 -0
  114. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +27 -35
  115. metadata +55 -18
  116. data/lib/chef/util/powershell/cmdlet.rb +0 -169
  117. data/lib/chef/util/powershell/cmdlet_result.rb +0 -61
  118. data/spec/data/trusted_certs_empty/.gitkeep +0 -0
  119. data/spec/data/trusted_certs_empty/README.md +0 -1
  120. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -111
  121. data/spec/scripts/ssl-serve.rb +0 -47
  122. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  provides :http_request
28
28
 
29
- description "Use the **http_request** resource to send an HTTP request (GET, PUT, POST, DELETE, HEAD, or OPTIONS) with an arbitrary message. This resource is often useful when custom callbacks are necessary."
29
+ description "Use the **http_request** resource to send an HTTP request (`GET`, `PUT`, `POST`, `DELETE`, `HEAD`, or `OPTIONS`) with an arbitrary message. This resource is often useful when custom callbacks are necessary."
30
30
 
31
31
  default_action :get
32
32
  allowed_actions :get, :patch, :put, :post, :delete, :head, :options
@@ -125,7 +125,7 @@ class Chef
125
125
  # @raise [Mixlib::ShellOut::ShellCommandFailed] not a supported language or locale
126
126
  #
127
127
  def generate_locales
128
- shell_out!("locale-gen #{unavailable_locales.join(" ")}")
128
+ shell_out!("locale-gen #{unavailable_locales.join(" ")}", timeout: 1800)
129
129
  end
130
130
 
131
131
  # Sets the system locale for the current computer.
@@ -36,7 +36,7 @@ class Chef
36
36
 
37
37
  property :chunk, Integer,
38
38
  default: 16,
39
- description: "The chunk size. This property should not be used for a RAID 1 mirrored pair (i.e. when the level property is set to 1)."
39
+ description: "The chunk size. This property should not be used for a RAID 1 mirrored pair (i.e. when the `level` property is set to `1`)."
40
40
 
41
41
  property :devices, Array,
42
42
  default: lazy { [] },
@@ -63,7 +63,7 @@ class Chef
63
63
  description: "An optional property to specify the name of the RAID device if it differs from the resource block's name."
64
64
 
65
65
  property :layout, String,
66
- description: "The RAID5 parity algorithm. Possible values: left-asymmetric (or la), left-symmetric (or ls), right-asymmetric (or ra), or right-symmetric (or rs)."
66
+ description: "The RAID5 parity algorithm. Possible values: `left-asymmetric` (or `la`), `left-symmetric` (or ls), `right-asymmetric` (or `ra`), or `right-symmetric` (or `rs`)."
67
67
 
68
68
  action_class do
69
69
  def load_current_resource
@@ -65,13 +65,13 @@ class Chef
65
65
  {
66
66
  'mcx_preference_settings' => {
67
67
  'idleTime' => 0,
68
- }
69
- }
70
- ]
71
- }
72
- }
73
- }
74
- ]
68
+ },
69
+ },
70
+ ],
71
+ },
72
+ },
73
+ },
74
+ ],
75
75
  }
76
76
 
77
77
  osx_profile 'Install screensaver profile' do
@@ -29,7 +29,7 @@ class Chef
29
29
 
30
30
  provides :remote_directory
31
31
 
32
- description "Use the **remote_directory** resource to incrementally transfer a directory from a cookbook to a node. The director that is copied from the cookbook should be located under COOKBOOK_NAME/files/default/REMOTE_DIRECTORY. The remote_directory resource will obey file specificity."
32
+ description "Use the **remote_directory** resource to incrementally transfer a directory from a cookbook to a node. The directory that is copied from the cookbook should be located under `COOKBOOK_NAME/files/default/REMOTE_DIRECTORY`. The `remote_directory` resource will obey file specificity."
33
33
 
34
34
  default_action :create
35
35
  allowed_actions :create, :create_if_missing, :delete
@@ -25,11 +25,7 @@ class Chef
25
25
 
26
26
  provides :ruby
27
27
 
28
- description "Use the **ruby** resource to execute scripts using the Ruby interpreter. This"\
29
- " resource may also use any of the actions and properties that are available"\
30
- " to the **execute** resource. Commands that are executed with this resource are (by"\
31
- " their nature) not idempotent, as they are typically unique to the environment"\
32
- " in which they are run. Use `not_if` and `only_if` to guard this resource for idempotence."
28
+ description "Use the **ruby** resource to execute scripts using the Ruby interpreter. This resource may also use any of the actions and properties that are available to the **execute** resource. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use `not_if` and `only_if` to guard this resource for idempotence."
33
29
 
34
30
  def initialize(name, run_context = nil)
35
31
  super
@@ -28,7 +28,7 @@ class Chef
28
28
 
29
29
  provides :ruby_block, target_mode: true
30
30
 
31
- description "Use the **ruby_block** resource to execute Ruby code during a #{ChefUtils::Dist::Infra::PRODUCT} run. Ruby code in the ruby_block resource is evaluated with other resources during convergence, whereas Ruby code outside of a ruby_block resource is evaluated before other resources, as the recipe is compiled."
31
+ description "Use the **ruby_block** resource to execute Ruby code during a #{ChefUtils::Dist::Infra::PRODUCT} run. Ruby code in the `ruby_block` resource is evaluated with other resources during convergence, whereas Ruby code outside of a `ruby_block` resource is evaluated before other resources, as the recipe is compiled."
32
32
 
33
33
  default_action :run
34
34
  allowed_actions :create, :run
@@ -169,8 +169,8 @@ class Chef
169
169
  elsif module_name.nil?
170
170
  raise Exceptions::ValidationFailed,
171
171
  "#helpers requires either a module name or inline module code as a block.\n" +
172
- "e.g.: helpers do; helper_code; end;\n" +
173
- "OR: helpers(MyHelpersModule)"
172
+ "e.g.: helpers do; helper_code; end;\n" +
173
+ "OR: helpers(MyHelpersModule)"
174
174
  else
175
175
  raise Exceptions::ValidationFailed,
176
176
  "Argument to #helpers must be a module. You gave #{module_name.inspect} (#{module_name.class})"
@@ -29,6 +29,11 @@ class Chef
29
29
  property :full_name, String,
30
30
  description: "The full name of the user.",
31
31
  introduced: "14.6"
32
+
33
+ # Override the property from the parent class to coerce to integer.
34
+ property :uid, [ String, Integer, NilClass ], # nil for backwards compat
35
+ description: "The numeric user identifier.",
36
+ coerce: proc { |n| n && Integer(n) rescue n }
32
37
  end
33
38
  end
34
39
  end
@@ -69,7 +69,7 @@ class Chef
69
69
  description: "The password to access the source if it is a pfx file."
70
70
 
71
71
  property :private_key_acl, Array,
72
- description: "An array of 'domain\account' entries to be granted read-only access to the certificate's private key. Not idempotent."
72
+ description: "An array of 'domain\\account' entries to be granted read-only access to the certificate's private key. Not idempotent."
73
73
 
74
74
  property :store_name, String,
75
75
  description: "The certificate store to manipulate.",
@@ -87,6 +87,11 @@ class Chef
87
87
  description: "Ensure that sensitive resource data is not logged by the #{ChefUtils::Dist::Infra::CLIENT}.",
88
88
  default: lazy { pfx_password ? true : false }, skip_docs: true
89
89
 
90
+ property :exportable, [TrueClass, FalseClass],
91
+ description: "Ensure that imported pfx certificate is exportable. Please provide 'true' if you want the certificate to be exportable.",
92
+ default: false,
93
+ introduced: "16.8"
94
+
90
95
  action :create do
91
96
  description "Creates or updates a certificate."
92
97
 
@@ -162,8 +167,9 @@ class Chef
162
167
  end
163
168
 
164
169
  def add_pfx_cert
170
+ exportable = new_resource.exportable ? 1 : 0
165
171
  store = ::Win32::Certstore.open(new_resource.store_name)
166
- store.add_pfx(new_resource.source, new_resource.pfx_password)
172
+ store.add_pfx(new_resource.source, new_resource.pfx_password, exportable)
167
173
  end
168
174
 
169
175
  def delete_cert
@@ -303,11 +309,7 @@ class Chef
303
309
  # @raise [OpenSSL::PKCS12::PKCS12Error] When incorrect password is provided for PFX certificate
304
310
  #
305
311
  def fetch_cert_object(ext)
306
- contents = if binary_cert?
307
- ::File.binread(new_resource.source)
308
- else
309
- ::File.read(new_resource.source)
310
- end
312
+ contents = ::File.binread(new_resource.source)
311
313
 
312
314
  case ext
313
315
  when ".pfx"
@@ -324,12 +326,6 @@ class Chef
324
326
  end
325
327
  end
326
328
 
327
- # @return [Boolean] Whether the certificate file is binary encoded or not
328
- #
329
- def binary_cert?
330
- shell_out!("file -b --mime-encoding #{new_resource.source}").stdout.strip == "binary"
331
- end
332
-
333
329
  # Imports the certificate object into cert store
334
330
  #
335
331
  # @param cert_objs [OpenSSL::X509::Certificate] Object containing certificate's attributes
@@ -50,6 +50,11 @@ class Chef
50
50
 
51
51
  # http://linux.die.net/man/5/yum.conf as well as
52
52
  # http://dnf.readthedocs.io/en/latest/conf_ref.html
53
+ property :reposdir, String,
54
+ description: "The directory where the Yum repository files should be stored",
55
+ default: "/etc/yum.repos.d/",
56
+ introduced: "16.9"
57
+
53
58
  property :baseurl, [String, Array],
54
59
  description: "URL to the directory where the Yum repository's `repodata` directory lives. Can be an `http://`, `https://` or a `ftp://` URLs. You can specify multiple URLs in one `baseurl` statement."
55
60
 
@@ -131,7 +131,7 @@ class Chef
131
131
  else
132
132
  raise Chef::Exceptions::InvalidResourceSpecification,
133
133
  "The object `#{query_object.inspect}' is not valid for resource collection lookup. " +
134
- "Use a String like `resource_type[resource_name]' or a Chef::Resource object"
134
+ "Use a String like `resource_type[resource_name]' or a Chef::Resource object"
135
135
  end
136
136
  end
137
137
 
@@ -16,36 +16,34 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../powershell/cmdlet"
19
+ require_relative "../../mixin/powershell_exec"
20
20
 
21
21
  class Chef::Util::DSC
22
22
  class ConfigurationGenerator
23
+ include Chef::Mixin::PowershellExec
24
+
23
25
  def initialize(node, config_directory)
24
26
  @node = node
25
27
  @config_directory = config_directory
26
28
  end
27
29
 
28
- def configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags)
30
+ def configuration_document_from_script_code(code, configuration_flags, imports)
29
31
  Chef::Log.trace("DSC: DSC code:\n '#{code}'")
30
32
  generated_script_path = write_document_generation_script(code, "chef_dsc", imports)
31
33
  begin
32
- configuration_document_from_script_path(generated_script_path, "chef_dsc", configuration_flags, shellout_flags)
34
+ configuration_document_from_script_path(generated_script_path, "chef_dsc", configuration_flags)
33
35
  ensure
34
36
  ::FileUtils.rm(generated_script_path)
35
37
  end
36
38
  end
37
39
 
38
- def configuration_document_from_script_path(script_path, configuration_name, configuration_flags, shellout_flags)
40
+ def configuration_document_from_script_path(script_path, configuration_name, configuration_flags)
39
41
  validate_configuration_name!(configuration_name)
40
42
 
41
- document_generation_cmdlet = Chef::Util::Powershell::Cmdlet.new(
42
- @node,
43
- configuration_document_generation_code(script_path, configuration_name)
44
- )
45
-
46
- merged_configuration_flags = get_merged_configuration_flags!(configuration_flags, configuration_name)
43
+ config_generation_code = configuration_document_generation_code(script_path, configuration_name)
44
+ switches_string = command_switches_string(get_merged_configuration_flags!(configuration_flags, configuration_name))
47
45
 
48
- document_generation_cmdlet.run!(merged_configuration_flags, shellout_flags)
46
+ powershell_exec!("#{config_generation_code} #{switches_string}")
49
47
  configuration_document_location = find_configuration_document(configuration_name)
50
48
 
51
49
  unless configuration_document_location
@@ -59,6 +57,49 @@ class Chef::Util::DSC
59
57
 
60
58
  protected
61
59
 
60
+ def validate_switch_name!(switch_parameter_name)
61
+ unless switch_parameter_name.match?(/\A[A-Za-z]+[_a-zA-Z0-9]*\Z/)
62
+ raise ArgumentError, "`#{switch_parameter_name}` is not a valid PowerShell cmdlet switch parameter name"
63
+ end
64
+ end
65
+
66
+ def escape_parameter_value(parameter_value)
67
+ parameter_value.gsub(/(`|'|"|#)/, '`\1')
68
+ end
69
+
70
+ def escape_string_parameter_value(parameter_value)
71
+ "'#{escape_parameter_value(parameter_value)}'"
72
+ end
73
+
74
+ def command_switches_string(switches)
75
+ command_switches = switches.map do |switch_name, switch_value|
76
+ if switch_name.class != Symbol
77
+ raise ArgumentError, "Invalid type `#{switch_name} `for PowerShell switch '#{switch_name}'. The switch must be specified as a Symbol'"
78
+ end
79
+
80
+ validate_switch_name!(switch_name)
81
+
82
+ switch_argument = ""
83
+ switch_present = true
84
+
85
+ case switch_value
86
+ when Numeric, Float
87
+ switch_argument = switch_value.to_s
88
+ when FalseClass
89
+ switch_present = false
90
+ when TrueClass
91
+ when String
92
+ switch_argument = escape_string_parameter_value(switch_value)
93
+ else
94
+ raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`"
95
+ end
96
+
97
+ switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(" ").strip : ""
98
+ end
99
+
100
+ command_switches.join(" ")
101
+ end
102
+
62
103
  # From PowerShell error help for the Configuration language element:
63
104
  # Standard names may only contain letters (a-z, A-Z), numbers (0-9), and underscore (_).
64
105
  # The name may not be null or empty, and should start with a letter.
@@ -75,15 +75,15 @@ class Chef
75
75
  #
76
76
 
77
77
  def self.parse(lcm_output, test_dsc_configuration)
78
+ lcm_output = String(lcm_output).split("\n")
78
79
  test_dsc_configuration ? test_dsc_parser(lcm_output) : what_if_parser(lcm_output)
79
80
  end
80
81
 
81
82
  def self.test_dsc_parser(lcm_output)
82
- lcm_output ||= ""
83
83
  current_resource = {}
84
84
 
85
85
  resources = []
86
- lcm_output.lines.each do |line|
86
+ lcm_output.each do |line|
87
87
  op_action , op_value = line.strip.split(":")
88
88
  op_action&.strip!
89
89
  case op_action
@@ -107,11 +107,10 @@ class Chef
107
107
  end
108
108
 
109
109
  def self.what_if_parser(lcm_output)
110
- lcm_output ||= ""
111
110
  current_resource = {}
112
111
 
113
112
  resources = []
114
- lcm_output.lines.each do |line|
113
+ lcm_output.each do |line|
115
114
  op_action, op_type, info = parse_line(line)
116
115
 
117
116
  case op_action
@@ -16,25 +16,27 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../powershell/cmdlet"
19
+ require_relative "../../mixin/powershell_exec"
20
20
  require_relative "lcm_output_parser"
21
21
 
22
22
  class Chef::Util::DSC
23
23
  class LocalConfigurationManager
24
+ include Chef::Mixin::PowershellExec
25
+
24
26
  def initialize(node, configuration_path)
25
27
  @node = node
26
28
  @configuration_path = configuration_path
27
29
  clear_execution_time
28
30
  end
29
31
 
30
- def test_configuration(configuration_document, shellout_flags)
31
- status = run_configuration_cmdlet(configuration_document, false, shellout_flags)
32
- log_dsc_exception(status.stderr) unless status.succeeded?
33
- configuration_update_required?(status.return_value)
32
+ def test_configuration(configuration_document)
33
+ status = run_configuration_cmdlet(configuration_document, false)
34
+ log_dsc_exception(status.errors.join("\n")) if status.error?
35
+ configuration_update_required?(status.result)
34
36
  end
35
37
 
36
- def set_configuration(configuration_document, shellout_flags)
37
- run_configuration_cmdlet(configuration_document, true, shellout_flags)
38
+ def set_configuration(configuration_document)
39
+ run_configuration_cmdlet(configuration_document, true)
38
40
  end
39
41
 
40
42
  def last_operation_execution_time_seconds
@@ -45,7 +47,7 @@ class Chef::Util::DSC
45
47
 
46
48
  private
47
49
 
48
- def run_configuration_cmdlet(configuration_document, apply_configuration, shellout_flags)
50
+ def run_configuration_cmdlet(configuration_document, apply_configuration)
49
51
  Chef::Log.trace("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.")
50
52
 
51
53
  start_operation_timing
@@ -53,11 +55,12 @@ class Chef::Util::DSC
53
55
 
54
56
  begin
55
57
  save_configuration_document(configuration_document)
56
- cmdlet = ::Chef::Util::Powershell::Cmdlet.new(@node, lcm_command(apply_configuration))
58
+ cmd = lcm_command(apply_configuration)
59
+ Chef::Log.trace("DSC: Calling DSC Local Config Manager with:\n#{cmd}")
60
+
61
+ status = powershell_exec(cmd)
57
62
  if apply_configuration
58
- status = cmdlet.run!({}, shellout_flags)
59
- else
60
- status = cmdlet.run({}, shellout_flags)
63
+ status.error!
61
64
  end
62
65
  ensure
63
66
  end_operation_timing
@@ -77,7 +80,7 @@ class Chef::Util::DSC
77
80
  ps4_base_command
78
81
  else
79
82
  if ps_version_gte_5?
80
- "#{common_command_prefix} Test-DscConfiguration -path #{@configuration_path} | format-list"
83
+ "#{common_command_prefix} Test-DscConfiguration -path #{@configuration_path} | format-list | Out-String"
81
84
  else
82
85
  ps4_base_command + " -whatif; if (! $?) { exit 1 }"
83
86
  end
@@ -100,7 +103,7 @@ class Chef::Util::DSC
100
103
  end
101
104
 
102
105
  def whatif_not_supported?(dsc_exception_output)
103
- !! (dsc_exception_output.gsub(/[\r\n]+/, "").gsub(/\s+/, " ") =~ /A parameter cannot be found that matches parameter name 'Whatif'/i)
106
+ !! (dsc_exception_output.gsub(/[\n]+/, "").gsub(/\s+/, " ") =~ /A parameter cannot be found that matches parameter name 'Whatif'/i)
104
107
  end
105
108
 
106
109
  def dsc_module_import_failure?(command_output)
@@ -16,14 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../powershell/cmdlet"
20
- require_relative "../powershell/cmdlet_result"
19
+ require_relative "../../mixin/powershell_exec"
21
20
  require_relative "../../exceptions"
22
21
 
23
22
  class Chef
24
23
  class Util
25
24
  class DSC
26
25
  class ResourceStore
26
+ include Chef::Mixin::PowershellExec
27
27
 
28
28
  def self.instance
29
29
  @@instance ||= ResourceStore.new.tap do |store|
@@ -83,19 +83,13 @@ class Chef
83
83
 
84
84
  # Returns a list of dsc resources
85
85
  def query_resources
86
- cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, "get-dscresource",
87
- :object)
88
- result = cmdlet.run
89
- result.return_value
86
+ powershell_exec("get-dscresource").result
90
87
  end
91
88
 
92
89
  # Returns a list of dsc resources matching the provided name
93
90
  def query_resource(resource_name)
94
- cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, "get-dscresource #{resource_name}",
95
- :object)
96
- result = cmdlet.run
97
- ret_val = result.return_value
98
- if ret_val.nil?
91
+ ret_val = powershell_exec("get-dscresource #{resource_name}").result
92
+ if ret_val.empty?
99
93
  []
100
94
  elsif ret_val.is_a? Array
101
95
  ret_val
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("16.7.61")
26
+ VERSION = Chef::VersionString.new("16.9.20")
27
27
  end
28
28
 
29
29
  #