53 lines
1.5 KiB
PowerShell
53 lines
1.5 KiB
PowerShell
function Update-FeedAuthentication {
|
|
<#
|
|
.SYNOPSIS
|
|
Update feed authentication for choco feeds.
|
|
|
|
.DESCRIPTION
|
|
Updates the user authentication stored in choco for a given feed.
|
|
|
|
.PARAMETER Username
|
|
[string] The username to use for all sources
|
|
|
|
.PARAMETER Password
|
|
[string] Plain text value password
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$Username = "AlkamiSDKSubscriber",
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Password
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName)
|
|
|
|
$chocoSources = (Get-ChocolateySources)
|
|
foreach($chocoSource in $chocoSources) {
|
|
if($chocoSource.isSDK) {
|
|
$name = $chocoSource.Name
|
|
$source = $chocoSource.Source
|
|
$displayPassword = $password.Substring(0,4)
|
|
|
|
Write-Host "$logLead : Resetting feed with provided information for $name [$source]"
|
|
|
|
Write-Verbose "$logLead : choco source remove -n=`"$name`""
|
|
choco source remove -n="$name"
|
|
|
|
Write-Verbose "$logLead : choco source add -n=`"$name`" -s=`"$source`" -u=`"$Username`" -p=`"$displayPassword`""
|
|
choco source add -n="$name" -s="$source" -u="$Username" -p="$Password"
|
|
|
|
Write-Verbose "$logLead : added back $name"
|
|
$validationCheckResponses = choco list -s $source --page-size 1 --page 0
|
|
|
|
## Using 401 as the match for: The remote server returned an error: (401) Unauthorized.
|
|
if (!!($validationCheckResponses -match '401')) {
|
|
Write-Error "$logLead : The username and password provided returned an Unauthorized Failure for $name [$source]"
|
|
} else {
|
|
Write-Verbose "$logLead : successfully tested $name"
|
|
}
|
|
}
|
|
}
|
|
}
|