@@ -10,50 +10,33 @@ Param (
10
10
)
11
11
. " ${PSScriptRoot} \..\scripts\common.ps1"
12
12
13
- # Given the github io blob storage url and language regex,
14
- # the helper function will return a list of artifact names.
15
- function Get-BlobStorage-Artifacts ($blobStorageUrl , $blobDirectoryRegex , $blobArtifactsReplacement ) {
13
+ # Fetch a list of "artifacts" from blob storage corresponding to the given
14
+ # language (-storagePrefix). Remove the prefix from the path names to arrive at
15
+ # an "artifact" name.
16
+ function Get-BlobStorage-Artifacts (
17
+ $blobDirectoryRegex ,
18
+ $blobArtifactsReplacement ,
19
+ $storageAccountName ,
20
+ $storageContainerName ,
21
+ $storagePrefix
22
+ ) {
16
23
LogDebug " Reading artifact from storage blob ..."
17
- $returnedArtifacts = @ ()
18
- $pageToken = " "
19
- Do {
20
- $resp = " "
21
- if (! $pageToken ) {
22
- # First page call.
23
- $resp = Invoke-RestMethod - Method Get - Uri $blobStorageUrl
24
- }
25
- else {
26
- # Next page call
27
- $blobStorageUrlPageToken = $blobStorageUrl + " &marker=$pageToken "
28
- $resp = Invoke-RestMethod - Method Get - Uri $blobStorageUrlPageToken
29
- }
30
- # Convert to xml documents.
31
- $xmlDoc = [xml ](removeBomFromString $resp )
32
- foreach ($elem in $xmlDoc.EnumerationResults.Blobs.BlobPrefix ) {
33
- # What service return like "dotnet/Azure.AI.Anomalydetector/", needs to fetch out "Azure.AI.Anomalydetector"
34
- $artifact = $elem.Name -replace $blobDirectoryRegex , $blobArtifactsReplacement
35
- $returnedArtifacts += $artifact
36
- }
37
- # Fetch page token
38
- $pageToken = $xmlDoc.EnumerationResults.NextMarker
39
- } while ($pageToken )
40
- return $returnedArtifacts
41
- }
42
-
43
- # The sequence of Bom bytes differs by different encoding.
44
- # The helper function here is only to strip the utf-8 encoding system as it is used by blob storage list api.
45
- # Return the original string if not in BOM utf-8 sequence.
46
- function RemoveBomFromString ([string ]$bomAwareString ) {
47
- if ($bomAwareString.length -le 3 ) {
48
- return $bomAwareString
49
- }
50
- $bomPatternByteArray = [byte []] (0xef , 0xbb , 0xbf )
51
- # The default encoding for powershell is ISO-8859-1, so converting bytes with the encoding.
52
- $bomAwareBytes = [Text.Encoding ]::GetEncoding(28591 ).GetBytes($bomAwareString.Substring (0 , 3 ))
53
- if (@ (Compare-Object $bomPatternByteArray $bomAwareBytes - SyncWindow 0 ).Length -eq 0 ) {
54
- return $bomAwareString.Substring (3 )
55
- }
56
- return $bomAwareString
24
+ # "--only-show-errors" suppresses warnings about the fact that the az CLI is not authenticated
25
+ # "--query '[].name'" returns a list of only blob names
26
+ # "--num-results *" handles pagination so the caller does not have to
27
+ $artifacts = az storage blob list `
28
+ -- account- name $storageAccountName `
29
+ -- container- name $storageContainerName `
30
+ -- prefix $storagePrefix `
31
+ -- delimiter / `
32
+ -- only- show-errors `
33
+ -- query ' [].name' `
34
+ -- num- results * | ConvertFrom-Json
35
+ LogDebug " Number of artifacts found: $ ( $artifacts.Length ) "
36
+
37
+ # example: "python/azure-storage-blob" -> "azure-storage-blob"
38
+ $artifacts = $artifacts.ForEach ({ $_ -replace $blobDirectoryRegex , $blobArtifactsReplacement })
39
+ return $artifacts
57
40
}
58
41
59
42
function Get-TocMapping {
0 commit comments