Skip to content

Commit 3523883

Browse files
authored
Merge pull request #5252 from panchagnula/sisirap-NickGBase-IdentitySet
Fixes#4808: Add support for Identity property on WebApps & Fixes:#5155: Add support for Https only property
2 parents 8a0c6c5 + e598e0f commit 3523883

File tree

8 files changed

+113
-33
lines changed

8 files changed

+113
-33
lines changed

src/ResourceManager/Websites/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Added ResourceGroup Completer to -ResourceGroup parameters allowing tab completion through resource groups in current subscription
2323
* Added -AsJob support for long-running Websites cmdlets. Allows selected cmdlets to run in the background and return a job to track and control progress.
2424
- Affected cmdlets are New-, Remove-, Add-, and Set- for WebApps, AppServicePlan and Slots
25+
* Added -AssignIdentity & -Httpsonly properties for SetAzureWebApp
2526

2627
## Version 4.0.0
2728
* Add support for online help

src/ResourceManager/Websites/Commands.Websites/Cmdlets/AppServicePlans/SetAzureAppServicePlan.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.WebApps.Utilities;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1617
using Microsoft.Azure.Management.WebSites.Models;
1718
using System.Management.Automation;
1819
using System.Text.RegularExpressions;
@@ -33,14 +34,14 @@ public class SetAzureAppServicePlanCmdlet : AppServicePlanBaseCmdlet
3334
public string AdminSiteName { get; set; }
3435

3536
[Parameter(ParameterSetName = ParameterSet1Name, Position = 3, Mandatory = false, HelpMessage = "The App Service plan tier. Allowed values are [Free|Shared|Basic|Standard|Premium|PremiumV2]")]
36-
[ValidateSet("Free", "Shared", "Basic", "Standard", "Premium", "PremiumV2", IgnoreCase = true)]
37+
[PSArgumentCompleter("Free", "Shared", "Basic", "Standard", "Premium", "PremiumV2", "Isolated")]
3738
public string Tier { get; set; }
3839

3940
[Parameter(ParameterSetName = ParameterSet1Name, Position = 4, Mandatory = false, HelpMessage = "Number of Workers to be allocated.")]
4041
public int NumberofWorkers { get; set; }
4142

4243
[Parameter(ParameterSetName = ParameterSet1Name, Position = 5, Mandatory = false, HelpMessage = "Size of workers to be allocated. Allowed values are [Small|Medium|Large|ExtraLarge]")]
43-
[ValidateSet("Small", "Medium", "Large", "ExtraLarge", IgnoreCase = true)]
44+
[PSArgumentCompleter("Small", "Medium", "Large", "ExtraLarge")]
4445
public string WorkerSize { get; set; }
4546

4647
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Whether or not to enable Per Site Scaling")]

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,18 @@ public class SetAzureWebAppCmdlet : WebAppBaseCmdlet
9696

9797
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
9898
public SwitchParameter AsJob { get; set; }
99+
100+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp or functionapp")]
101+
public SwitchParameter AssignIdentity { get; set; }
102+
103+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp or functionapp")]
104+
public SwitchParameter HttpsOnly { get; set; }
99105

100106
public override void ExecuteCmdlet()
101107
{
102108
base.ExecuteCmdlet();
103109
SiteConfig siteConfig = null;
110+
Site site = null;
104111
string location = null;
105112
switch (ParameterSetName)
106113
{
@@ -131,10 +138,40 @@ public override void ExecuteCmdlet()
131138
AutoSwapSlotName = parameters.Contains("AutoSwapSlotName") ? AutoSwapSlotName : null,
132139
NumberOfWorkers = parameters.Contains("NumberOfWorkers") ? NumberOfWorkers : WebApp.SiteConfig.NumberOfWorkers
133140
};
141+
142+
// Update web app configuration
143+
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());
134144
}
135145

136-
// Update web app configuration
137-
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());
146+
if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
147+
{
148+
site = new Site
149+
{
150+
Location = location,
151+
ServerFarmId = WebApp.ServerFarmId,
152+
Identity = parameters.Contains("AssignIdentity") ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
153+
HttpsOnly = parameters.Contains("HttpsOnly")
154+
};
155+
156+
if (parameters.Contains("AssignIdentity"))
157+
{
158+
Dictionary<string, string> appSettings = WebApp.SiteConfig?.AppSettings?.ToDictionary(x => x.Name, x => x.Value);
159+
160+
// Add or update the appsettings property
161+
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
162+
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, WebApp.SiteConfig, appSettings,
163+
WebApp.SiteConfig.ConnectionStrings.
164+
ToDictionary(nvp => nvp.Name,
165+
nvp => new ConnStringValueTypePair
166+
{
167+
Type = nvp.Type.Value,
168+
Value = nvp.ConnectionString
169+
},
170+
StringComparer.OrdinalIgnoreCase));
171+
}
172+
173+
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, site);
174+
}
138175

139176
if (parameters.Contains("AppServicePlan"))
140177
{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public static class CmdletHelpers
2828
"NumberOfWorkers"
2929
};
3030

31+
public static HashSet<string> SiteParameters = new HashSet<string>
32+
{
33+
"HttpsOnly",
34+
"AssignIdentity"
35+
};
36+
3137
private static readonly Regex AppWithSlotNameRegex = new Regex(@"^(?<siteName>[^\(]+)/(?<slotName>[^\)]+)$");
3238

3339
private static readonly Regex WebAppResourceIdRegex =
@@ -284,8 +290,8 @@ internal static void ExtractWebAppPropertiesFromWebApp(Site webapp, out string r
284290

285291
string webAppNameTemp, slotNameTemp;
286292
if (TryParseAppAndSlotNames(
287-
webapp.Name,
288-
out webAppNameTemp,
293+
webapp.Name,
294+
out webAppNameTemp,
289295
out slotNameTemp))
290296
{
291297
webAppName = webAppNameTemp;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,19 @@ public HostingEnvironmentProfile CreateHostingEnvironmentProfile(string resource
9494
return CmdletHelpers.CreateHostingEnvironmentProfile(WrappedWebsitesClient.SubscriptionId, resourceGroupName, aseResourceGroupName, aseName);
9595
}
9696

97-
public void UpdateWebApp(string resourceGroupName, string location, string webAppName, string slotName, string appServicePlan)
97+
public void UpdateWebApp(string resourceGroupName, string location, string webAppName, string slotName, string appServicePlan, Site siteEnvelope =null)
9898
{
9999
var webSiteToUpdate = new Site()
100100
{
101101
ServerFarmId = appServicePlan,
102-
Location = location
102+
Location = location,
103103
};
104104

105+
if (siteEnvelope!=null)
106+
{
107+
webSiteToUpdate = siteEnvelope;
108+
}
109+
105110
string qualifiedSiteName;
106111
if (CmdletHelpers.ShouldUseDeploymentSlot(webAppName, slotName, out qualifiedSiteName))
107112
{
@@ -216,7 +221,7 @@ public Site GetWebApp(string resourceGroupName, string webSiteName, string slotN
216221
WrappedWebsitesClient.WebApps().GetSlot(resourceGroupName, webSiteName, slotName) :
217222
WrappedWebsitesClient.WebApps().Get(resourceGroupName, webSiteName);
218223

219-
GetWebAppConfiguration(resourceGroupName, webSiteName, slotName, site);
224+
GetWebAppConfiguration(resourceGroupName, webSiteName, slotName, site);
220225

221226
return site;
222227
}

src/ResourceManager/Websites/Commands.Websites/Validations/ValidateServerFarmAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void ValidateSku(SkuDescription sku)
4949
throw new ValidationMetadataException("Argument 'ServerFarm.SKU.Name' must conform to format first letter of sku name and numerical value of worker size. Worker Size [Small = 1, Medium = 2, Large = 3, ExtraLarge = 4] For instance, F1 means free small workers, P3 means premium large workers. ");
5050
}
5151

52-
const string tierPattern = "^(Free|Shared|Basic|Standard|Premium)$";
52+
const string tierPattern = "^(Free|Shared|Basic|Standard|Premium|Isolated)$";
5353
if (!Regex.IsMatch(sku.Tier, tierPattern, RegexOptions.IgnoreCase))
5454
{
5555
throw new ValidationMetadataException("Argument 'ServerFarm.SKU.Tier' must be one of Free|Shared|Basic|Standard|Premium");
@@ -58,7 +58,7 @@ private void ValidateSku(SkuDescription sku)
5858
var firstLetter = string.Equals("Shared", sku.Tier, StringComparison.OrdinalIgnoreCase) ? 'D' : sku.Tier[0];
5959
if (char.ToUpperInvariant(firstLetter) != char.ToUpperInvariant(sku.Name[0]))
6060
{
61-
throw new ValidationMetadataException(string.Format("Arguments 'ServerFarm.SKU.Name' and 'ServerFarm.SKU.Tier' must point to the same tier. [F = Free, D = Shared, B = Basic, S = Standard, P = Premium]. Current values: SKU.Name = {0}, SKU.Tier = {1}", sku.Name, sku.Tier));
61+
throw new ValidationMetadataException(string.Format("Arguments 'ServerFarm.SKU.Name' and 'ServerFarm.SKU.Tier' must point to the same tier. [F = Free, D = Shared, B = Basic, S = Standard, P = Premium, I=Isolated]. Current values: SKU.Name = {0}, SKU.Tier = {1}", sku.Name, sku.Tier));
6262
}
6363
}
6464

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

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
external help file: Microsoft.Azure.Commands.Websites.dll-Help.xml
3-
Module Name: AzureRM.WebSites
3+
Module Name: AzureRM.Websites
44
ms.assetid: 4166119F-D26A-45A1-B040-D7B2459833D6
55
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.websites/set-azurermwebapp
66
schema: 2.0.0
@@ -21,16 +21,16 @@ 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>]
25-
[-ResourceGroupName] <String> [-Name] <String> [-AsJob]
26-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
24+
[[-AutoSwapSlotName] <String>] [-HostNames <String[]>] [-NumberOfWorkers <Int32>] [-AsJob] [-AssignIdentity]
25+
[-HttpsOnly] [-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
26+
[<CommonParameters>]
2727
```
2828

2929
### S2
3030
```
3131
Set-AzureRmWebApp [[-Use32BitWorkerProcess] <Boolean>] [[-AutoSwapSlotName] <String>]
32-
[-NumberOfWorkers <Int32>] [-WebApp] <Site> [-AsJob]
33-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
32+
[-NumberOfWorkers <Int32>] [-AsJob] [-WebApp] <Site> [-DefaultProfile <IAzureContextContainer>]
33+
[<CommonParameters>]
3434
```
3535

3636
## DESCRIPTION
@@ -77,6 +77,36 @@ Accept pipeline input: False
7777
Accept wildcard characters: False
7878
```
7979
80+
### -AsJob
81+
Run cmdlet in the background
82+
83+
```yaml
84+
Type: SwitchParameter
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: False
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
95+
### -AssignIdentity
96+
Enable MSI on an existing azure webapp or functionapp
97+
98+
```yaml
99+
Type: SwitchParameter
100+
Parameter Sets: S1
101+
Aliases:
102+
103+
Required: False
104+
Position: Named
105+
Default value: None
106+
Accept pipeline input: False
107+
Accept wildcard characters: False
108+
```
109+
80110
### -AutoSwapSlotName
81111
Destination slot name for auto swap
82112
@@ -197,6 +227,21 @@ Accept pipeline input: False
197227
Accept wildcard characters: False
198228
```
199229
230+
### -HttpsOnly
231+
Enable/disable redirecting all traffic to HTTPS on an existing azure webapp or functionapp
232+
233+
```yaml
234+
Type: SwitchParameter
235+
Parameter Sets: S1
236+
Aliases:
237+
238+
Required: False
239+
Position: Named
240+
Default value: None
241+
Accept pipeline input: False
242+
Accept wildcard characters: False
243+
```
244+
200245
### -ManagedPipelineMode
201246
Managed Pipeline Mode Name
202247
@@ -348,21 +393,6 @@ Accept pipeline input: False
348393
Accept wildcard characters: False
349394
```
350395
351-
### -AsJob
352-
Run cmdlet in the background
353-
354-
```yaml
355-
Type: SwitchParameter
356-
Parameter Sets: (All)
357-
Aliases:
358-
359-
Required: False
360-
Position: Named
361-
Default value: None
362-
Accept pipeline input: False
363-
Accept wildcard characters: False
364-
```
365-
366396
### CommonParameters
367397
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
368398

tools/AzureRM/AzureRM.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Placeholder for script template
1+
# Placeholder for script template

0 commit comments

Comments
 (0)