Skip to content

Commit 9f77587

Browse files
authored
Merge pull request #7213 from chandrasekarsrinivasan/serviceendpoint
Bug fix in Service Endpoint policies
2 parents ad20f74 + dfa2bcd commit 9f77587

File tree

8 files changed

+128
-45
lines changed

8 files changed

+128
-45
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/VirtualNetworkTests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ function Test-VirtualNetworkSubnetServiceEndpointPolicies
785785
$serviceEndpointPolicyDefinitionDescription = "New Policy"
786786
$serviceEndpointPolicyName = "ServiceEndpointPolicy1"
787787
$serviceEndpointPolicyDefinitionResourceName = "/subscriptions/subid1/resourceGroups/storageRg/providers/Microsoft.Storage/storageAccounts/stAccount"
788+
$provisioningStateSucceeded = "Succeeded"
788789

789790
try
790791
{
@@ -802,6 +803,14 @@ function Test-VirtualNetworkSubnetServiceEndpointPolicies
802803
Assert-AreEqual $serviceEndpointPolicyDefinitionName $getserviceEndpointPolicy[0].ServiceEndpointPolicyDefinitions[0].Name;
803804
Assert-AreEqual $serviceEndpointPolicyDefinitionDescription $getserviceEndpointPolicy[0].ServiceEndpointPolicyDefinitions[0].Description;
804805
Assert-AreEqual $serviceEndpointPolicyDefinitionResourceName $getserviceEndpointPolicy[0].ServiceEndpointPolicyDefinitions[0].ServiceResources[0];
806+
Assert-AreEqual $getserviceEndpointPolicy[0].ProvisioningState $provisioningStateSucceeded;
807+
808+
$getserviceEndpointPolicyDefinition = Get-AzureRmServiceEndpointPolicyDefinition -Name $serviceEndpointPolicyDefinitionName -ServiceEndpointPolicy $getserviceEndpointPolicy
809+
810+
Assert-AreEqual $getserviceEndpointPolicyDefinition[0].Name $serviceEndpointPolicyDefinitionName;
811+
Assert-AreEqual $getserviceEndpointPolicyDefinition[0].ProvisioningState $provisioningStateSucceeded;
812+
Assert-AreEqual $getserviceEndpointPolicyDefinition[0].ServiceResources[0] $serviceEndpointPolicyDefinitionResourceName;
813+
Assert-AreEqual $getserviceEndpointPolicyDefinition[0].Service $serviceEndpoint;
805814

806815
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -ServiceEndpoint $serviceEndpoint -ServiceEndpointPolicy $serviceEndpointPolicy;
807816
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet;

src/ResourceManager/Network/Commands.Network/Microsoft.Azure.Commands.Network.format.ps1xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,10 @@
14101410
<Label>ServiceEndpointPolicyDefinitions</Label>
14111411
<PropertyName>ServiceEndpointPolicyDefinitionsText</PropertyName>
14121412
</ListItem>
1413+
<ListItem>
1414+
<Label>Subnets</Label>
1415+
<PropertyName>SubnetsText</PropertyName>
1416+
</ListItem>
14131417
</ListItems>
14141418
</ListEntry>
14151419
</ListEntries>
@@ -1428,14 +1432,6 @@
14281432
<Label>Name</Label>
14291433
<PropertyName>Name</PropertyName>
14301434
</ListItem>
1431-
<ListItem>
1432-
<Label>ResourceGroupName</Label>
1433-
<PropertyName>ResourceGroupName</PropertyName>
1434-
</ListItem>
1435-
<ListItem>
1436-
<Label>Location</Label>
1437-
<PropertyName>Location</PropertyName>
1438-
</ListItem>
14391435
<ListItem>
14401436
<Label>Id</Label>
14411437
<PropertyName>Id</PropertyName>
@@ -1444,10 +1440,6 @@
14441440
<Label>Etag</Label>
14451441
<PropertyName>Etag</PropertyName>
14461442
</ListItem>
1447-
<ListItem>
1448-
<Label>ResourceGuid</Label>
1449-
<PropertyName>ResourceGuid</PropertyName>
1450-
</ListItem>
14511443
<ListItem>
14521444
<Label>ProvisioningState</Label>
14531445
<PropertyName>ProvisioningState</PropertyName>
Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,58 @@
1-
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
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+
// ----------------------------------------------------------------------------------
714

815
namespace Microsoft.Azure.Commands.Network.Models
916
{
17+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
18+
using Newtonsoft.Json;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
1025
public class PSServiceEndpointPolicy : PSTopLevelResource
1126
{
1227
[JsonProperty(Order = 1)]
1328
public List<PSServiceEndpointPolicyDefinition> ServiceEndpointPolicyDefinitions { get; set; }
1429

30+
[JsonProperty(Order = 1)]
31+
public List<PSSubnet> Subnets { get; set; }
32+
1533
[JsonIgnore]
1634
public string ServiceEndpointPolicyDefinitionsText
1735
{
1836
get { return JsonConvert.SerializeObject(ServiceEndpointPolicyDefinitions, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
1937
}
38+
39+
[JsonIgnore]
40+
public string SubnetsText
41+
{
42+
get { return JsonConvert.SerializeObject(Subnets, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
43+
}
44+
45+
[Ps1Xml(Target = ViewControl.Table)]
46+
public string ProvisioningState { get; set; }
47+
48+
public bool ShouldSerializeSubnets()
49+
{
50+
return !string.IsNullOrEmpty(this.Name);
51+
}
52+
53+
public bool ShouldSerializeServiceEndpointPolicyDefinitions()
54+
{
55+
return !string.IsNullOrEmpty(this.Name);
56+
}
2057
}
2158
}

src/ResourceManager/Network/Commands.Network/Models/PSServiceEndpointPolicyDefinition.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Microsoft.Azure.Commands.Network.Models
1616
{
17+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
1718
using Newtonsoft.Json;
1819
using System.Collections.Generic;
1920

@@ -27,5 +28,8 @@ public class PSServiceEndpointPolicyDefinition : PSChildResource
2728

2829
[JsonProperty(Order = 1)]
2930
public List<string> serviceResources { get; set; }
31+
32+
[Ps1Xml(Target = ViewControl.Table)]
33+
public string ProvisioningState { get; set; }
3034
}
3135
}

src/ResourceManager/Network/Commands.Network/Models/PSSubnet.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class PSSubnet : PSChildResource
4141
[JsonProperty(Order = 1)]
4242
public List<PSServiceEndpoint> ServiceEndpoints { get; set; }
4343

44+
[JsonProperty(Order = 1)]
4445
public List<PSServiceEndpointPolicy> ServiceEndpointPolicies { get; set; }
4546

4647
[JsonProperty(Order = 1)]
@@ -76,7 +77,22 @@ public bool ShouldSerializeIpConfigurations()
7677
return !string.IsNullOrEmpty(this.Name);
7778
}
7879

79-
[JsonIgnore]
80+
public bool ShouldSerializeServiceEndpointPolicies()
81+
{
82+
return !string.IsNullOrEmpty(this.Name);
83+
}
84+
85+
public bool ShouldSerializeServiceEndpoints()
86+
{
87+
return !string.IsNullOrEmpty(this.Name);
88+
}
89+
90+
public bool ShouldSerializeResourceNavigationLinks()
91+
{
92+
return !string.IsNullOrEmpty(this.Name);
93+
}
94+
95+
[JsonIgnore]
8096
public string ServiceEndpointText
8197
{
8298
get { return JsonConvert.SerializeObject(ServiceEndpoints, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }

src/ResourceManager/Network/Commands.Network/ServiceEndpointPolicy/ServiceEndpointPolicyDefinition/GetAzureServiceEndpointPolicyDefinitionCommand.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Network.Models;
1616
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
17+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
1718
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1819
using System.Linq;
1920
using System.Management.Automation;
@@ -24,7 +25,7 @@ namespace Microsoft.Azure.Commands.Network
2425
public class GetAzureServiceEndpointPolicyDefinitionCommand : NetworkBaseCmdlet
2526
{
2627
[Parameter(
27-
Mandatory = false,
28+
Mandatory = true,
2829
HelpMessage = "The name of the service endpoint policy definition")]
2930
public string Name { get; set; }
3031

@@ -34,8 +35,9 @@ public class GetAzureServiceEndpointPolicyDefinitionCommand : NetworkBaseCmdlet
3435
HelpMessage = "The Service endpoint policy")]
3536
public PSServiceEndpointPolicy ServiceEndpointPolicy { get; set; }
3637

38+
[CmdletParameterBreakingChange("ResourceId", ChangeDescription = "Parameter is being deprecated without being replaced")]
3739
[Parameter(
38-
Mandatory = true,
40+
Mandatory = false,
3941
ValueFromPipelineByPropertyName = true,
4042
ParameterSetName = "GetByResourceIdParameterSet")]
4143
[ValidateNotNullOrEmpty]
@@ -45,12 +47,6 @@ public override void Execute()
4547
{
4648
if (this.ShouldProcess(Name, VerbsLifecycle.Restart))
4749
{
48-
if (this.IsParameterBound(c => c.ResourceId))
49-
{
50-
var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
51-
this.Name = resourceIdentifier.ResourceName;
52-
}
53-
5450
base.Execute();
5551
var definitions = this.ServiceEndpointPolicy.ServiceEndpointPolicyDefinitions;
5652

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
external help file: Microsoft.Azure.Commands.Network.dll-Help.xml
33
Module Name: AzureRM.Network
4-
online version:https://docs.microsoft.com/en-us/powershell/module/azurerm.network/get-azurermserviceendpointpolicydefinition
4+
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.network/get-azurermserviceendpointpolicydefinition
55
schema: 2.0.0
66
---
77

@@ -14,7 +14,7 @@ schema: 2.0.0
1414

1515
```
1616
Get-AzureRmServiceEndpointPolicyDefinition [-Name <String>] -ServiceEndpointPolicy <PSServiceEndpointPolicy>
17-
[-DefaultRules] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
17+
-ResourceId <String> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -24,18 +24,18 @@ The **Get-AzureRmServiceEndpointPolicyDefinition** cmdlet gets a service endpoin
2424

2525
### Example 1
2626
```
27-
$policydef= Get-AzureRmServiceEndpointPolicyDefinition -Name "ServiceEndpointPolicyDefinition1"
27+
$policydef= Get-AzureRmServiceEndpointPolicyDefinition -Name "ServiceEndpointPolicyDefinition1" -ServiceEndpointPolicy $Policy
2828
```
2929

30-
This command gets the service endpoint policy definition named ServiceEndpointPolicyDefinition1 stores it in the $policydef variable.
30+
This command gets the service endpoint policy definition named ServiceEndpointPolicyDefinition1 in ServiceEndpointPolicy $Policy stores it in the $policydef variable.
3131

3232
## PARAMETERS
3333

3434
### -DefaultProfile
3535
The credentials, account, tenant, and subscription used for communication with azure.
3636

3737
```yaml
38-
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer
38+
Type: IAzureContextContainer
3939
Parameter Sets: (All)
4040
Aliases: AzureRmContext, AzureCredential
4141

@@ -46,11 +46,11 @@ Accept pipeline input: False
4646
Accept wildcard characters: False
4747
```
4848
49-
### -DefaultRules
50-
{{Fill DefaultRules Description}}
49+
### -Name
50+
The name of the service endpoint policy definition
5151
5252
```yaml
53-
Type: SwitchParameter
53+
Type: String
5454
Parameter Sets: (All)
5555
Aliases:
5656

@@ -61,26 +61,26 @@ Accept pipeline input: False
6161
Accept wildcard characters: False
6262
```
6363
64-
### -Name
65-
The name of the service endpoint policy definition
64+
### -ResourceId
65+
{{Fill ResourceId Description}}
6666
6767
```yaml
68-
Type: System.String
68+
Type: String
6969
Parameter Sets: (All)
7070
Aliases:
7171

72-
Required: False
72+
Required: True
7373
Position: Named
7474
Default value: None
75-
Accept pipeline input: False
75+
Accept pipeline input: True (ByPropertyName)
7676
Accept wildcard characters: False
7777
```
7878
7979
### -ServiceEndpointPolicy
8080
The Service endpoint policy
8181
8282
```yaml
83-
Type: Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy
83+
Type: PSServiceEndpointPolicy
8484
Parameter Sets: (All)
8585
Aliases:
8686

@@ -91,20 +91,47 @@ Accept pipeline input: True (ByValue)
9191
Accept wildcard characters: False
9292
```
9393
94+
### -Confirm
95+
Prompts you for confirmation before running the cmdlet.
96+
97+
```yaml
98+
Type: SwitchParameter
99+
Parameter Sets: (All)
100+
Aliases: cf
101+
102+
Required: False
103+
Position: Named
104+
Default value: None
105+
Accept pipeline input: False
106+
Accept wildcard characters: False
107+
```
108+
109+
### -WhatIf
110+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
111+
112+
```yaml
113+
Type: SwitchParameter
114+
Parameter Sets: (All)
115+
Aliases: wi
116+
117+
Required: False
118+
Position: Named
119+
Default value: None
120+
Accept pipeline input: False
121+
Accept wildcard characters: False
122+
```
123+
94124
### CommonParameters
95-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
96-
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
125+
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).
97126
98127
## INPUTS
99128
100129
### Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy
101130
102-
103131
## OUTPUTS
104132
105133
### Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicyDefinition
106134
107-
108135
## NOTES
109136
110137
## RELATED LINKS

tools/StaticAnalysis/Exceptions/AzureRM.Network/BreakingChangeIssues.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@
5151
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.AddAzureVirtualNetworkSubnetConfigCommand","Add-AzureRmVirtualNetworkSubnetConfig","0","2020","The cmdlet 'Add-AzureRmVirtualNetworkSubnetConfig' no longer supports the type 'System.String' for parameter 'AddressPrefix'.","Change the type for parameter 'AddressPrefix' back to 'System.String'."
5252
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkSubnetConfigCommand","New-AzureRmVirtualNetworkSubnetConfig","0","3000","The type of property 'AddressPrefix' of type 'Microsoft.Azure.Commands.Network.Models.PSSubnet' has changed from 'System.String' to 'System.Collections.Generic.List`1[System.String]'.","Change the type of property 'AddressPrefix' back to 'System.String'."
5353
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkSubnetConfigCommand","New-AzureRmVirtualNetworkSubnetConfig","0","2020","The cmdlet 'New-AzureRmVirtualNetworkSubnetConfig' no longer supports the type 'System.String' for parameter 'AddressPrefix'.","Change the type for parameter 'AddressPrefix' back to 'System.String'."
54+
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.GetAzureServiceEndpointPolicyDefinitionCommand","Get-AzureRmServiceEndpointPolicyDefinition","0","1050","The parameter set '__AllParameterSets' for cmdlet 'Get-AzureRmServiceEndpointPolicyDefinition' has been removed.","Add parameter set '__AllParameterSets' back to cmdlet 'Get-AzureRmServiceEndpointPolicyDefinition'."
55+
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.GetAzureServiceEndpointPolicyDefinitionCommand","Get-AzureRmServiceEndpointPolicyDefinition","0","1050","The parameter set 'GetByResourceIdParameterSet' for cmdlet 'Get-AzureRmServiceEndpointPolicyDefinition' has been removed.","Add parameter set 'GetByResourceIdParameterSet' back to cmdlet 'Get-AzureRmServiceEndpointPolicyDefinition'."

0 commit comments

Comments
 (0)