summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Magnus Rakvåg <tm@intility.no>2018-06-11 10:47:47 +0200
committerTor Magnus Rakvåg <tm@intility.no>2018-06-11 10:47:47 +0200
commit9cbaaa5ee48c8a6a9b77d17751b91fab03163397 (patch)
tree87c5a16036677ad01ff0a81ed9f32850296138e4
parent679ca53aea02e706494874c759635137fe07ea65 (diff)
downloadchef-9cbaaa5ee48c8a6a9b77d17751b91fab03163397.tar.gz
use psrepository cmdlet under the hood for powershellget
Signed-off-by: Tor Magnus Rakvåg <tm@intility.no>
-rw-r--r--lib/chef/resource/powershell_package_source.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/chef/resource/powershell_package_source.rb b/lib/chef/resource/powershell_package_source.rb
index 2cde896144..5d6e7bb07b 100644
--- a/lib/chef/resource/powershell_package_source.rb
+++ b/lib/chef/resource/powershell_package_source.rb
@@ -36,7 +36,7 @@ class Chef
description: "",
default: false
- property :package_management_provider, String,
+ property :provider_name, String,
equal_to: %w{ Programs msi NuGet msu PowerShellGet psl chocolatey },
validation_message: "The following providers are supported: 'Programs', 'msi', 'NuGet', 'msu', 'PowerShellGet', 'psl' or 'chocolatey'",
description: "",
@@ -55,13 +55,19 @@ class Chef
required: false
action :register do
- register_cmd = "Register-PackageSource -Name '#{new_resource.name}' -Location '#{new_resource.url}'"
- register_cmd << " -Trusted" if new_resource.trusted
- register_cmd << " -PackageManagementProvider '#{new_resource.package_management_provider}'"
- register_cmd << " -PublishLocation '#{new_resource.publish_location}'" if new_resource.publish_location
- register_cmd << " -ScriptSourceLocation '#{new_resource.script_source_location}'" if new_resource.script_source_location
- register_cmd << " -ScriptPublishLocation '#{new_resource.script_publish_location}'" if new_resource.script_publish_location
- register_cmd << " -Force -ForceBootstrap"
+ if psrepository_cmdlet_appropriate?
+ register_cmd = "Install-PackageProvider -Name 'NuGet';"
+ register_cmd << " Register-PSRepository -Name '#{new_resource.name}' -SourceLocation '#{new_resource.url}'"
+ register_cmd << " -PublishLocation '#{new_resource.publish_location}'" if new_resource.publish_location
+ register_cmd << " -ScriptSourceLocation '#{new_resource.script_source_location}'" if new_resource.script_source_location
+ register_cmd << " -ScriptPublishLocation '#{new_resource.script_publish_location}'" if new_resource.script_publish_location
+ register_cmd << " -InstallationPolicy Trusted" if new_resource.trusted
+ else
+ register_cmd = "Register-PackageSource -Name '#{new_resource.name}' -Location '#{new_resource.url}'"
+ register_cmd << " -ProviderName '#{new_resource.provider_name}'"
+ register_cmd << " -Force -ForceBootstrap"
+ register_cmd << " -Trusted" if new_resource.trusted
+ end
powershell_script "register package source: #{new_resource.name}" do
code register_cmd
@@ -83,6 +89,10 @@ class Chef
cmd = powershell_out!("(Get-PackageSource -Name '#{new_resource.name}').Name")
cmd.stdout.downcase.strip == new_resource.name.downcase
end
+
+ def psrepository_cmdlet_appropriate?
+ new_resource.provider_name == "PowerShellGet"
+ end
end
end
end