24
24
using Microsoft . Azure . Management . Internal . Network . Version2017_10_01 ;
25
25
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
26
26
using Microsoft . Azure . Management . Monitor . Version2018_09_01 . Models ;
27
+ using System . ComponentModel ;
27
28
28
29
namespace Microsoft . Azure . Commands . WebApps . Cmdlets . WebApps
29
30
{
@@ -53,9 +54,9 @@ public class AddAzureWebAppAccessRestrictionRuleCmdlet : WebAppBaseClientCmdLet
53
54
[ ValidateNotNullOrEmpty ]
54
55
public string WebAppName { get ; set ; }
55
56
56
- [ Parameter ( ParameterSetName = IpAddressParameterSet , Mandatory = true , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
57
- [ Parameter ( ParameterSetName = SubnetNameParameterSet , Mandatory = true , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
58
- [ Parameter ( ParameterSetName = SubnetIdParameterSet , Mandatory = true , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
57
+ [ Parameter ( ParameterSetName = IpAddressParameterSet , Mandatory = false , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
58
+ [ Parameter ( ParameterSetName = SubnetNameParameterSet , Mandatory = false , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
59
+ [ Parameter ( ParameterSetName = SubnetIdParameterSet , Mandatory = false , HelpMessage = "Access Restriction rule name. E.g.: DeveloperWorkstation." ) ]
59
60
[ ValidateNotNullOrEmpty ]
60
61
public string Name { get ; set ; }
61
62
@@ -68,14 +69,14 @@ public class AddAzureWebAppAccessRestrictionRuleCmdlet : WebAppBaseClientCmdLet
68
69
[ Parameter ( ParameterSetName = SubnetNameParameterSet , Mandatory = true , HelpMessage = "Access Restriction priority. E.g.: 500." ) ]
69
70
[ Parameter ( ParameterSetName = SubnetIdParameterSet , Mandatory = true , HelpMessage = "Access Restriction priority. E.g.: 500." ) ]
70
71
[ ValidateNotNullOrEmpty ]
71
- [ ValidateRange ( 100 , 65000 ) ]
72
72
public uint Priority { get ; set ; }
73
73
74
- [ Parameter ( ParameterSetName = IpAddressParameterSet , Mandatory = true , HelpMessage = "Allow or Deny rule." ) ]
75
- [ Parameter ( ParameterSetName = SubnetNameParameterSet , Mandatory = true , HelpMessage = "Allow or Deny rule." ) ]
76
- [ Parameter ( ParameterSetName = SubnetIdParameterSet , Mandatory = true , HelpMessage = "Allow or Deny rule." ) ]
74
+ [ Parameter ( ParameterSetName = IpAddressParameterSet , Mandatory = false , HelpMessage = "Allow or Deny rule." ) ]
75
+ [ Parameter ( ParameterSetName = SubnetNameParameterSet , Mandatory = false , HelpMessage = "Allow or Deny rule." ) ]
76
+ [ Parameter ( ParameterSetName = SubnetIdParameterSet , Mandatory = false , HelpMessage = "Allow or Deny rule." ) ]
77
77
[ ValidateNotNullOrEmpty ]
78
78
[ ValidateSet ( "Allow" , "Deny" ) ]
79
+ [ DefaultValue ( "Allow" ) ]
79
80
public string Action { get ; set ; }
80
81
81
82
[ Parameter ( ParameterSetName = IpAddressParameterSet , Mandatory = false , HelpMessage = "Deployment Slot name." ) ]
@@ -121,29 +122,12 @@ public override void ExecuteCmdlet()
121
122
SiteConfig siteConfig = webApp . SiteConfig ;
122
123
var accessRestrictionList = TargetScmSite ? siteConfig . ScmIpSecurityRestrictions : siteConfig . IpSecurityRestrictions ;
123
124
IpSecurityRestriction ipSecurityRestriction = null ;
124
- bool accessRestrictionExists = false ;
125
125
int intPriority = checked ( ( int ) Priority ) ;
126
126
switch ( ParameterSetName )
127
127
{
128
- case IpAddressParameterSet :
129
- foreach ( var accessRestriction in accessRestrictionList )
130
- {
131
- if ( accessRestriction . IpAddress != null &&
132
- accessRestriction . IpAddress == IpAddress &&
133
- accessRestriction . Action . ToLowerInvariant ( ) == Action . ToLowerInvariant ( ) )
134
- {
135
- accessRestrictionExists = true ;
136
- accessRestriction . Name = Name ;
137
- accessRestriction . Priority = intPriority ;
138
- accessRestriction . Description = Description ;
139
- break ;
140
- }
141
- }
142
- if ( ! accessRestrictionExists )
143
- {
144
- ipSecurityRestriction = new IpSecurityRestriction ( IpAddress , null , null , null , null , Action , null , intPriority , Name , Description ) ;
145
- accessRestrictionList . Add ( ipSecurityRestriction ) ;
146
- }
128
+ case IpAddressParameterSet :
129
+ ipSecurityRestriction = new IpSecurityRestriction ( IpAddress , null , null , null , null , Action , null , intPriority , Name , Description ) ;
130
+ accessRestrictionList . Add ( ipSecurityRestriction ) ;
147
131
break ;
148
132
149
133
case SubnetNameParameterSet :
@@ -158,29 +142,13 @@ public override void ExecuteCmdlet()
158
142
{
159
143
CmdletHelpers . VerifySubnetDelegation ( subnetResourceId ) ;
160
144
}
161
- foreach ( var accessRestriction in accessRestrictionList )
162
- {
163
- if ( accessRestriction . VnetSubnetResourceId != null &&
164
- accessRestriction . VnetSubnetResourceId . ToLowerInvariant ( ) == subnetResourceId . ToLowerInvariant ( ) &&
165
- accessRestriction . Action . ToLowerInvariant ( ) == Action . ToLowerInvariant ( ) )
166
- {
167
- accessRestrictionExists = true ;
168
- accessRestriction . Name = Name ;
169
- accessRestriction . Priority = intPriority ;
170
- accessRestriction . Description = Description ;
171
- break ;
172
- }
173
- }
174
- if ( ! accessRestrictionExists )
175
- {
176
- ipSecurityRestriction = new IpSecurityRestriction ( null , null , subnetResourceId , null , null , Action , null , intPriority , Name , Description ) ;
177
- accessRestrictionList . Add ( ipSecurityRestriction ) ;
178
- }
145
+
146
+ ipSecurityRestriction = new IpSecurityRestriction ( null , null , subnetResourceId , null , null , Action , null , intPriority , Name , Description ) ;
147
+ accessRestrictionList . Add ( ipSecurityRestriction ) ;
179
148
break ;
180
149
}
181
150
182
- string updateAction = accessRestrictionExists ? "Updating" : "Adding" ;
183
- if ( ShouldProcess ( WebAppName , $ "{ updateAction } Access Restriction Rule '{ Name } ' for Web App '{ WebAppName } '") )
151
+ if ( ShouldProcess ( WebAppName , $ "Adding Access Restriction Rule for Web App '{ WebAppName } '") )
184
152
{
185
153
// Update web app configuration
186
154
WebsitesClient . UpdateWebAppConfiguration ( ResourceGroupName , webApp . Location , WebAppName , SlotName , siteConfig ) ;
0 commit comments