Skip to content

Commit 2fb2085

Browse files
authored
Merge pull request #5420 from wastoresh/fixlistcontainer
Fix Get-AzureStorageContainer with Account SAS failure
2 parents 878f28f + 600ab12 commit 2fb2085

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/Storage/ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21-
21+
* Fix Get Blob Container cmdlet execute fail with Accout SAS credential issue
22+
- Get-AzureStorageContainer
23+
2224
## Version 4.1.0
2325
* Add cmdlets to get and set Storage service properties
2426
- Get-AzureStorageServiceProperty

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageContainer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ internal void PackCloudBlobContainerWithAcl(IEnumerable<Tuple<CloudBlobContainer
206206
return;
207207
}
208208

209+
// Only write warning for SAS when use cmdlet alias Get-AzureStorageContainerAcl, since the cmdlets alias specified get container ACL
210+
if (this.MyInvocation.Line.ToLower().Contains("get-azurestoragecontaineracl"))
211+
{
212+
// Write warning when user SAS credential since get container ACL will fail
213+
AzureStorageContext storageContext = this.GetCmdletStorageContext();
214+
if (storageContext != null && storageContext.StorageAccount != null && storageContext.StorageAccount.Credentials != null && storageContext.StorageAccount.Credentials.IsSAS)
215+
{
216+
WriteWarning("Get container permission will fail with SAS token credentials, it needs storage Account key credentials.");
217+
}
218+
}
219+
209220
IStorageBlobManagement localChannel = Channel;
210221
foreach (Tuple<CloudBlobContainer, BlobContinuationToken> containerInfo in containerList)
211222
{
@@ -231,13 +242,10 @@ internal async Task GetContainerPermission(long taskId, IStorageBlobManagement l
231242
permissions = await localChannel.GetContainerPermissionsAsync(container, accessCondition,
232243
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
233244
}
234-
catch (StorageException e)
245+
catch (StorageException e) when (e.IsNotFoundException() || e.IsForbiddenException())
235246
{
236-
if (!e.IsNotFoundException())
237-
{
238-
throw;
239-
}
240-
//404 Not found means we don't have permission to query the Permission of the specified container.
247+
// 404 Not found, or 403 Forbidden means we don't have permission to query the Permission of the specified container.
248+
// Just skip return container permission in this case.
241249
}
242250
WriteCloudContainerObject(taskId, localChannel, container, permissions, continuationToken);
243251
}

src/Storage/Commands.Storage/Common/StorageExceptionUtil.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public static bool IsNotFoundException(this StorageException e)
3232
return e.RequestInformation != null && e.RequestInformation.HttpStatusCode == 404;
3333
}
3434

35+
/// <summary>
36+
/// Whether the storage exception is Fordidden exception or not.
37+
/// </summary>
38+
/// <param name="e">StorageException from storage client</param>
39+
/// <returns>Whether the storageexception is caused by Fordidden</returns>
40+
public static bool IsForbiddenException(this StorageException e)
41+
{
42+
return e.RequestInformation != null && e.RequestInformation.HttpStatusCode == 403;
43+
}
44+
3545
/// <summary>
3646
/// Whether the storage exception is 409 conflict exception
3747
/// </summary>

src/Storage/Commands.Storage/Microsoft.WindowsAzure.Commands.Storage.format.ps1xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
<TableColumnHeader>
327327
<Label>Name</Label>
328328
<Alignment>Left</Alignment>
329+
<Width>20</Width>
329330
</TableColumnHeader>
330331
<TableColumnHeader>
331332
<Label>PublicAccess</Label>

0 commit comments

Comments
 (0)