Skip to content

Commit 7e1b83e

Browse files
author
Hovsep
committed
Merge pull request Azure#2248 from akurmi/dev
Adding Get-AzureRmWebAppSlotConfigName and Set-AzureRmWebAppSlotConfigName cmdlets
2 parents 08d8cae + 34bd11e commit 7e1b83e

File tree

10 files changed

+9572
-1731
lines changed

10 files changed

+9572
-1731
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@
246246
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestGetWebAppSlotMetrics.json">
247247
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
248248
</None>
249+
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestManageSlotSlotConfigName.json">
250+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
251+
</None>
249252
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestSetWebAppSlot.json">
250253
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
251254
</None>
@@ -317,4 +320,4 @@
317320
</ItemGroup>
318321
<ItemGroup />
319322
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
320-
</Project>
323+
</Project>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,12 @@ public void TestSetWebAppSlot()
9090
{
9191
WebsitesController.NewInstance.RunPsTest("Test-SetWebAppSlot");
9292
}
93+
94+
[Fact]
95+
[Trait(Category.AcceptanceType, Category.CheckIn)]
96+
public void TestManageSlotSlotConfigName()
97+
{
98+
WebsitesController.NewInstance.RunPsTest("Test-ManageSlotSlotConfigName");
99+
}
93100
}
94101
}

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,49 @@ function Test-WebAppSlotPublishingProfile
703703
Remove-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $planName -Force
704704
Remove-AzureRmResourceGroup -Name $rgname -Force
705705
}
706-
}
706+
}
707+
708+
<#
709+
.SYNOPSIS
710+
Tests managing slot config names for a web app
711+
#>
712+
function Test-ManageSlotSlotConfigName
713+
{
714+
$rgname = "Default-Web-EastAsia"
715+
$appname = "webappslottest"
716+
717+
# Retrive Web App
718+
$webApp = Get-AzureRmWebApp -ResourceGroupName $rgname -Name $appname
719+
720+
$slotConfigNames = $webApp | Get-AzureRmWebAppSlotConfigName
721+
722+
# Make sure that None of the settings are currently marked as slot setting
723+
Assert-AreEqual 0 $slotConfigNames.AppSettingNames.Count
724+
Assert-AreEqual 0 $slotConfigNames.ConnectionStringNames.Count
725+
726+
# Test - Mark all app settings as slot setting
727+
$appSettingNames = $webApp.SiteConfig.AppSettings | Select-Object -ExpandProperty Name
728+
$webApp | Set-AzureRmWebAppSlotConfigName -AppSettingNames $appSettingNames
729+
$slotConfigNames = $webApp | Get-AzureRmWebAppSlotConfigName
730+
Assert-AreEqual $webApp.SiteConfig.AppSettings.Count $slotConfigNames.AppSettingNames.Count
731+
Assert-AreEqual 0 $slotConfigNames.ConnectionStringNames.Count
732+
733+
# Test- Mark all connection strings as slot setting
734+
$connectionStringNames = $webApp.SiteConfig.ConnectionStrings | Select-Object -ExpandProperty Name
735+
Set-AzureRmWebAppSlotConfigName -ResourceGroupName $rgname -Name $appname -ConnectionStringNames $connectionStringNames
736+
$slotConfigNames = Get-AzureRmWebAppSlotConfigName -ResourceGroupName $rgname -Name $appname
737+
Assert-AreEqual $webApp.SiteConfig.AppSettings.Count $slotConfigNames.AppSettingNames.Count
738+
Assert-AreEqual $webApp.SiteConfig.ConnectionStrings.Count $slotConfigNames.ConnectionStringNames.Count
739+
740+
# Test- Clear slot app setting names
741+
$webApp | Set-AzureRmWebAppSlotConfigName -RemoveAllAppSettingNames
742+
$slotConfigNames = $webApp | Get-AzureRmWebAppSlotConfigName
743+
Assert-AreEqual 0 $slotConfigNames.AppSettingNames.Count
744+
Assert-AreEqual $webApp.SiteConfig.ConnectionStrings.Count $slotConfigNames.ConnectionStringNames.Count
745+
746+
# Test - Clear slot connection string names
747+
Set-AzureRmWebAppSlotConfigName -ResourceGroupName $rgname -Name $appname -RemoveAllConnectionStringNames
748+
$slotConfigNames = Get-AzureRmWebAppSlotConfigName -ResourceGroupName $rgname -Name $appname
749+
Assert-AreEqual 0 $slotConfigNames.AppSettingNames.Count
750+
Assert-AreEqual 0 $slotConfigNames.ConnectionStringNames.Count
751+
}

src/ResourceManager/Websites/Commands.Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests/TestManageSlotSlotConfigName.json

Lines changed: 1157 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.WebApps.Utilities;
17+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
18+
{
19+
[Cmdlet(VerbsCommon.Get, "AzureRmWebAppSlotConfigName")]
20+
public class GetAzureWebAppSlotConfigName : WebAppBaseCmdlet
21+
{
22+
public override void ExecuteCmdlet()
23+
{
24+
base.ExecuteCmdlet();
25+
WriteObject(WebsitesClient.GetSlotConfigNames(ResourceGroupName, Name));
26+
}
27+
}
28+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.WebApps.Models;
17+
using Microsoft.Azure.Commands.WebApps.Utilities;
18+
19+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.DeploymentSlots
20+
{
21+
[Cmdlet(VerbsCommon.Set, "AzureRmWebAppSlotConfigName")]
22+
public class SetAzureWebAppSlotConfigName : WebAppBaseCmdlet
23+
{
24+
[Parameter(Position = 2, Mandatory = false, HelpMessage = "Names of app settings that need to marked as slot settings", ValueFromPipelineByPropertyName = true)]
25+
[ValidateNotNullOrEmpty]
26+
public string[] AppSettingNames { get; set; }
27+
28+
[Parameter(Position = 3, Mandatory = false, HelpMessage = "Names of connection strings that need to marked as slot settings", ValueFromPipelineByPropertyName = true)]
29+
[ValidateNotNullOrEmpty]
30+
public string[] ConnectionStringNames { get; set; }
31+
32+
[Parameter(Position = 4, Mandatory = false, HelpMessage = "Remove all app settings")]
33+
[ValidateNotNullOrEmpty]
34+
public SwitchParameter RemoveAllAppSettingNames { get; set; }
35+
36+
[Parameter(Position = 5, Mandatory = false, HelpMessage = "Remove all connection string names")]
37+
[ValidateNotNullOrEmpty]
38+
public SwitchParameter RemoveAllConnectionStringNames { get; set; }
39+
40+
public override void ExecuteCmdlet()
41+
{
42+
base.ExecuteCmdlet();
43+
if ((RemoveAllAppSettingNames)
44+
&& AppSettingNames != null)
45+
{
46+
throw new ValidationMetadataException("Please either provide a list of app setting names or set RemoveAllSettingNames option to true");
47+
}
48+
49+
if((RemoveAllConnectionStringNames)
50+
&& ConnectionStringNames != null)
51+
{
52+
throw new ValidationMetadataException("Please either provide a list of connection string names or set RemoveAllConnectionStringNames option to true");
53+
}
54+
55+
var appSettingNames = RemoveAllAppSettingNames.IsPresent ? new string[0] : AppSettingNames;
56+
var connectionStringNames = RemoveAllConnectionStringNames.IsPresent ? new string[0] : ConnectionStringNames;
57+
WriteObject(WebsitesClient.SetSlotConfigNames(ResourceGroupName, Name, appSettingNames, connectionStringNames));
58+
}
59+
}
60+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@
148148
<Compile Include="Cmdlets\Certificates\NewAzureWebAppSSLBinding.cs" />
149149
<Compile Include="Cmdlets\Certificates\RemoveAzureWebAppSSLBinding.cs" />
150150
<Compile Include="Cmdlets\DeploymentSlots\GetAzureWebAppSlot.cs" />
151+
<Compile Include="Cmdlets\DeploymentSlots\GetAzureWebAppSlotConfigName.cs" />
151152
<Compile Include="Cmdlets\DeploymentSlots\GetAzureWebAppSlotMetrics.cs" />
152153
<Compile Include="Cmdlets\DeploymentSlots\GetAzureWebAppSlotPublishingProfile.cs" />
153154
<Compile Include="Cmdlets\DeploymentSlots\NewAzureWebAppSlot.cs" />
154155
<Compile Include="Cmdlets\DeploymentSlots\RemoveAzureWebAppSlot.cs" />
155156
<Compile Include="Cmdlets\DeploymentSlots\ResetAzureWebAppSlotPublishingProfile.cs" />
156157
<Compile Include="Cmdlets\DeploymentSlots\RestartAzureWebAppSlot.cs" />
157158
<Compile Include="Cmdlets\DeploymentSlots\SetAzureWebAppSlot.cs" />
159+
<Compile Include="Cmdlets\DeploymentSlots\SetAzureWebAppSlotConfigName.cs" />
158160
<Compile Include="Cmdlets\DeploymentSlots\StartAzureWebAppSlot.cs" />
159161
<Compile Include="Cmdlets\DeploymentSlots\StopAzureWebAppSlot.cs" />
160162
<Compile Include="Cmdlets\BackupRestore\EditAzureWebAppBackupConfiguration.cs" />

src/ResourceManager/Websites/Commands.Websites/Microsoft.Azure.Commands.Websites.dll-Help.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ FormatsToProcess = @()
6161

6262
# Modules to import as nested modules of the module specified in ModuleToProcess
6363
NestedModules = @(
64-
'..\..\..\Package\Debug\ResourceManager\AzureResourceManager\Websites\Microsoft.Azure.Commands.Websites.dll'
64+
'..\..\..\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Websites\Microsoft.Azure.Commands.Websites.dll'
6565
)
6666

6767
# Functions to export from this module

0 commit comments

Comments
 (0)