Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Don't Merge!][SecureString] [SDK-based][Az.Storage] Add an output type SecureString #27192

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Storage/Storage.Management/help/New-AzStorageBlobSASToken.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Generates a SAS token for an Azure storage blob.
```
New-AzStorageBlobSASToken [-Container] <String> [-Blob] <String> [-Permission <String>]
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-AsSecureString] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand All @@ -26,7 +26,7 @@ New-AzStorageBlobSASToken [-Container] <String> [-Blob] <String> [-Permission <S
```
New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClient>] -Policy <String>
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-AsSecureString] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand All @@ -35,7 +35,7 @@ New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClien
```
New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClient>] [-Permission <String>]
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-AsSecureString] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand All @@ -44,7 +44,7 @@ New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClien
```
New-AzStorageBlobSASToken [-Container] <String> [-Blob] <String> -Policy <String>
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-AsSecureString] [-Context <IStorageContext>]
[-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand Down Expand Up @@ -82,6 +82,21 @@ This example generates a User Identity blob SAS token with storage context based

## PARAMETERS

### -AsSecureString
Specify to convert output token as a secure string.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Blob
Specifies the storage blob name.

Expand Down Expand Up @@ -360,6 +375,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

### System.String

### System.Security.SecureString

## NOTES

## RELATED LINKS
Expand Down
27 changes: 24 additions & 3 deletions src/Storage/Storage/Blob/Cmdlet/NewAzureStorageBlobSasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
using System.Collections.Generic;
using global::Azure.Storage;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using System.Security;
using Microsoft.WindowsAzure.Commands.Common;

[Cmdlet("New", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlobSASToken", DefaultParameterSetName = BlobNamePipelineParmeterSetWithPermission, SupportsShouldProcess = true), OutputType(typeof(String))]
[CmdletOutputBreakingChangeWithVersion(typeof(String), "14.0.0", "9.0.0", ReplacementCmdletOutputTypeName = "System.Security.SecureString")]
[Cmdlet("New", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlobSASToken", DefaultParameterSetName = BlobNamePipelineParmeterSetWithPermission, SupportsShouldProcess = true), OutputType(typeof(String), typeof(SecureString))]
public class NewAzureStorageBlobSasTokenCommand : StorageCloudBlobCmdletBase
{
/// <summary>
Expand Down Expand Up @@ -132,6 +135,9 @@ public string Policy
[ValidateNotNullOrEmpty]
public string EncryptionScope { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Specify to convert output token as a secure string.")]
public SwitchParameter AsSecureString { get; set; }

// Overwrite the useless parameter
public override int? ServerTimeoutPerRequest { get; set; }
public override int? ClientTimeoutPerRequest { get; set; }
Expand Down Expand Up @@ -222,11 +228,26 @@ public override void ExecuteCmdlet()
if (FullUri)
{
string fullUri = SasTokenHelper.GetFullUriWithSASToken(blobClient.Uri.ToString(), sasToken);
WriteObject(fullUri);
if (AsSecureString)
{
WriteObject(fullUri.ConvertToSecureString());
}
else
{
WriteObject(fullUri);
}

}
else
{
WriteObject(sasToken);
if (AsSecureString)
{
WriteObject(sasToken.ConvertToSecureString());
}
else
{
WriteObject(sasToken);
}
}
}

Expand Down