@@ -135,7 +135,7 @@ try {
135
135
if (-not $storageAccount.Contains (' .' )) {
136
136
$storageAccount += " .blob.core.windows.net"
137
137
}
138
- $BaseUrl = ReplaceCDN - sourceUrl " https://$storageAccount /$ ( $Type.ToLowerInvariant ()) /" - useBlobUrl:( $bcContainerHelperConfig .DoNotUseCdnForArtifacts )
138
+ $BaseUrl = ReplaceCDN - sourceUrl " https://$storageAccount /$ ( $Type.ToLowerInvariant ()) /"
139
139
$storageAccount = ReplaceCDN - sourceUrl $storageAccount - useBlobUrl
140
140
141
141
if ($storageAccount -eq ' bcinsider.blob.core.windows.net' -and ! $accept_insiderEULA ) {
@@ -181,7 +181,7 @@ try {
181
181
$artifactUrl
182
182
}
183
183
else {
184
- $GetListUrl = " https:// $storageAccount / $ ( $Type .ToLowerInvariant () ) /?comp=list&restype=container "
184
+ $versionPrefix = ' '
185
185
if ($select -eq ' SecondToLastMajor' ) {
186
186
if ($version ) {
187
187
throw " You cannot specify a version when asking for the Second To Last Major version"
@@ -196,138 +196,60 @@ try {
196
196
if ($dots -ne 3 -or ! ([Version ]::TryParse($version , [ref ] $closestToVersion ))) {
197
197
throw " Version number must be in the format 1.2.3.4 when you want to get the closest artifact Url"
198
198
}
199
- $GetListUrl + = " &prefix= $ ( $closestToVersion.Major ) .$ ( $closestToVersion.Minor ) ."
199
+ $versionPrefix = " $ ( $closestToVersion.Major ) .$ ( $closestToVersion.Minor ) ."
200
200
}
201
201
elseif (! ([string ]::IsNullOrEmpty($version ))) {
202
202
$dots = ($version.ToCharArray () -eq ' .' ).Count
203
203
if ($dots -lt 3 ) {
204
204
# avoid 14.1 returning 14.10, 14.11 etc.
205
205
$version = " $ ( $version.TrimEnd (' .' )) ."
206
206
}
207
- $GetListUrl += " &prefix= $ ( $ Version) "
207
+ $versionPrefix = $ Version
208
208
}
209
-
210
- $Artifacts = @ ()
211
- $nextMarker = ' '
212
- $currentMarker = ' '
213
- $downloadAttempt = 1
214
- $downloadRetryAttempts = 10
215
- do {
216
- if ($currentMarker -ne $nextMarker )
217
- {
218
- $currentMarker = $nextMarker
219
- $downloadAttempt = 1
220
- }
221
- Write-Verbose " Download String $GetListUrl$nextMarker "
222
- try
223
- {
224
- $Response = Invoke-RestMethod - UseBasicParsing - ContentType " application/json; charset=UTF8" - Uri " $GetListUrl$nextMarker "
225
- if (([int ]$Response [0 ]) -eq 239 -and ([int ]$Response [1 ]) -eq 187 -and ([int ]$Response [2 ]) -eq 191 ) {
226
- # Remove UTF8 BOM
227
- $response = $response.Substring (3 )
228
- }
229
- if (([int ]$Response [0 ]) -eq 65279 ) {
230
- # Remove Unicode BOM (PowerShell 7.4)
231
- $response = $response.Substring (1 )
232
- }
233
- $enumerationResults = ([xml ]$Response ).EnumerationResults
234
-
235
- if ($enumerationResults.Blobs ) {
236
- if (($After ) -or ($Before )) {
237
- $artifacts += $enumerationResults.Blobs.Blob | % {
238
- if ($after ) {
239
- $blobModifiedDate = [DateTime ]::Parse($_.Properties ." Last-Modified" )
240
- if ($before ) {
241
- if ($blobModifiedDate -lt $before -and $blobModifiedDate -gt $after ) {
242
- $_.Name
243
- }
244
- }
245
- elseif ($blobModifiedDate -gt $after ) {
246
- $_.Name
247
- }
248
- }
249
- else {
250
- $blobModifiedDate = [DateTime ]::Parse($_.Properties ." Last-Modified" )
251
- if ($blobModifiedDate -lt $before ) {
252
- $_.Name
253
- }
254
- }
255
- }
256
- }
257
- else {
258
- $artifacts += $enumerationResults.Blobs.Blob.Name
259
- }
260
- }
261
- $nextMarker = $enumerationResults.NextMarker
262
- if ($nextMarker ) {
263
- $nextMarker = " &marker=$nextMarker "
264
- }
265
- }
266
- catch
267
- {
268
- $downloadAttempt += 1
269
- Write-Host " Error querying artifacts. Error message was $ ( $_.Exception.Message ) "
270
- Write-Host
271
-
272
- if ($downloadAttempt -le $downloadRetryAttempts )
273
- {
274
- Write-Host " Repeating download attempt (" $downloadAttempt.ToString () " of " $downloadRetryAttempts.ToString () " )..."
275
- Write-Host
276
- }
277
- else
278
- {
279
- throw
280
- }
281
- }
282
- } while ($nextMarker )
283
209
284
- if (! ([string ]::IsNullOrEmpty($country ))) {
285
- # avoid confusion between base and se
286
- $countryArtifacts = $Artifacts | Where-Object { $_.EndsWith (" /$country " , [System.StringComparison ]::InvariantCultureIgnoreCase) -and ($doNotCheckPlatform -or ($Artifacts.Contains (" $ ( $_.Split (' /' )[0 ]) /platform" ))) }
287
- if (! $countryArtifacts ) {
288
- if (($type -eq " sandbox" ) -and ($bcContainerHelperConfig.mapCountryCode.PSObject.Properties.Name -eq $country )) {
289
- $country = $bcContainerHelperConfig.mapCountryCode ." $country "
290
- $countryArtifacts = $Artifacts | Where-Object { $_.EndsWith (" /$country " , [System.StringComparison ]::InvariantCultureIgnoreCase) -and ($doNotCheckPlatform -or ($Artifacts.Contains (" $ ( $_.Split (' /' )[0 ]) /platform" ))) }
291
- }
292
- }
293
- $Artifacts = $countryArtifacts
210
+ $parameters = @ {
211
+ " storageAccount" = $storageAccount
212
+ " Type" = $Type
213
+ " VersionPrefix" = $versionPrefix
214
+ " Country" = $country
215
+ " doNotCheckPlatform" = $doNotCheckPlatform
216
+ }
217
+ if ($after ) {
218
+ $parameters [" after" ] = $after
219
+ }
220
+ if ($before ) {
221
+ $parameters [" before" ] = $before
222
+ }
223
+ if ($bcContainerHelperConfig.useIndexForArtifacts ) {
224
+ $artifacts = QueryArtifactsFromIndex @parameters
294
225
}
295
226
else {
296
- $Artifacts = $Artifacts | Where-Object { ! ( $_ .EndsWith ( " /platform " , [ System.StringComparison ]::InvariantCultureIgnoreCase)) }
227
+ $artifacts = QueryArtifactsFromStorage @parameters
297
228
}
298
229
299
230
switch ($Select ) {
300
231
' All' {
301
- $Artifacts = $Artifacts |
302
- Sort-Object { [Version ]($_.Split (' /' )[0 ]) }
232
+ # Artifacts are sorted
303
233
}
304
234
' Latest' {
305
- $Artifacts = $Artifacts |
306
- Sort-Object { [Version ]($_.Split (' /' )[0 ]) } |
307
- Select-Object - Last 1
235
+ $Artifacts = $Artifacts | Select-Object - Last 1
308
236
}
309
237
' First' {
310
- $Artifacts = $Artifacts |
311
- Sort-Object { [Version ]($_.Split (' /' )[0 ]) } |
312
- Select-Object - First 1
238
+ $Artifacts = $Artifacts | Select-Object - First 1
313
239
}
314
240
' SecondToLastMajor' {
315
- $Artifacts = $Artifacts |
316
- Sort-Object - Descending { [Version ]($_.Split (' /' )[0 ]) }
317
- $latest = $Artifacts | Select-Object - First 1
241
+ $latest = $Artifacts | Select-Object - Last 1
318
242
if ($latest ) {
319
243
$latestversion = [Version ]($latest.Split (' /' )[0 ])
320
244
$Artifacts = $Artifacts |
321
245
Where-Object { ([Version ]($_.Split (' /' )[0 ])).Major -ne $latestversion.Major } |
322
- Select-Object - First 1
246
+ Select-Object - Last 1
323
247
}
324
248
else {
325
249
$Artifacts = @ ()
326
250
}
327
251
}
328
252
' Closest' {
329
- $Artifacts = $Artifacts |
330
- Sort-Object { [Version ]($_.Split (' /' )[0 ]) }
331
253
$closest = $Artifacts |
332
254
Where-Object { [Version ]($_.Split (' /' )[0 ]) -ge $closestToVersion } |
333
255
Select-Object - First 1
0 commit comments