summaryrefslogtreecommitdiff
path: root/lib/chef/provider/dsc_resource.rb
diff options
context:
space:
mode:
authorGregory Batye <gbatye@fb.com>2017-02-15 10:41:35 -0800
committerGregory Batye <gbatye@fb.com>2017-02-15 10:41:35 -0800
commitc0f2f0e22d6bd8c14e39dc8950a751fccaa30910 (patch)
tree82abcf214c0d9cb9e9aa22ca10279624a4ff09bf /lib/chef/provider/dsc_resource.rb
parente8b452c2e9cdfadebe22e1ed2d6cb94b2d4f5a0a (diff)
parentac07b819652edb10b0421c12c16cce13e6e70f23 (diff)
downloadchef-c0f2f0e22d6bd8c14e39dc8950a751fccaa30910.tar.gz
Merge remote-tracking branch 'chef/master' into fix_osx_profile
Diffstat (limited to 'lib/chef/provider/dsc_resource.rb')
-rw-r--r--lib/chef/provider/dsc_resource.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb
index 0f25065925..026d2ef104 100644
--- a/lib/chef/provider/dsc_resource.rb
+++ b/lib/chef/provider/dsc_resource.rb
@@ -29,6 +29,7 @@ class Chef
super
@new_resource = new_resource
@module_name = new_resource.module_name
+ @module_version = new_resource.module_version
@reboot_resource = nil
end
@@ -65,6 +66,13 @@ class Chef
a.whyrun err + ["Assuming a previous resource sets the RefreshMode."]
a.block_action!
end
+ requirements.assert(:run) do |a|
+ a.assertion { module_usage_valid? }
+ err = ["module_name must be supplied along with module_version."]
+ a.failure_message Chef::Exceptions::DSCModuleNameMissing,
+ err
+ a.block_action!
+ end
end
protected
@@ -92,6 +100,10 @@ class Chef
Chef::Platform.supports_refresh_mode_enabled?(node)
end
+ def module_usage_valid?
+ !(!@module_name && @module_version)
+ end
+
def generate_description
@converge_description
end
@@ -148,10 +160,14 @@ class Chef
end
end
+ def module_info_object
+ @module_version.nil? ? module_name : "@{ModuleName='#{module_name}';ModuleVersion='#{@module_version}'}"
+ end
+
def invoke_resource(method, output_format = :object)
properties = translate_type(@new_resource.properties)
switches = "-Method #{method} -Name #{@new_resource.resource}"\
- " -Property #{properties} -Module #{module_name} -Verbose"
+ " -Property #{properties} -Module #{module_info_object} -Verbose"
cmdlet = Chef::Util::Powershell::Cmdlet.new(
node,
"Invoke-DscResource #{switches}",