Skip to content

Commit 6456173

Browse files
authored
Fix BlobProperties is empty issue when use sas without prefix '?'(#15465)
1 parent 79ff2a2 commit 6456173

File tree

11 files changed

+37
-15
lines changed

11 files changed

+37
-15
lines changed

src/Storage/Storage.Management.Test/Storage.Management.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
1515
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.6.0" />
1616
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.6.0" />
17-
<PackageReference Include="Azure.Storage.Queues" Version="12.5.0" />
17+
<PackageReference Include="Azure.Storage.Queues" Version="12.6.0" />
1818
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="22.0.0" />
1919
</ItemGroup>
2020

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- `Add-AzStorageAccountManagementPolicyAction`
2525
* Make list datalake gen2 items list out all items by default, instead of need user to list chunk by chunk.
2626
- `Get-AzDataLakeGen2ChildItem`
27+
* Fix BlobProperties is empty issue when use sas without prefix '?' [#15460]
2728

2829
## Version 3.9.0
2930
* Supported enable/disable Blob container soft delete

src/Storage/Storage/Blob/StorageCloudBlobCmdletBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ internal DataLakeFileSystemClient GetFileSystemClientByName(IStorageBlobManageme
656656
}
657657
else if (localChannel.StorageContext.StorageAccount.Credentials.IsSAS) //SAS
658658
{
659-
fileSystem = new DataLakeFileSystemClient(new Uri (fileSystemUri.ToString() + localChannel.StorageContext.StorageAccount.Credentials.SASToken));
659+
fileSystem = new DataLakeFileSystemClient(new Uri (fileSystemUri.ToString() + "?" + Util.GetSASStringWithoutQuestionMark(localChannel.StorageContext.StorageAccount.Credentials.SASToken)));
660660
}
661661
else if (localChannel.StorageContext.StorageAccount.Credentials.IsSharedKey) //Shared Key
662662
{
@@ -897,15 +897,16 @@ public static BlobClient GetTrack2BlobClient(CloudBlob cloubBlob, AzureStorageCo
897897
}
898898
else if (cloubBlob.ServiceClient.Credentials.IsSAS) //SAS
899899
{
900+
string sas = Util.GetSASStringWithoutQuestionMark(cloubBlob.ServiceClient.Credentials.SASToken);
900901
string fullUri = cloubBlob.SnapshotQualifiedUri.ToString();
901902
if (cloubBlob.IsSnapshot)
902903
{
903904
// Since snapshot URL already has '?', need remove '?' in the first char of sas
904-
fullUri = fullUri + "&" + cloubBlob.ServiceClient.Credentials.SASToken.Substring(1);
905+
fullUri = fullUri + "&" + sas;
905906
}
906907
else
907908
{
908-
fullUri = fullUri + cloubBlob.ServiceClient.Credentials.SASToken;
909+
fullUri = fullUri + "?" + sas;
909910
}
910911
blobClient = new BlobClient(new Uri(fullUri), options);
911912
}

src/Storage/Storage/Common/AzureStorageBlob.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,16 @@ public static BlobClient GetTrack2BlobClient(CloudBlob cloubBlob, AzureStorageCo
379379
}
380380
else if (cloubBlob.ServiceClient.Credentials.IsSAS) //SAS
381381
{
382+
string sas = Util.GetSASStringWithoutQuestionMark(cloubBlob.ServiceClient.Credentials.SASToken);
382383
string fullUri = cloubBlob.SnapshotQualifiedUri.ToString();
383384
if (cloubBlob.IsSnapshot)
384385
{
385386
// Since snapshot URL already has '?', need remove '?' in the first char of sas
386-
fullUri = fullUri + "&" + cloubBlob.ServiceClient.Credentials.SASToken.Substring(1);
387+
fullUri = fullUri + "&" + sas;
387388
}
388389
else
389390
{
390-
fullUri = fullUri + cloubBlob.ServiceClient.Credentials.SASToken;
391+
fullUri = fullUri + "?" + sas;
391392
}
392393
blobClient = new BlobClient(new Uri(fullUri), options);
393394
}

src/Storage/Storage/Common/AzureStorageContainer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
2424
using BlobContainerProperties = global::Azure.Storage.Blobs.Models.BlobContainerProperties;
2525
using Microsoft.Azure.Storage.Auth;
2626
using Microsoft.Azure.Storage;
27+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2728

2829
/// <summary>
2930
/// azure storage container
@@ -259,7 +260,8 @@ public static BlobContainerClient GetTrack2BlobContainerClient(CloudBlobContaine
259260
else if (cloubContainer.ServiceClient.Credentials.IsSAS) //SAS
260261
{
261262
string fullUri = cloubContainer.Uri.ToString();
262-
fullUri = fullUri + cloubContainer.ServiceClient.Credentials.SASToken;
263+
string sas = Util.GetSASStringWithoutQuestionMark(cloubContainer.ServiceClient.Credentials.SASToken);
264+
fullUri = fullUri + "?" + sas;
263265
blobContainerClient = new BlobContainerClient(new Uri(fullUri), options);
264266
}
265267
else if (cloubContainer.ServiceClient.Credentials.IsSharedKey) //Shared Key

src/Storage/Storage/Common/AzureStorageFile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
2121
using Microsoft.WindowsAzure.Commands.Storage;
2222
using global::Azure.Storage.Files.Shares;
2323
using global::Azure.Storage;
24+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2425

2526
/// <summary>
2627
/// Azure storage file object
@@ -97,15 +98,16 @@ public static ShareFileClient GetTrack2FileClient(CloudFile cloudFile, AzureStor
9798
ShareFileClient fileClient;
9899
if (cloudFile.ServiceClient.Credentials.IsSAS) //SAS
99100
{
101+
string sas = Util.GetSASStringWithoutQuestionMark(cloudFile.ServiceClient.Credentials.SASToken);
100102
string fullUri = cloudFile.SnapshotQualifiedUri.ToString();
101103
if (cloudFile.Share.IsSnapshot)
102104
{
103105
// Since snapshot URL already has '?', need remove '?' in the first char of sas
104-
fullUri = fullUri + "&" + cloudFile.ServiceClient.Credentials.SASToken.Substring(1);
106+
fullUri = fullUri + "&" + sas;
105107
}
106108
else
107109
{
108-
fullUri = fullUri + cloudFile.ServiceClient.Credentials.SASToken;
110+
fullUri = fullUri + "?" + sas;
109111
}
110112
fileClient = new ShareFileClient(new Uri(fullUri));
111113
}

src/Storage/Storage/Common/AzureStorageFileDirectory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
2121
using Microsoft.WindowsAzure.Commands.Storage;
2222
using global::Azure.Storage.Files.Shares;
2323
using global::Azure.Storage;
24+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2425

2526
/// <summary>
2627
/// Azure storage file object
@@ -91,15 +92,16 @@ protected static ShareDirectoryClient GetTrack2FileDirClient(CloudFileDirectory
9192
ShareDirectoryClient fileDirClient;
9293
if (cloudFileDir.ServiceClient.Credentials.IsSAS) //SAS
9394
{
95+
string sas = Util.GetSASStringWithoutQuestionMark(cloudFileDir.ServiceClient.Credentials.SASToken);
9496
string fullUri = cloudFileDir.SnapshotQualifiedUri.ToString();
9597
if (cloudFileDir.Share.IsSnapshot)
9698
{
9799
// Since snapshot URL already has '?', need remove '?' in the first char of sas
98-
fullUri = fullUri + "&" + cloudFileDir.ServiceClient.Credentials.SASToken.Substring(1);
100+
fullUri = fullUri + "&" + sas;
99101
}
100102
else
101103
{
102-
fullUri = fullUri + cloudFileDir.ServiceClient.Credentials.SASToken;
104+
fullUri = fullUri + "?" + sas;
103105
}
104106
fileDirClient = new ShareDirectoryClient(new Uri(fullUri));
105107
}

src/Storage/Storage/Common/AzureStorageFileShare.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
2121
using Microsoft.WindowsAzure.Commands.Storage;
2222
using global::Azure.Storage.Files.Shares;
2323
using global::Azure.Storage;
24+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2425

2526
/// <summary>
2627
/// Azure storage file object
@@ -108,15 +109,16 @@ protected static ShareClient GetTrack2FileShareClient(CloudFileShare cloudFileSh
108109
ShareClient fileShareClient;
109110
if (cloudFileShare.ServiceClient.Credentials.IsSAS) //SAS
110111
{
112+
string sas = Util.GetSASStringWithoutQuestionMark(cloudFileShare.ServiceClient.Credentials.SASToken);
111113
string fullUri = cloudFileShare.SnapshotQualifiedUri.ToString();
112114
if (cloudFileShare.IsSnapshot)
113115
{
114116
// Since snapshot URL already has '?', need remove '?' in the first char of sas
115-
fullUri = fullUri + "&" + cloudFileShare.ServiceClient.Credentials.SASToken.Substring(1);
117+
fullUri = fullUri + "&" + sas;
116118
}
117119
else
118120
{
119-
fullUri = fullUri + cloudFileShare.ServiceClient.Credentials.SASToken;
121+
fullUri = fullUri + "?" + sas;
120122
}
121123
fileShareClient = new ShareClient(new Uri(fullUri));
122124
}

src/Storage/Storage/Common/AzureStorageQueue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
2020
using global::Azure.Storage;
2121
using global::Azure.Storage.Queues;
2222
using Microsoft.WindowsAzure.Commands.Storage;
23+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2324

2425
/// <summary>
2526
/// Azure storage queue
@@ -111,8 +112,9 @@ protected static QueueClient GetTrack2QueueClient(CloudQueue cloudQueue, AzureSt
111112
}
112113
else if (cloudQueue.ServiceClient.Credentials.IsSAS) //SAS
113114
{
115+
string sas = Util.GetSASStringWithoutQuestionMark(cloudQueue.ServiceClient.Credentials.SASToken);
114116
string fullUri = cloudQueue.Uri.ToString();
115-
fullUri = fullUri + cloudQueue.ServiceClient.Credentials.SASToken;
117+
fullUri = fullUri + "?" + sas;
116118
queueClient = new QueueClient(new Uri(fullUri));
117119
}
118120
else if (cloudQueue.ServiceClient.Credentials.IsSharedKey) //Shared Key

src/Storage/Storage/Common/Util.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,5 +679,14 @@ public static NtfsFileAttributes LocalAttributesToAzureFileNtfsAttributes(FileAt
679679

680680
return cloudFileNtfsAttributes;
681681
}
682+
683+
public static string GetSASStringWithoutQuestionMark(string sas)
684+
{
685+
if (sas.StartsWith("?"))
686+
{
687+
sas = sas.Substring(1);
688+
}
689+
return sas;
690+
}
682691
}
683692
}

0 commit comments

Comments
 (0)