Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PSFramework.NuGet/PSFramework.NuGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'PSFramework.NuGet.psm1'

# Version number of this module.
ModuleVersion = '0.9.0'
ModuleVersion = '0.9.2'

# ID used to uniquely identify this module
GUID = 'ad0f2a25-552f-4dd6-bd8e-5ddced2a5d88'
Expand Down
5 changes: 5 additions & 0 deletions PSFramework.NuGet/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.9.2 (2025-01-17)

+ Fix: Get-PSFRepository - writes error when searching for a specific repository that only exists in one PSGet version
+ Fix: Update-PSFRepository - will update the "Trusted" status of a configured repository, even if the base properties have not yet been configured

## 0.9.0 (2025-01-03)

+ Initial Preview Release
6 changes: 4 additions & 2 deletions PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
}
process {
if ($script:psget.V3 -and $Type -in 'All','V3') {
foreach ($repository in Get-PSResourceRepository -Name $Name) {
foreach ($repository in Get-PSResourceRepository -Name $Name -ErrorAction Ignore) {
if (-not $repository) { continue }
[PSCustomObject]@{
PSTypeName = 'PSFramework.NuGet.Repository'
Name = $repository.Name
Expand All @@ -63,7 +64,8 @@
if (-not $script:psget.v2CanPublish) { $status = 'NoPublish' }
if (-not $script:psget.v2CanInstall) { $status = 'NoInstall' }

foreach ($repository in Get-PSRepository -Name $Name) {
foreach ($repository in Get-PSRepository -Name $Name -ErrorAction Ignore) {
if (-not $repository) { continue }
[PSCustomObject]@{
PSTypeName = 'PSFramework.NuGet.Repository'
Name = $repository.Name
Expand Down
141 changes: 73 additions & 68 deletions PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,88 +54,93 @@
$supportedTypes = 'Any', 'Update', 'All', 'V2', 'V2Preferred', 'V3'

foreach ($configuredRepo in $Configured) {
# Incomplete configurations are ignored (e.g. just storing credentials)
if (-not $configuredRepo.Type -or -not $configuredRepo.Uri) { continue }
# Incomplete configurations are processed in a limited manner, as not enough information is present to create or delete
$isIncomplete = -not $configuredRepo.Type -or -not $configuredRepo.Uri

if ($configuredRepo.Type -notin $supportedTypes) {
if (-not $isIncomplete -and $configuredRepo.Type -notin $supportedTypes) {
Write-PSFMessage -Level Warning -String 'Update-PSFRepository.Error.InvalidType' -StringValues $configuredRepo.Type, ($supportedTypes -join ', ')
continue
}

$matching = $Actual | Where-Object Name -EQ $configuredRepo._Name
$shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present)
# An incomplete configuration can only be used to modify an existing repository, so skip if nothing matches
if ($isIncomplete -and -not $matching) { continue }

$mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred'
if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false }
$mustBeV2 = $configuredRepo.Type -in 'All', 'V2'
$mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred'
if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false }
$mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3'
if (-not $isIncomplete) {
$shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present)

# Case: Should not exist and does not
if (-not $shouldExist -and -not $matching) {
continue
}
$mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred'
if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false }
$mustBeV2 = $configuredRepo.Type -in 'All', 'V2'
$mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred'
if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false }
$mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3'

#region Deletion
foreach ($matchingRepo in $matching) {
if (
# Should exist
$shouldExist -and
(
$matchingRepo.Type -eq 'V2' -and $mayBeV2 -or
$matchingRepo.Type -eq 'V3' -and $mayBeV3
)
) {
# Case: Should not exist and does not
if (-not $shouldExist -and -not $matching) {
continue
}

[PSCustomObject]@{
Type = 'Delete'
Configured = $configuredRepo
Actual = $matchingRepo
Changes = @{ }
#region Deletion
foreach ($matchingRepo in $matching) {
if (
# Should exist
$shouldExist -and
(
$matchingRepo.Type -eq 'V2' -and $mayBeV2 -or
$matchingRepo.Type -eq 'V3' -and $mayBeV3
)
) {
continue
}

[PSCustomObject]@{
Type = 'Delete'
Configured = $configuredRepo
Actual = $matchingRepo
Changes = @{ }
}
}
}
if (-not $shouldExist) { continue }
#endregion Deletion
if (-not $shouldExist) { continue }
#endregion Deletion

#region Creation
# Case: Should exist but does not
if ($shouldExist -and -not $matching) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $null
Changes = @{ }
#region Creation
# Case: Should exist but does not
if ($shouldExist -and -not $matching) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $null
Changes = @{ }
}
continue
}
continue
}

# Case: Must exist on V2 but does not
if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $matching
Changes = @{ }
# Case: Must exist on V2 but does not
if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $matching
Changes = @{ }
}
}
}

# Case: Must exist on V3 but does not
if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $matching
Changes = @{ }
# Case: Must exist on V3 but does not
if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) {
[PSCustomObject]@{
Type = 'Create'
Configured = $configuredRepo
Actual = $matching
Changes = @{ }
}
}

# If there is no matching, existing repository, there is no need to update
if (-not $matching) { continue }
#endregion Creation
}

# If there is no matching, existing repository, there is no need to update
if (-not $matching) { continue }
#endregion Creation

#region Update
foreach ($matchingRepo in $matching) {
$intendedUri = $configuredRepo.Uri
Expand All @@ -147,7 +152,7 @@
if ($null -eq $trusted) { $trusted = $true }

$changes = @{ }
if ($matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri }
if (-not $isIncomplete -and $matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri }
if ($matchingRepo.Trusted -ne $trusted) { $changes.Trusted = $trusted -as [bool] }
if (
$configuredRepo.Priority -and
Expand Down Expand Up @@ -208,10 +213,10 @@
$uri = $Change.Configured.Uri -replace 'v3/index.json$', 'v2'

$param = @{
Name = $Change.Configured._Name
SourceLocation = $uri
Name = $Change.Configured._Name
SourceLocation = $uri
PublishLocation = $uri
ErrorAction = 'Stop'
ErrorAction = 'Stop'
}
if ($trusted) { $param.InstallationPolicy = 'Trusted' }
if ($Change.Configured.Proxy) { $param.Proxy = $Change.Configured.Proxy }
Expand All @@ -222,9 +227,9 @@
}
if ($registerV3) {
$param = @{
Name = $Change.Configured._Name
Uri = $Change.Configured.Uri
Trusted = $trusted
Name = $Change.Configured._Name
Uri = $Change.Configured.Uri
Trusted = $trusted
ErrorAction = 'Stop'
}
if ($null -ne $Change.Configured.Priority) {
Expand Down