Skip to content

Commit

Permalink
update the output type of Get-AzWebAppPublishingProfile from String t…
Browse files Browse the repository at this point in the history
…o SecureString
  • Loading branch information
YanaXu committed Dec 18, 2024
1 parent 7236500 commit 8a7cef5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/Websites/Websites.Test/ScenarioTests/WebAppTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ function Test-WebAppPublishingProfile
Assert-AreEqual $serverFarm.Id $webapp.ServerFarmId

# Get web app publishing profile
[xml]$profile = Get-AzWebAppPublishingProfile -ResourceGroupName $rgname -Name $appName -OutputFile $profileFileName
[xml]$profile = Get-AzWebAppPublishingProfile -ResourceGroupName $rgname -Name $appName -OutputFile $profileFileName | ConvertFrom-SecureString -AsPlainText
$msDeployProfile = $profile.publishData.publishProfile | ? { $_.publishMethod -eq 'MSDeploy' } | Select -First 1
$pass = $msDeployProfile.userPWD

Expand All @@ -1152,14 +1152,14 @@ function Test-WebAppPublishingProfile
Assert-False { $pass -eq $newPass }

# Get web app publishing profile
[xml]$profile = $webapp | Get-AzWebAppPublishingProfile -OutputFile $profileFileName -Format FileZilla3
[xml]$profile = $webapp | Get-AzWebAppPublishingProfile -OutputFile $profileFileName -Format FileZilla3 | ConvertFrom-SecureString -AsPlainText
$fileZillaProfile = $profile.FileZilla3.Servers.Server

# Assert
Assert-True { $fileZillaProfile.Name -eq $appName }

# Get web app publishing profile without OutputFile
[xml]$profile = Get-AzWebAppPublishingProfile -ResourceGroupName $rgname -Name $appName
[xml]$profile = Get-AzWebAppPublishingProfile -ResourceGroupName $rgname -Name $appName | ConvertFrom-SecureString -AsPlainText

# Assert
Assert-NotNull $profile
Expand Down Expand Up @@ -1232,7 +1232,6 @@ function Test-PublishAzureWebAppFromWar
$javaContainerVersion="8.5"
$PropertiesObject = @{javaVersion = $javaVersion;javaContainer = $javaContainer;javaContainerVersion = $javaContainerVersion}
New-AzResource -PropertyObject $PropertiesObject -ResourceGroupName $rgname -ResourceType Microsoft.Web/sites/config -ResourceName "$appName/web" -ApiVersion 2018-02-01 -Force

$warPath = Join-Path $ResourcesPath "HelloJava.war"
$publishedApp = Publish-AzWebApp -ResourceGroupName $rgname -Name $appName -ArchivePath $warPath -Force

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@


using System.Management.Automation;
using System.Security;

namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
{
/// <summary>
/// this commandlet will get the publishing creds of the given Azure Web app using ARM APIs
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "WebAppPublishingProfile")]
[OutputType(typeof(string))]
[OutputType(typeof(SecureString))]
public class GetAzureWebAppPublishingProfileCmdlet : WebAppBaseCmdlet
{
private const string DefaultFormat = "WebDeploy";
Expand All @@ -46,7 +47,8 @@ public GetAzureWebAppPublishingProfileCmdlet()
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
WriteObject(WebsitesClient.GetWebAppPublishingProfile(ResourceGroupName, Name, null, OutputFile, Format, IncludeDisasterRecoveryEndpoints));
string profile = WebsitesClient.GetWebAppPublishingProfile(ResourceGroupName, Name, null, OutputFile, Format, IncludeDisasterRecoveryEndpoints);
WriteObject(profile.ToSecureString());
}

}
Expand Down
19 changes: 19 additions & 0 deletions src/Websites/Websites/Cmdlets/WebApps/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
{
public static class Utils
{
public static System.Security.SecureString ToSecureString(this string input)
{
if (string.IsNullOrEmpty(input))
return null;

System.Security.SecureString secureString = new System.Security.SecureString();
foreach (char c in input)
{
secureString.AppendChar(c);
}
secureString.MakeReadOnly();
return secureString;
}
}
}
21 changes: 18 additions & 3 deletions src/Websites/Websites/help/Get-AzWebAppPublishingProfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Gets an Azure Web App publishing profile.
```
Get-AzWebAppPublishingProfile [[-OutputFile] <String>] [[-Format] <String>] [-IncludeDisasterRecoveryEndpoints]
[-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### S2
```
Get-AzWebAppPublishingProfile [[-OutputFile] <String>] [[-Format] <String>] [-IncludeDisasterRecoveryEndpoints]
[-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>]
[-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

Expand Down Expand Up @@ -118,6 +118,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: System.Management.Automation.ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ResourceGroupName
Resource Group Name
Expand Down Expand Up @@ -159,7 +174,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## OUTPUTS
### System.String
### System.Security.SecureString
## NOTES
Expand Down

0 comments on commit 8a7cef5

Please sign in to comment.