class Chef::Resource::PowershellPackageSource
Public Instance Methods
build_package_source_command(cmdlet_type, new_resource)
click to toggle source
# File lib/chef/resource/powershell_package_source.rb, line 286 def build_package_source_command(cmdlet_type, new_resource) if new_resource.user && new_resource.password cmd = "$user = '#{new_resource.user}';" cmd << "[securestring]$secure_password = Convertto-SecureString -String '#{new_resource.password}' -AsPlainText -Force;" cmd << "$Credentials = New-Object System.Management.Automation.PSCredential -Argumentlist ($user, $secure_password);" cmd << "#{cmdlet_type}-PackageSource -Name '#{new_resource.source_name}'" cmd << " -Location '#{new_resource.source_location}'" if new_resource.source_location cmd << " -Trusted" if new_resource.trusted cmd << " -ProviderName '#{new_resource.provider_name}'" if new_resource.provider_name cmd << " -Credential $credentials" cmd << " | Out-Null" cmd else cmd = "#{cmdlet_type}-PackageSource -Name '#{new_resource.source_name}'" cmd << " -NewName '#{new_resource.new_name}'" if new_resource.new_name cmd << " -Location '#{new_resource.source_location}'" if new_resource.source_location cmd << " -Trusted" if new_resource.trusted cmd << " -ProviderName '#{new_resource.provider_name}'" if new_resource.provider_name cmd << " | Out-Null" cmd end end
build_ps_repository_command(cmdlet_type, new_resource)
click to toggle source
# File lib/chef/resource/powershell_package_source.rb, line 256 def build_ps_repository_command(cmdlet_type, new_resource) if new_resource.trusted == true install_policy = "Trusted" else install_policy = "Untrusted" end if new_resource.user && new_resource.password cmd = "$user = '#{new_resource.user}';" cmd << "[securestring]$secure_password = Convertto-SecureString -String '#{new_resource.password}' -AsPlainText -Force;" cmd << "$Credentials = New-Object System.Management.Automation.PSCredential -Argumentlist ($user, $secure_password);" cmd << "#{cmdlet_type}-PSRepository -Name '#{new_resource.source_name}'" cmd << " -SourceLocation '#{new_resource.source_location}'" if new_resource.source_location cmd << " -InstallationPolicy '#{install_policy}'" cmd << " -PublishLocation '#{new_resource.publish_location}'" if new_resource.publish_location cmd << " -ScriptSourceLocation '#{new_resource.script_source_location}'" if new_resource.script_source_location cmd << " -ScriptPublishLocation '#{new_resource.script_publish_location}'" if new_resource.script_publish_location cmd << " -Credential $Credentials" cmd << " | Out-Null" else cmd = "#{cmdlet_type}-PSRepository -Name '#{new_resource.source_name}'" cmd << " -SourceLocation '#{new_resource.source_location}'" if new_resource.source_location cmd << " -InstallationPolicy '#{install_policy}'" cmd << " -PublishLocation '#{new_resource.publish_location}'" if new_resource.publish_location cmd << " -ScriptSourceLocation '#{new_resource.script_source_location}'" if new_resource.script_source_location cmd << " -ScriptPublishLocation '#{new_resource.script_publish_location}'" if new_resource.script_publish_location cmd << " | Out-Null" end cmd end
get_package_source_details()
click to toggle source
# File lib/chef/resource/powershell_package_source.rb, line 240 def get_package_source_details powershell_exec! <<~EOH $package_details = Get-PackageSource -Name '#{new_resource.source_name}' -ErrorAction SilentlyContinue if ($package_details.ProviderName -match "PowerShellGet"){ return "PSRepository" } elseif ($package_details.ProviderName ) { return "PackageSource" } elseif ($null -eq $package_details) { return "Unregistered" } EOH end