|
54 | 54 | $supportedTypes = 'Any', 'Update', 'All', 'V2', 'V2Preferred', 'V3' |
55 | 55 |
|
56 | 56 | foreach ($configuredRepo in $Configured) { |
57 | | - # Incomplete configurations are ignored (e.g. just storing credentials) |
58 | | - if (-not $configuredRepo.Type -or -not $configuredRepo.Uri) { continue } |
| 57 | + # Incomplete configurations are processed in a limited manner, as not enough information is present to create or delete |
| 58 | + $isIncomplete = -not $configuredRepo.Type -or -not $configuredRepo.Uri |
59 | 59 |
|
60 | | - if ($configuredRepo.Type -notin $supportedTypes) { |
| 60 | + if (-not $isIncomplete -and $configuredRepo.Type -notin $supportedTypes) { |
61 | 61 | Write-PSFMessage -Level Warning -String 'Update-PSFRepository.Error.InvalidType' -StringValues $configuredRepo.Type, ($supportedTypes -join ', ') |
62 | 62 | continue |
63 | 63 | } |
64 | 64 |
|
65 | 65 | $matching = $Actual | Where-Object Name -EQ $configuredRepo._Name |
66 | | - $shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present) |
| 66 | + # An incomplete configuration can only be used to modify an existing repository, so skip if nothing matches |
| 67 | + if ($isIncomplete -and -not $matching) { continue } |
67 | 68 |
|
68 | | - $mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred' |
69 | | - if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false } |
70 | | - $mustBeV2 = $configuredRepo.Type -in 'All', 'V2' |
71 | | - $mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred' |
72 | | - if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false } |
73 | | - $mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3' |
| 69 | + if (-not $isIncomplete) { |
| 70 | + $shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present) |
74 | 71 |
|
75 | | - # Case: Should not exist and does not |
76 | | - if (-not $shouldExist -and -not $matching) { |
77 | | - continue |
78 | | - } |
| 72 | + $mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred' |
| 73 | + if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false } |
| 74 | + $mustBeV2 = $configuredRepo.Type -in 'All', 'V2' |
| 75 | + $mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred' |
| 76 | + if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false } |
| 77 | + $mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3' |
79 | 78 |
|
80 | | - #region Deletion |
81 | | - foreach ($matchingRepo in $matching) { |
82 | | - if ( |
83 | | - # Should exist |
84 | | - $shouldExist -and |
85 | | - ( |
86 | | - $matchingRepo.Type -eq 'V2' -and $mayBeV2 -or |
87 | | - $matchingRepo.Type -eq 'V3' -and $mayBeV3 |
88 | | - ) |
89 | | - ) { |
| 79 | + # Case: Should not exist and does not |
| 80 | + if (-not $shouldExist -and -not $matching) { |
90 | 81 | continue |
91 | 82 | } |
92 | 83 |
|
93 | | - [PSCustomObject]@{ |
94 | | - Type = 'Delete' |
95 | | - Configured = $configuredRepo |
96 | | - Actual = $matchingRepo |
97 | | - Changes = @{ } |
| 84 | + #region Deletion |
| 85 | + foreach ($matchingRepo in $matching) { |
| 86 | + if ( |
| 87 | + # Should exist |
| 88 | + $shouldExist -and |
| 89 | + ( |
| 90 | + $matchingRepo.Type -eq 'V2' -and $mayBeV2 -or |
| 91 | + $matchingRepo.Type -eq 'V3' -and $mayBeV3 |
| 92 | + ) |
| 93 | + ) { |
| 94 | + continue |
| 95 | + } |
| 96 | + |
| 97 | + [PSCustomObject]@{ |
| 98 | + Type = 'Delete' |
| 99 | + Configured = $configuredRepo |
| 100 | + Actual = $matchingRepo |
| 101 | + Changes = @{ } |
| 102 | + } |
98 | 103 | } |
99 | | - } |
100 | | - if (-not $shouldExist) { continue } |
101 | | - #endregion Deletion |
| 104 | + if (-not $shouldExist) { continue } |
| 105 | + #endregion Deletion |
102 | 106 |
|
103 | | - #region Creation |
104 | | - # Case: Should exist but does not |
105 | | - if ($shouldExist -and -not $matching) { |
106 | | - [PSCustomObject]@{ |
107 | | - Type = 'Create' |
108 | | - Configured = $configuredRepo |
109 | | - Actual = $null |
110 | | - Changes = @{ } |
| 107 | + #region Creation |
| 108 | + # Case: Should exist but does not |
| 109 | + if ($shouldExist -and -not $matching) { |
| 110 | + [PSCustomObject]@{ |
| 111 | + Type = 'Create' |
| 112 | + Configured = $configuredRepo |
| 113 | + Actual = $null |
| 114 | + Changes = @{ } |
| 115 | + } |
| 116 | + continue |
111 | 117 | } |
112 | | - continue |
113 | | - } |
114 | 118 |
|
115 | | - # Case: Must exist on V2 but does not |
116 | | - if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) { |
117 | | - [PSCustomObject]@{ |
118 | | - Type = 'Create' |
119 | | - Configured = $configuredRepo |
120 | | - Actual = $matching |
121 | | - Changes = @{ } |
| 119 | + # Case: Must exist on V2 but does not |
| 120 | + if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) { |
| 121 | + [PSCustomObject]@{ |
| 122 | + Type = 'Create' |
| 123 | + Configured = $configuredRepo |
| 124 | + Actual = $matching |
| 125 | + Changes = @{ } |
| 126 | + } |
122 | 127 | } |
123 | | - } |
124 | 128 |
|
125 | | - # Case: Must exist on V3 but does not |
126 | | - if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) { |
127 | | - [PSCustomObject]@{ |
128 | | - Type = 'Create' |
129 | | - Configured = $configuredRepo |
130 | | - Actual = $matching |
131 | | - Changes = @{ } |
| 129 | + # Case: Must exist on V3 but does not |
| 130 | + if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) { |
| 131 | + [PSCustomObject]@{ |
| 132 | + Type = 'Create' |
| 133 | + Configured = $configuredRepo |
| 134 | + Actual = $matching |
| 135 | + Changes = @{ } |
| 136 | + } |
132 | 137 | } |
| 138 | + |
| 139 | + # If there is no matching, existing repository, there is no need to update |
| 140 | + if (-not $matching) { continue } |
| 141 | + #endregion Creation |
133 | 142 | } |
134 | 143 |
|
135 | | - # If there is no matching, existing repository, there is no need to update |
136 | | - if (-not $matching) { continue } |
137 | | - #endregion Creation |
138 | | - |
139 | 144 | #region Update |
140 | 145 | foreach ($matchingRepo in $matching) { |
141 | 146 | $intendedUri = $configuredRepo.Uri |
|
147 | 152 | if ($null -eq $trusted) { $trusted = $true } |
148 | 153 |
|
149 | 154 | $changes = @{ } |
150 | | - if ($matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri } |
| 155 | + if (-not $isIncomplete -and $matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri } |
151 | 156 | if ($matchingRepo.Trusted -ne $trusted) { $changes.Trusted = $trusted -as [bool] } |
152 | 157 | if ( |
153 | 158 | $configuredRepo.Priority -and |
|
208 | 213 | $uri = $Change.Configured.Uri -replace 'v3/index.json$', 'v2' |
209 | 214 |
|
210 | 215 | $param = @{ |
211 | | - Name = $Change.Configured._Name |
212 | | - SourceLocation = $uri |
| 216 | + Name = $Change.Configured._Name |
| 217 | + SourceLocation = $uri |
213 | 218 | PublishLocation = $uri |
214 | | - ErrorAction = 'Stop' |
| 219 | + ErrorAction = 'Stop' |
215 | 220 | } |
216 | 221 | if ($trusted) { $param.InstallationPolicy = 'Trusted' } |
217 | 222 | if ($Change.Configured.Proxy) { $param.Proxy = $Change.Configured.Proxy } |
|
222 | 227 | } |
223 | 228 | if ($registerV3) { |
224 | 229 | $param = @{ |
225 | | - Name = $Change.Configured._Name |
226 | | - Uri = $Change.Configured.Uri |
227 | | - Trusted = $trusted |
| 230 | + Name = $Change.Configured._Name |
| 231 | + Uri = $Change.Configured.Uri |
| 232 | + Trusted = $trusted |
228 | 233 | ErrorAction = 'Stop' |
229 | 234 | } |
230 | 235 | if ($null -ne $Change.Configured.Priority) { |
|
0 commit comments