Skip to content

Commit 05a4844

Browse files
authored
Merge pull request #5986 from panchagnula/sisirap-BUILD-Merged-MSI
Websites: Adding support for MSI & Https in slots
2 parents 34687a1 + a0a914a commit 05a4844

File tree

9 files changed

+1725
-1092
lines changed

9 files changed

+1725
-1092
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@
300300
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
301301
</ItemGroup>
302302
<ItemGroup />
303-
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
304303
<Import Project="..\..\..\..\tools\Common.Dependencies.Test.targets" />
305304
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
306305
</Project>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,18 @@ function Test-SetWebAppSlot
525525
# Assert
526526
Assert-AreEqual $appWithSlotName $slot.Name
527527
Assert-AreEqual $serverFarm1.Id $slot.ServerFarmId
528+
Assert-Null $webApp.Identity
528529

529-
# Change service plan
530-
$job = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName2 -AsJob
530+
# Change service plan & set properties
531+
$job = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName2 -HttpsOnly $true -AssignIdentity $true -AsJob
531532
$job | Wait-Job
532533
$slot = $job | Receive-Job
533534

534535
# Assert
535536
Assert-AreEqual $appWithSlotName $slot.Name
536537
Assert-AreEqual $serverFarm2.Id $slot.ServerFarmId
538+
Assert-AreEqual $true $slot.HttpsOnly
539+
Assert-NotNull $slot.Identity
537540

538541
# Set config properties
539542
$slot.SiteConfig.HttpLoggingEnabled = $true

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,24 @@ function Test-SetWebApp
595595
# Assert
596596
Assert-AreEqual $webAppName $webApp.Name
597597
Assert-AreEqual $serverFarm1.Id $webApp.ServerFarmId
598+
Assert-Null $webApp.Identity
598599

599-
# Change service plan
600-
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -AsJob
600+
# Change service plan & set site properties
601+
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -HttpsOnly $true -AssignIdentity $true -AsJob
601602
$job | Wait-Job
602603
$webApp = $job | Receive-Job
603604

604605
# Assert
605606
Assert-AreEqual $webAppName $webApp.Name
606607
Assert-AreEqual $serverFarm2.Id $webApp.ServerFarmId
608+
Assert-AreEqual $true $webApp.HttpsOnly
609+
Assert-NotNull $webApp.Identity
607610

608611
# Set config properties
609612
$webapp.SiteConfig.HttpLoggingEnabled = $true
610613
$webapp.SiteConfig.RequestTracingEnabled = $true
611614

615+
# Set site properties
612616
$webApp = $webApp | Set-AzureRmWebApp
613617

614618
# Assert

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

Lines changed: 869 additions & 557 deletions
Large diffs are not rendered by default.

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

Lines changed: 766 additions & 511 deletions
Large diffs are not rendered by default.

src/ResourceManager/Websites/Commands.Websites/Cmdlets/DeploymentSlots/SetAzureWebAppSlot.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,17 @@ public class SetAzureWebAppSlotCmdlet : WebAppSlotBaseCmdlet
8989
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
9090
public SwitchParameter AsJob { get; set; }
9191

92+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
93+
public bool AssignIdentity { get; set; }
94+
95+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
96+
public bool HttpsOnly { get; set; }
97+
9298
public override void ExecuteCmdlet()
9399
{
94100
base.ExecuteCmdlet();
95101
SiteConfig siteConfig = null;
102+
Site site = null;
96103
string location = null;
97104
switch (ParameterSetName)
98105
{
@@ -128,12 +135,41 @@ public override void ExecuteCmdlet()
128135
// Update web app configuration
129136
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, Slot, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());
130137

138+
if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
139+
{
140+
141+
site = new Site
142+
{
143+
Location = location,
144+
ServerFarmId = WebApp.ServerFarmId,
145+
Identity = parameters.Contains("AssignIdentity") && AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
146+
HttpsOnly = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly
147+
};
148+
149+
Dictionary<string, string> appSettings = WebApp.SiteConfig?.AppSettings?.ToDictionary(x => x.Name, x => x.Value);
150+
if (parameters.Contains("AssignIdentity"))
151+
{
152+
153+
// Add or update the appsettings property
154+
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
155+
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, Slot, WebApp.SiteConfig, appSettings,
156+
WebApp.SiteConfig.ConnectionStrings.
157+
ToDictionary(nvp => nvp.Name,
158+
nvp => new ConnStringValueTypePair
159+
{
160+
Type = nvp.Type.Value,
161+
Value = nvp.ConnectionString
162+
},
163+
StringComparer.OrdinalIgnoreCase));
164+
}
165+
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, WebApp.ServerFarmId, site);
166+
}
167+
131168
if (parameters.Contains("AppServicePlan"))
132169
{
133170
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, AppServicePlan);
134171
}
135172

136-
137173
break;
138174
case ParameterSet2Name:
139175
// Web app is direct or pipeline input

src/ResourceManager/Websites/Commands.Websites/Cmdlets/WebApps/SetAzureWebApp.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public class SetAzureWebAppCmdlet : WebAppBaseCmdlet
9898
public SwitchParameter AsJob { get; set; }
9999

100100
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
101-
public SwitchParameter AssignIdentity { get; set; }
101+
public bool AssignIdentity { get; set; }
102102

103103
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
104-
public SwitchParameter HttpsOnly { get; set; }
104+
public bool HttpsOnly { get; set; }
105105

106106
public override void ExecuteCmdlet()
107107
{
@@ -145,21 +145,22 @@ public override void ExecuteCmdlet()
145145

146146
if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
147147
{
148+
148149
site = new Site
149150
{
150151
Location = location,
151152
ServerFarmId = WebApp.ServerFarmId,
152-
Identity = AssignIdentity.IsPresent ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
153-
HttpsOnly = HttpsOnly.IsPresent
153+
Identity = parameters.Contains("AssignIdentity") && AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
154+
HttpsOnly = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly
154155
};
155156

156157
Dictionary<string, string> appSettings = WebApp.SiteConfig?.AppSettings?.ToDictionary(x => x.Name, x => x.Value);
157-
if (AssignIdentity.IsPresent)
158+
if (parameters.Contains("AssignIdentity"))
158159
{
159160

160161
// Add or update the appsettings property
161162
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
162-
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, WebApp.SiteConfig, appSettings,
163+
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, WebApp.SiteConfig, appSettings,
163164
WebApp.SiteConfig.ConnectionStrings.
164165
ToDictionary(nvp => nvp.Name,
165166
nvp => new ConnStringValueTypePair
@@ -169,12 +170,6 @@ public override void ExecuteCmdlet()
169170
},
170171
StringComparer.OrdinalIgnoreCase));
171172
}
172-
else
173-
{
174-
// disabling the identity property updates the siteconfig only
175-
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity.IsPresent).ToString();
176-
}
177-
178173
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, site);
179174
}
180175

src/ResourceManager/Websites/Commands.Websites/help/Set-AzureRmWebApp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Set-AzureRmWebApp [[-AppServicePlan] <String>] [[-DefaultDocuments] <String[]>]
2121
[[-ConnectionStrings] <Hashtable>]
2222
[[-HandlerMappings] <System.Collections.Generic.IList`1[Microsoft.Azure.Management.WebSites.Models.HandlerMapping]>]
2323
[[-ManagedPipelineMode] <String>] [[-WebSocketsEnabled] <Boolean>] [[-Use32BitWorkerProcess] <Boolean>]
24-
[[-AutoSwapSlotName] <String>] [-HostNames <String[]>] [-NumberOfWorkers <Int32>] [-AsJob] [-AssignIdentity]
25-
[-HttpsOnly] [-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
24+
[[-AutoSwapSlotName] <String>] [-HostNames <String[]>] [-NumberOfWorkers <Int32>] [-AsJob] [[-AssignIdentity] <Boolean>]
25+
[[-HttpsOnly] <Boolean>] [-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
2626
[<CommonParameters>]
2727
```
2828

@@ -93,10 +93,10 @@ Accept wildcard characters: False
9393
```
9494
9595
### -AssignIdentity
96-
Enable MSI on an existing azure webapp or functionapp
96+
Enable/disable MSI on an existing azure webapp or functionapp [PREVIEW]
9797
9898
```yaml
99-
Type: SwitchParameter
99+
Type: Boolean
100100
Parameter Sets: S1
101101
Aliases:
102102

@@ -231,7 +231,7 @@ Accept wildcard characters: False
231231
Enable/disable redirecting all traffic to HTTPS on an existing azure webapp or functionapp
232232
233233
```yaml
234-
Type: SwitchParameter
234+
Type: Boolean
235235
Parameter Sets: S1
236236
Aliases:
237237

src/ResourceManager/Websites/Commands.Websites/help/Set-AzureRmWebAppSlot.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Set-AzureRmWebAppSlot [[-AppServicePlan] <String>] [[-DefaultDocuments] <String[
2222
[[-HandlerMappings] <System.Collections.Generic.IList`1[Microsoft.Azure.Management.WebSites.Models.HandlerMapping]>]
2323
[[-ManagedPipelineMode] <String>] [[-WebSocketsEnabled] <Boolean>] [[-Use32BitWorkerProcess] <Boolean>]
2424
[-AutoSwapSlotName <String>] [-NumberOfWorkers <Int32>] [-ResourceGroupName] <String> [-Name] <String>
25-
[-Slot] <String> [-AsJob]
25+
[[-AssignIdentity] <Boolean>] [[HttpsOnly] <Boolean>] [-Slot] <String> [-AsJob]
2626
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2727
```
2828

@@ -352,6 +352,35 @@ Default value: None
352352
Accept pipeline input: False
353353
Accept wildcard characters: False
354354
```
355+
### -HttpsOnly
356+
Enable/disable redirecting all traffic to HTTPS on an existing slot
357+
358+
```yaml
359+
Type: Boolean
360+
Parameter Sets: S1
361+
Aliases:
362+
363+
Required: False
364+
Position: Named
365+
Default value: None
366+
Accept pipeline input: False
367+
Accept wildcard characters: False
368+
```
369+
### -AssignIdentity
370+
Enable/disable MSI on an existing slot [PREVIEW]
371+
372+
```yaml
373+
Type: Boolean
374+
Parameter Sets: S1
375+
Aliases:
376+
377+
Required: False
378+
Position: Named
379+
Default value: None
380+
Accept pipeline input: False
381+
Accept wildcard characters: False
382+
```
383+
355384
### -AsJob
356385
Run cmdlet in the background
357386

0 commit comments

Comments
 (0)