diff --git a/Set-SslSecurity.ps1 b/Set-SslSecurity.ps1 index 70c569b..ca7a818 100644 --- a/Set-SslSecurity.ps1 +++ b/Set-SslSecurity.ps1 @@ -120,7 +120,6 @@ process { Write-Host "Nexus is ready!" Invoke-Choco source remove --name="'ChocolateyInternal'" - $RepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json" # Build Credential Object, Connect to Nexus $securePw = (Get-Content 'C:\programdata\sonatype-work\nexus3\admin.password') | ConvertTo-SecureString -AsPlainText -Force @@ -156,34 +155,39 @@ process { Password = ($NexusPw | ConvertTo-SecureString -AsPlainText -Force) FirstName = 'Choco' LastName = 'User' - EmailAddress = 'chocouser@foo.com' + EmailAddress = 'chocouser@example.com' Status = 'Active' Roles = 'chocorole' } New-NexusUser @UserParams } - $ChocoArgs = @( - 'source', - 'add', - "--name='ChocolateyInternal'", - "--source='$RepositoryUrl'", - '--priority=1', - "--user='chocouser'", - "--password='$NexusPw'" - ) - & Invoke-Choco @ChocoArgs - - # Update Repository API key - $chocoArgs = @('apikey', "--source='$RepositoryUrl'", "--api-key='$NuGetApiKey'") - & Invoke-Choco @chocoArgs - - # Reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN - Remove-NexusRepositoryFolder -RepositoryName ChocolateyInternal -Name v3 + # Update all sources with credentials and the new path + foreach ($Repository in Get-NexusRepository -Format nuget | Where-Object Type -eq 'hosted') { + $RepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/$($Repository.Name)/index.json" + + $ChocoArgs = @( + 'source', + 'add', + "--name='$($Repository.Name)'", + "--source='$RepositoryUrl'", + '--priority=1', + "--user='chocouser'", + "--password='$NexusPw'" + ) + & Invoke-Choco @ChocoArgs + + # Update Repository API key + $chocoArgs = @('apikey', "--source='$RepositoryUrl'", "--api-key='$NuGetApiKey'") + & Invoke-Choco @chocoArgs + + # Reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN + Remove-NexusRepositoryFolder -RepositoryName $Repository.Name -Name v3 + } Update-Clixml -Properties @{ NexusUri = "https://$($SubjectWithoutCn):8443" - NexusRepo = $RepositoryUrl + NexusRepo = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json" ChocoUserPassword = $NexusPw } diff --git a/Start-C4bNexusSetup.ps1 b/Start-C4bNexusSetup.ps1 index cc2657e..a8249d0 100644 --- a/Start-C4bNexusSetup.ps1 +++ b/Start-C4bNexusSetup.ps1 @@ -84,7 +84,11 @@ process { # Add ChocolateyInternal as a source repository Invoke-Choco source add -n 'ChocolateyInternal' -s "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --priority 1 - #Remove Local Chocolatey Setup Source + # Add ChocolateyTest as a source repository, to enable authenticated pushing + Invoke-Choco source add -n 'ChocolateyTest' -s "$((Get-NexusRepository -Name 'ChocolateyTest').url)/index.json" + Invoke-Choco source disable -n 'ChocolateyTest' + + # Remove Local Chocolatey Setup Source $chocoArgs = @('source', 'remove', '--name="LocalChocolateySetup"') & Invoke-Choco @chocoArgs diff --git a/scripts/ClientSetup.ps1 b/scripts/ClientSetup.ps1 index 9b12a73..2ce2585 100644 --- a/scripts/ClientSetup.ps1 +++ b/scripts/ClientSetup.ps1 @@ -84,12 +84,12 @@ if ($Credential) { # Find the latest version of Chocolatey, if a version was not specified $NupkgUrl = if (-not $ChocolateyVersion) { - $QueryUrl = ($RepositoryUrl.TrimEnd('/index.json'), "v3/registration/Chocolatey/index.json") -join '/' + $QueryUrl = (($RepositoryUrl -replace '/index\.json$'), "v3/registration/Chocolatey/index.json") -join '/' $Result = $webClient.DownloadString($QueryUrl) | ConvertFrom-Json $Result.items.items[-1].packageContent } else { # Otherwise, assume the URL - "$($RepositoryUrl.TrimEnd('/index.json'))/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg" + "$($RepositoryUrl -replace '/index\.json$')/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg" } # Download the NUPKG