Skip to content

Commit c3aa805

Browse files
[Az.Network] Use SecureString for sas url inputs in GetNetworkVirtualApplianceBootDiagnosticsCommand (#27187)
* use SecureString for sas url inputs in cmdlet * remove unused directives * updating help file * update test and help * Revert "update test and help" This reverts commit f3c19cd. * update test --------- Co-authored-by: Nori Zhang <[email protected]>
1 parent 5c6bf25 commit c3aa805

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/Network/Network.Test/ScenarioTests/NetworkVirtualApplianceBootDiagnosticsTest.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ function Test-NetworkVirtualApplianceBootDiagnostics
6060

6161
# Generate SAS token for the existing Blob
6262
#$sasToken = New-AzStorageBlobSASToken -Container $containerName -Blob $blobName -Context $storageAccountContext -Permission "rw" -ExpiryTime ([System.DateTime]::UtcNow).AddDays(1) -StartTime ([System.DateTime]::UtcNow).AddHours(-1) -FullUri
63-
$sasToken = "placeholder"
63+
$sasToken = "******"
6464
Assert-NotNull $sasToken
6565
Write-Host "SAS uri for the blob '$blobName' is: $sasToken"
66+
$sasTokenEncrypt = ConvertTo-SecureString -String $sasToken -AsPlainText -Force
6667

67-
$sasUrlScreenShot = "placeholder"
68+
$sasUrlScreenShot = "******"
69+
$sasUrlScreenShotEncrypt = ConvertTo-SecureString -String $sasUrlScreenShot -AsPlainText -Force
6870

69-
$nvabootdiagnostics = Get-AzNetworkVirtualApplianceBootDiagnostics -ResourceGroupName $rgname -Name $nvaname -InstanceId 0 -SerialConsoleStorageSasUrl $sasToken -ConsoleScreenshotStorageSasUrl $sasUrlScreenShot
71+
$nvabootdiagnostics = Get-AzNetworkVirtualApplianceBootDiagnostics -ResourceGroupName $rgname -Name $nvaname -InstanceId 0 -SerialConsoleStorageSasUrl $sasTokenEncrypt -ConsoleScreenshotStorageSasUrl $sasUrlScreenShotEncrypt
7072
Assert-AreEqual $nvabootdiagnostics.Status "Succeeded"
7173
}
7274
finally{

src/Network/Network/NetworkVirtualAppliance/GetNetworkVirtualApplianceBootDiagnosticsCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Management.Automation;
24+
using System.Security;
25+
using Microsoft.WindowsAzure.Commands.Common;
2426

2527
namespace Microsoft.Azure.Commands.Network
2628
{
@@ -59,13 +61,13 @@ public class GetNetworkVirtualApplianceBootDiagnosticsCommand : NetworkVirtualAp
5961
Mandatory = false,
6062
ValueFromPipelineByPropertyName = true,
6163
HelpMessage = "Storage blob (eg. txt file) sas url into which serial console logs for requested VM instance is copied")]
62-
public string SerialConsoleStorageSasUrl { get; set; }
64+
public SecureString SerialConsoleStorageSasUrl { get; set; }
6365

6466
[Parameter(
6567
Mandatory = false,
6668
ValueFromPipelineByPropertyName = true,
6769
HelpMessage = "Storage blob (eg. png file) sas url into which console screen shot for requested VM instance is copied")]
68-
public string ConsoleScreenshotStorageSasUrl { get; set; }
70+
public SecureString ConsoleScreenshotStorageSasUrl { get; set; }
6971

7072
[Parameter(
7173
Mandatory = true,
@@ -108,8 +110,8 @@ public override void Execute()
108110
var bootDiagParams = new NetworkVirtualApplianceBootDiagnosticParameters()
109111
{
110112
InstanceId = instanceId,
111-
SerialConsoleStorageSasUrl = this.SerialConsoleStorageSasUrl,
112-
ConsoleScreenshotStorageSasUrl = this.ConsoleScreenshotStorageSasUrl
113+
SerialConsoleStorageSasUrl = this.SerialConsoleStorageSasUrl?.ConvertToString(),
114+
ConsoleScreenshotStorageSasUrl = this.ConsoleScreenshotStorageSasUrl?.ConvertToString()
113115
};
114116

115117
var result = this.NetworkVirtualAppliancesClient.GetBootDiagnosticLogsWithHttpMessagesAsync(resourceGroupName: this.ResourceGroupName, networkVirtualApplianceName: this.Name, request: bootDiagParams).GetAwaiter().GetResult();

src/Network/Network/help/Get-AzNetworkVirtualApplianceBootDiagnostics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Retrieves boot diagnostic logs for a given NetworkVirtualAppliance VM instance
1515
### ResourceNameParameterSet (Default)
1616
```
1717
Get-AzNetworkVirtualApplianceBootDiagnostics -ResourceGroupName <String> -Name <String> [-InstanceId <Int32>]
18-
[-SerialConsoleStorageSasUrl <String>] [-ConsoleScreenshotStorageSasUrl <String>] [-AsJob]
18+
[-SerialConsoleStorageSasUrl <SecureString>] [-ConsoleScreenshotStorageSasUrl <SecureString>] [-AsJob]
1919
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2020
```
2121

2222
### ResourceIdParameterSet
2323
```
24-
Get-AzNetworkVirtualApplianceBootDiagnostics [-InstanceId <Int32>] [-SerialConsoleStorageSasUrl <String>]
25-
[-ConsoleScreenshotStorageSasUrl <String>] -ResourceId <String> [-AsJob]
24+
Get-AzNetworkVirtualApplianceBootDiagnostics [-InstanceId <Int32>] [-SerialConsoleStorageSasUrl <SecureString>]
25+
[-ConsoleScreenshotStorageSasUrl <SecureString>] -ResourceId <String> [-AsJob]
2626
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2727
```
2828

@@ -75,7 +75,7 @@ Storage blob (eg.
7575
png file) sas url into which console screen shot for requested VM instance is copied
7676
7777
```yaml
78-
Type: String
78+
Type: SecureString
7979
Parameter Sets: (All)
8080
Aliases:
8181

@@ -166,7 +166,7 @@ Storage blob (eg.
166166
txt file) sas url into which serial console logs for requested VM instance is copied
167167
168168
```yaml
169-
Type: String
169+
Type: SecureString
170170
Parameter Sets: (All)
171171
Aliases:
172172

0 commit comments

Comments
 (0)