Skip to content

Commit a4cdc7d

Browse files
madsdmsJinLei
andauthored
[App Service] Access restriction deterministic remove (#15037)
* Fix #14869 * Update ChangeLog.md polish change log Co-authored-by: Jin Lei <[email protected]>
1 parent 8e11533 commit a4cdc7d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Websites/Websites/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed issue that prevented removing rules by name and unique identifier in `Remove-AzWebAppAccessRestrictionRule`
2122
* updated `Set-AzAppServicePlan` to keep existing Tags when adding new Tags
2223
* Fixed `Set-AzWebApp` to set the AppSettings
2324
* updated `Set-AzWebAppSlot` to set FtpsState

src/Websites/Websites/Cmdlets/AccessRestriction/RemoveAzureWebAppAccessRestrictionRule.cs

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

1515

16+
using System;
1617
using Microsoft.Azure.Commands.WebApps.Models;
1718
using System.Management.Automation;
1819
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -100,6 +101,11 @@ public override void ExecuteCmdlet()
100101
var accessRestrictionList = TargetScmSite ? siteConfig.ScmIpSecurityRestrictions : siteConfig.IpSecurityRestrictions;
101102
IpSecurityRestriction ipSecurityRestriction = null;
102103
bool accessRestrictionExists = false;
104+
int ruleTypes = Convert.ToInt32(!string.IsNullOrWhiteSpace(IpAddress)) + Convert.ToInt32(!string.IsNullOrWhiteSpace(ServiceTag)) +
105+
Convert.ToInt32(!string.IsNullOrWhiteSpace(SubnetId) || (!string.IsNullOrWhiteSpace(SubnetName) && !string.IsNullOrWhiteSpace(VirtualNetworkName)));
106+
107+
if (ruleTypes > 1)
108+
throw new Exception("Please specify only one of: IpAddress or ServiceTag or Subnet");
103109

104110
foreach (var accessRestriction in accessRestrictionList)
105111
{
@@ -117,7 +123,7 @@ public override void ExecuteCmdlet()
117123
if (!string.IsNullOrWhiteSpace(accessRestriction.IpAddress) && accessRestriction.IpAddress.ToLowerInvariant() == IpAddress.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
118124
{
119125
if (!string.IsNullOrWhiteSpace(Name))
120-
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
126+
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() != Name.ToLowerInvariant())
121127
continue;
122128

123129
ipSecurityRestriction = accessRestriction;
@@ -130,7 +136,7 @@ public override void ExecuteCmdlet()
130136
if (!string.IsNullOrWhiteSpace(accessRestriction.IpAddress) && accessRestriction.IpAddress.ToLowerInvariant() == ServiceTag.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
131137
{
132138
if (!string.IsNullOrWhiteSpace(Name))
133-
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
139+
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() != Name.ToLowerInvariant())
134140
continue;
135141

136142
ipSecurityRestriction = accessRestriction;
@@ -145,7 +151,7 @@ public override void ExecuteCmdlet()
145151
if (!string.IsNullOrWhiteSpace(accessRestriction.VnetSubnetResourceId) && accessRestriction.VnetSubnetResourceId.ToLowerInvariant() == subnetResourceId.ToLowerInvariant() && accessRestriction.Action.ToLowerInvariant() == Action.ToLowerInvariant())
146152
{
147153
if (!string.IsNullOrWhiteSpace(Name))
148-
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() == Name.ToLowerInvariant())
154+
if (!string.IsNullOrWhiteSpace(accessRestriction.Name) && accessRestriction.Name.ToLowerInvariant() != Name.ToLowerInvariant())
149155
continue;
150156

151157
ipSecurityRestriction = accessRestriction;

0 commit comments

Comments
 (0)