Skip to content

Commit 483deef

Browse files
author
Ashraf Farok (PALASH)
committed
New cmdlets added for Creating and entering rmote PSSession to web app container. New cmdlet added for getting container continious deployment url
1 parent 4c34167 commit 483deef

File tree

11 files changed

+2010
-3
lines changed

11 files changed

+2010
-3
lines changed

src/ResourceManager/Websites/Commands.Websites.Test/Commands.Websites.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestCreateNewWebAppSimple.json">
190190
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
191191
</None>
192+
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestEnableContainerContiniousDeploymentAndGetUrl.json">
193+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
194+
</None>
192195
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestRemoveWebApp.json">
193196
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
194197
</None>

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public void TestCreateNewWebAppHyperV()
4545
WebsitesController.NewInstance.RunPsTest(_logger, "Test-CreateNewWebAppHyperV");
4646
}
4747

48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void TestEnableContainerContiniousDeploymentAndGetUrl()
51+
{
52+
WebsitesController.NewInstance.RunPsTest(_logger, "Test-EnableContainerContiniousDeploymentAndGetUrl");
53+
}
54+
4855
[Fact]
4956
[Trait(Category.AcceptanceType, Category.CheckIn)]
5057
public void TestCreateNewAppOnAse()

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppTests.ps1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,81 @@ function Test-CreateNewWebAppHyperV
589589
Remove-AzureRmResourceGroup -Name $rgname -Force
590590
}
591591
}
592+
593+
<#
594+
.SYNOPSIS
595+
Tests enagbling continious deployment for container and getting continious deployment url.
596+
.DESCRIPTION
597+
SmokeTest
598+
#>
599+
function Test-EnableContainerContiniousDeploymentAndGetUrl
600+
{
601+
# Setup
602+
$rgname = Get-ResourceGroupName
603+
$wname = Get-WebsiteName
604+
$location = Get-WebLocation
605+
$whpName = Get-WebHostPlanName
606+
$tier = "PremiumContainer"
607+
$apiversion = "2015-08-01"
608+
$resourceType = "Microsoft.Web/sites"
609+
$containerImageName = "microsoft/iis"
610+
$containerRegistryUrl = "https://testcontainer.azurecr.io"
611+
$ontainerRegistryUser = "testregistry"
612+
$pass = "7Dxo9p79Ins2K3ZU"
613+
$containerRegistryPassword = ConvertTo-SecureString -String $pass -AsPlainText -Force
614+
$dockerPrefix = "DOCKER|"
615+
$expected_ci_url = "https://`$ps7234:dBm0r9w8PeZiv0rPyteQdmgrjCgljKz0QzDk448zg61gfgG90vdfoEuB2kSh@ps7234.scm.azurewebsites.net/docker/hook"
616+
617+
try
618+
{
619+
#Setup
620+
New-AzureRmResourceGroup -Name $rgname -Location $location
621+
$serverFarm = New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier -WorkerSize Small -HyperV
622+
623+
# Create new web app
624+
$job = New-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName -ContainerImageName $containerImageName -ContainerRegistryUrl $containerRegistryUrl -ContainerRegistryUser $ontainerRegistryUser -ContainerRegistryPassword $containerRegistryPassword -EnableContainerContinuousDeployment -AsJob
625+
$job | Wait-Job
626+
$actual = $job | Receive-Job
627+
628+
# Assert
629+
Assert-AreEqual $wname $actual.Name
630+
Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
631+
632+
# Get new web app
633+
$result = Get-AzureRmWebApp -ResourceGroupName $rgname -Name $wname
634+
635+
# Assert
636+
Assert-AreEqual $wname $result.Name
637+
Assert-AreEqual $serverFarm.Id $result.ServerFarmId
638+
Assert-AreEqual $true $result.IsXenon
639+
Assert-AreEqual ($dockerPrefix + $containerImageName) $result.SiteConfig.WindowsFxVersion
640+
641+
$appSettings = @{
642+
"DOCKER_REGISTRY_SERVER_URL" = $containerRegistryUrl;
643+
"DOCKER_REGISTRY_SERVER_USERNAME" = $ontainerRegistryUser;
644+
"DOCKER_REGISTRY_SERVER_PASSWORD" = $pass;
645+
"DOCKER_ENABLE_CI" = "true"}
646+
647+
foreach($nvp in $webApp.SiteConfig.AppSettings)
648+
{
649+
Assert-True { $appSettings.Keys -contains $nvp.Name }
650+
Assert-True { $appSettings[$nvp.Name] -match $nvp.Value }
651+
}
652+
653+
$ci_url = Get-AzureRmWebAppContainerContinuousDeploymentUrl -ResourceGroupName $rgname -Name $wname
654+
655+
Assert-AreEqual $expected_ci_url $ci_url
656+
657+
}
658+
finally
659+
{
660+
# Cleanup
661+
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Force
662+
Remove-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Force
663+
Remove-AzureRmResourceGroup -Name $rgname -Force
664+
}
665+
}
666+
592667
<#
593668
.SYNOPSIS
594669
Tests creating a new website on an ase

src/ResourceManager/Websites/Commands.Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestEnableContainerContiniousDeploymentAndGetUrl.json

Lines changed: 1739 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Websites/Commands.Websites/Az.Websites.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ CmdletsToExport = 'Get-AzAppServicePlan', 'Set-AzAppServicePlan',
9595
'New-AzWebApp', 'Remove-AzWebAppBackup',
9696
'Reset-AzWebAppPublishingProfile', 'Restart-AzWebApp',
9797
'Set-AzWebApp', 'Start-AzWebApp', 'Stop-AzWebApp',
98-
'Get-AzWebAppSnapshot', 'Restore-AzWebAppSnapshot'
98+
'Get-AzWebAppSnapshot', 'Restore-AzWebAppSnapshot',
99+
'Enter-AzureRmWebAppContainerPSSession', 'Get-AzureRMWebAppContainerContinuousDeploymentUr',
100+
'New-AzureRmWebAppContainerPSSession'
101+
102+
99103

100104
# Variables to export from this module
101105
# VariablesToExport = @()

src/ResourceManager/Websites/Commands.Websites/AzureRM.Websites.psd1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ CmdletsToExport = 'Get-AzureRmAppServicePlan', 'Set-AzureRmAppServicePlan',
9595
'New-AzureRmWebApp', 'Remove-AzureRmWebAppBackup',
9696
'Reset-AzureRmWebAppPublishingProfile', 'Restart-AzureRmWebApp',
9797
'Set-AzureRmWebApp', 'Start-AzureRmWebApp', 'Stop-AzureRmWebApp',
98-
'Get-AzureRmWebAppSnapshot', 'Restore-AzureRmWebAppSnapshot'
98+
'Get-AzureRmWebAppSnapshot', 'Restore-AzureRmWebAppSnapshot',
99+
'Enter-AzureRmWebAppContainerPSSession', 'Get-AzureRMWebAppContainerContinuousDeploymentUrl',
100+
'New-AzureRmWebAppContainerPSSession'
101+
99102

100103
# Variables to export from this module
101104
# VariablesToExport = @()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+

2+
// ----------------------------------------------------------------------------------
3+
//
4+
// Copyright Microsoft Corporation
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// ----------------------------------------------------------------------------------
15+
16+
using System.Management.Automation;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
19+
20+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
21+
{
22+
/// <summary>
23+
/// this commandlet will create remote ps session with site
24+
/// </summary>
25+
[Cmdlet("Enter", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "WebAppContainerPSSession")]
26+
[OutputType(typeof(string))]
27+
public class EnterAzureRmWebAppContainerPSSession : WebAppBaseCmdlet
28+
{
29+
[Parameter(ParameterSetName = ParameterSet1Name, Position = 1, Mandatory = false, HelpMessage = "The name of the web app slot.", ValueFromPipelineByPropertyName = true)]
30+
[ValidateNotNullOrEmpty]
31+
public string SlotName { get; set; }
32+
33+
public override void ExecuteCmdlet()
34+
{
35+
if (ParameterSetName == ParameterSet2Name)
36+
{
37+
string rg, name, slot;
38+
39+
Utilities.CmdletHelpers.TryParseWebAppMetadataFromResourceId(WebApp.Id, out rg, out name, out slot);
40+
ResourceGroupName = rg;
41+
Name = name;
42+
SlotName = slot;
43+
}
44+
WebsitesClient.RunWebAppContainerPSSessionScript(this, ResourceGroupName, Name, SlotName);
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+

2+
// ----------------------------------------------------------------------------------
3+
//
4+
// Copyright Microsoft Corporation
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// ----------------------------------------------------------------------------------
15+
16+
using System.Management.Automation;
17+
18+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
19+
{
20+
/// <summary>
21+
/// this commandlet will return ContainerContinuousDeploymentUrl
22+
/// </summary>
23+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "WebAppContainerContinuousDeploymentUrl")]
24+
[OutputType(typeof(string))]
25+
public class GetAzureRMWebAppContainerContinuousDeploymentUrl : WebAppBaseCmdlet
26+
{
27+
[Parameter(ParameterSetName = ParameterSet1Name, Position = 1, Mandatory = false, HelpMessage = "The name of the web app slot.", ValueFromPipelineByPropertyName = true)]
28+
[ValidateNotNullOrEmpty]
29+
public string SlotName { get; set; }
30+
31+
public override void ExecuteCmdlet()
32+
{
33+
if (ParameterSetName == ParameterSet2Name)
34+
{
35+
string rg, name, slot;
36+
37+
Utilities.CmdletHelpers.TryParseWebAppMetadataFromResourceId(WebApp.Id, out rg, out name, out slot);
38+
ResourceGroupName = rg;
39+
Name = name;
40+
SlotName = slot;
41+
}
42+
43+
WriteObject(WebsitesClient.GetPublishingCredentials(ResourceGroupName, Name).ScmUri + "/docker/hook");
44+
}
45+
}
46+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+

2+
// ----------------------------------------------------------------------------------
3+
//
4+
// Copyright Microsoft Corporation
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// ----------------------------------------------------------------------------------
15+
16+
using System.Management.Automation;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
19+
20+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
21+
{
22+
/// <summary>
23+
/// this commandlet will create remote ps session with site
24+
/// </summary>
25+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "WebAppContainerPSSession")]
26+
[OutputType(typeof(string))]
27+
public class NewAzureRmWebAppContainerPSSession : WebAppBaseCmdlet
28+
{
29+
[Parameter(ParameterSetName = ParameterSet1Name, Position = 1, Mandatory = false, HelpMessage = "The name of the web app slot.", ValueFromPipelineByPropertyName = true)]
30+
[ValidateNotNullOrEmpty]
31+
public string SlotName { get; set; }
32+
33+
public override void ExecuteCmdlet()
34+
{
35+
if (ParameterSetName == ParameterSet2Name)
36+
{
37+
string rg, name, slot;
38+
39+
Utilities.CmdletHelpers.TryParseWebAppMetadataFromResourceId(WebApp.Id, out rg, out name, out slot);
40+
ResourceGroupName = rg;
41+
Name = name;
42+
SlotName = slot;
43+
}
44+
45+
WebsitesClient.RunWebAppContainerPSSessionScript(this, ResourceGroupName, Name, SlotName, true);
46+
}
47+
}
48+
}

src/ResourceManager/Websites/Commands.Websites/Commands.Websites.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@
7979
<Compile Include="Cmdlets\BackupRestore\GetAzureWebAppBackupConfiguration.cs" />
8080
<Compile Include="Cmdlets\BackupRestore\GetAzureWebAppBackupList.cs" />
8181
<Compile Include="Cmdlets\DeploymentSlots\SwitchAzureWebAppSlot.cs" />
82+
<Compile Include="Cmdlets\WebApps\EnterAzureRmWebAppContainerPSSession.cs" />
83+
<Compile Include="Cmdlets\WebApps\GetAzureRMWebAppContainerContinuousDeploymentUrl.cs" />
8284
<Compile Include="Cmdlets\WebApps\GetAzureWebAppMetrics.cs" />
8385
<Compile Include="Cmdlets\WebApps\GetAzureWebAppPublishingProfile.cs" />
8486
<Compile Include="Cmdlets\WebApps\GetAzureWebApp.cs" />
8587
<Compile Include="Cmdlets\BackupRestore\NewAzureWebAppBackup.cs" />
88+
<Compile Include="Cmdlets\WebApps\NewAzureRmWebAppContainerPSSession.cs" />
8689
<Compile Include="Cmdlets\WebApps\RemoveAzureWebApp.cs" />
8790
<Compile Include="Cmdlets\WebApps\NewAzureWebApp.cs" />
8891
<Compile Include="Cmdlets\BackupRestore\RemoveAzureWebAppBackup.cs" />

src/ResourceManager/Websites/Commands.Websites/Utilities/WebsitesClient.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
using Microsoft.Azure.Management.WebSites;
1919
using Microsoft.Azure.Management.WebSites.Models;
2020
using Microsoft.Rest.Azure;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Linq;
25+
using System.Management.Automation;
2426
using System.Net;
2527
using System.Xml.Linq;
2628

@@ -259,7 +261,37 @@ public string GetWebAppPublishingProfile(string resourceGroupName, string webSit
259261
return doc.ToString();
260262
}
261263

262-
public string ResetWebAppPublishingCredentials(string resourceGroupName, string webSiteName, string slotName)
264+
public User GetPublishingCredentials(string resourceGroupName, string webSiteName, string slotName = null)
265+
{
266+
string qualifiedSiteName;
267+
268+
return CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ?
269+
WrappedWebsitesClient.WebApps().ListPublishingCredentialsSlot(resourceGroupName, webSiteName, slotName)
270+
: WrappedWebsitesClient.WebApps().ListPublishingCredentials(resourceGroupName, webSiteName);
271+
}
272+
273+
public void RunWebAppContainerPSSessionScript(PSCmdlet cmdlet, string resourceGroupName, string webSiteName, string slotName = null, bool newPSSession = false)
274+
{
275+
Site site = GetWebApp(resourceGroupName, webSiteName, slotName);
276+
User user = GetPublishingCredentials(resourceGroupName, webSiteName, slotName);
277+
const string webAppContainerPSSessionVarPrefix = "webAppPSSession";
278+
279+
string publishingUserName = user.PublishingUserName.Length <= 20 ? user.PublishingUserName : user.PublishingUserName.Substring(0, 20);
280+
string psSessionScript = string.Format("${3}User = '{0}' \n${3}Password = ConvertTo-SecureString -String '{1}' -AsPlainText -Force \n" +
281+
"${3}Credential = New-Object -TypeName PSCredential -ArgumentList ${3}User, ${3}Password\nSet-Item WSMAN:\\LocalHost\\Client\\Auth\\Basic -Value $true \n" +
282+
"Set-Item WSMAN:\\LocalHost\\Client\\TrustedHosts -Value {2} -Force\n" +
283+
(newPSSession ? "${3}NewPsSession = New-PSSession":"Enter-PSSession") + " -ConnectionUri https://{2}/WSMAN -Authentication Basic -Credential ${3}Credential \n",
284+
publishingUserName, user.PublishingPassword, site.DefaultHostName, webAppContainerPSSessionVarPrefix);
285+
286+
cmdlet.ExecuteScript<object>(psSessionScript);
287+
if (newPSSession)
288+
{
289+
cmdlet.WriteObject(cmdlet.GetVariableValue(string.Format("{0}NewPsSession", webAppContainerPSSessionVarPrefix)));
290+
}
291+
cmdlet.ExecuteScript<object>(string.Format("Clear-Variable {0}*", webAppContainerPSSessionVarPrefix)); //Clearing session variable
292+
}
293+
294+
public string ResetWebAppPublishingCredentials(string resourceGroupName, string webSiteName, string slotName)
263295
{
264296
string qualifiedSiteName;
265297
if (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName))

0 commit comments

Comments
 (0)