Skip to content

Commit f231a35

Browse files
Add suggestion for parameter of PrivateEndPoint cmdlet (#12948)
* Add Suggestion and New ParameterSet 1.Add Suggestion to Parameter 'PrivateLinkResourceType' 2.Change the ParameterSet 'ByResource' of the Cmdlet 'PrivateLinkResourceType' 3.Add ParameterSet to Cmdlet 'Get-AzPrivateLinkResource' * fix one issue * update the version of Appconfiguration * Revert "update the version of Appconfiguration" This reverts commit 86b5706. * Update the MarkDown file * Update the BreackingChangeIssues.csv * Fix the get-privateEndPoint issue. * Update the Markdown file and improve code quality * Remove parameter definition in NewWorkBaseCmdlet Co-authored-by: Dingmeng Xue <[email protected]>
1 parent ca2a601 commit f231a35

File tree

7 files changed

+202
-33
lines changed

7 files changed

+202
-33
lines changed

src/Network/Network/PrivateLinkService/PrivateEndpointConnection/GetAzurePrivateEndpointConnection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace Microsoft.Azure.Commands.Network
2424
{
2525
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PrivateEndpointConnection", DefaultParameterSetName = "ByResourceId"), OutputType(typeof(PSPrivateEndpointConnection))]
26-
public class GetAzurePrivateEndpointConnection : PrivateEndpointConnectionBaseCmdlet
26+
public class GetAzurePrivateEndpointConnection : PrivateEndpointConnectionBaseCmdlet, IDynamicParameters
2727
{
2828
[Parameter(
2929
Mandatory = true,
@@ -60,6 +60,11 @@ public override void Execute()
6060
this.PrivateLinkResourceType = resourceIdentifier.ResourceType;
6161
this.ServiceName = resourceIdentifier.ResourceName;
6262
}
63+
else if (this.IsParameterBound(c => c.PrivateLinkResourceType))
64+
{
65+
this.Subscription = DefaultProfile.DefaultContext.Subscription.Id;
66+
this.PrivateLinkResourceType = DynamicParameters[privateEndpointTypeName].Value as string;
67+
}
6368

6469
IPrivateLinkProvider provider = BuildProvider(this.Subscription, this.PrivateLinkResourceType);
6570

src/Network/Network/PrivateLinkService/PrivateEndpointConnection/PrivateEndpointConnectionBaseCmdlet.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace Microsoft.Azure.Commands.Network
2020
{
21-
public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet
21+
public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet, IDynamicParameters
2222
{
2323
[Parameter(
2424
Mandatory = true,
@@ -37,14 +37,6 @@ public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet
3737
[SupportsWildcards]
3838
public virtual string Name { get; set; }
3939

40-
[Parameter(
41-
Mandatory = true,
42-
ValueFromPipelineByPropertyName = true,
43-
HelpMessage = "The private link service name.",
44-
ParameterSetName = "ByResource")]
45-
[ValidateNotNullOrEmpty]
46-
public string ServiceName { get; set; }
47-
4840
[Parameter(
4941
Mandatory = true,
5042
ValueFromPipelineByPropertyName = true,
@@ -55,10 +47,29 @@ public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet
5547
public virtual string ResourceGroupName { get; set; }
5648

5749
[Parameter(
58-
Mandatory = false,
50+
Mandatory = true,
5951
ValueFromPipelineByPropertyName = true,
60-
HelpMessage = "The private link resource type.",
61-
ParameterSetName = "ByResource")]
52+
HelpMessage = "The private link service name.",
53+
ParameterSetName = "ByResource")]
54+
[ValidateNotNullOrEmpty]
55+
public string ServiceName { get; set; }
56+
57+
protected RuntimeDefinedParameterDictionary DynamicParameters;
58+
59+
public const string privateEndpointTypeName = "PrivateLinkResourceType";
60+
string NamedContextParameterSet = "ByResource";
61+
public object GetDynamicParameters()
62+
{
63+
var parameters = new RuntimeDefinedParameterDictionary();
64+
RuntimeDefinedParameter namedParameter;
65+
if (ProviderConfiguration.TryGetProvideServiceParameter(privateEndpointTypeName, NamedContextParameterSet, out namedParameter))
66+
{
67+
parameters.Add(privateEndpointTypeName, namedParameter);
68+
}
69+
DynamicParameters = parameters;
70+
return parameters;
71+
}
72+
6273
public string PrivateLinkResourceType { get; set; }
6374

6475
public string Subscription { get; set; }

src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
using Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkServiceProvider;
1717
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
1818
using Microsoft.Azure.Management.Network.Models;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1920
using System;
2021
using System.Management.Automation;
2122

2223
namespace Microsoft.Azure.Commands.Network
2324
{
2425
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PrivateLinkResource", DefaultParameterSetName = "ByPrivateLinkResourceId"), OutputType(typeof(PSPrivateLinkResource))]
25-
public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet
26+
public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet, IDynamicParameters
2627
{
2728
[Parameter(
2829
Mandatory = true,
@@ -31,22 +32,63 @@ public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet
3132
[ValidateNotNullOrEmpty]
3233
public string PrivateLinkResourceId { get; set; }
3334

35+
[Parameter(
36+
Mandatory = true,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "The resource group name.",
39+
ParameterSetName = "ByResource")]
40+
[ValidateNotNullOrEmpty]
41+
public virtual string ResourceGroupName { get; set; }
42+
43+
[Parameter(
44+
Mandatory = true,
45+
ValueFromPipelineByPropertyName = true,
46+
HelpMessage = "The private link service name.",
47+
ParameterSetName = "ByResource")]
48+
[ValidateNotNullOrEmpty]
49+
public string ServiceName { get; set; }
50+
51+
public string PrivateLinkResourceType { get; set; }
52+
string NamedContextParameterSet = "ByResource";
53+
private RuntimeDefinedParameterDictionary DynamicParameters;
54+
public const string privateEndpointTypeName = "PrivateLinkResourceType";
55+
public string Subscription { get; set; }
56+
57+
public object GetDynamicParameters()
58+
{
59+
var parameters = new RuntimeDefinedParameterDictionary();
60+
RuntimeDefinedParameter namedParameter;
61+
if (ProviderConfiguration.TryGetProvideServiceParameter(privateEndpointTypeName, NamedContextParameterSet, out namedParameter))
62+
{
63+
parameters.Add(privateEndpointTypeName, namedParameter);
64+
}
65+
DynamicParameters = parameters;
66+
return parameters;
67+
}
68+
3469
public override void Execute()
3570
{
3671
base.Execute();
37-
38-
var resourceIdentifier = new ResourceIdentifier(this.PrivateLinkResourceId);
39-
string ResourceGroupName = resourceIdentifier.ResourceGroupName;
40-
string Name = resourceIdentifier.ResourceName;
41-
string ResourceType = resourceIdentifier.ResourceType;
42-
43-
IPrivateLinkProvider provider = PrivateLinkProviderFactory.CreatePrivateLinkProvder(this, resourceIdentifier.Subscription, ResourceType);
72+
if (this.IsParameterBound(c => c.PrivateLinkResourceId))
73+
{
74+
var resourceIdentifier = new ResourceIdentifier(this.PrivateLinkResourceId);
75+
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
76+
this.ServiceName = resourceIdentifier.ResourceName;
77+
this.PrivateLinkResourceType = resourceIdentifier.ResourceType;
78+
this.Subscription = resourceIdentifier.Subscription;
79+
}
80+
else
81+
{
82+
this.Subscription = DefaultProfile.DefaultContext.Subscription.Id;
83+
this.PrivateLinkResourceType = DynamicParameters[privateEndpointTypeName].Value as string;
84+
}
85+
IPrivateLinkProvider provider = PrivateLinkProviderFactory.CreatePrivateLinkProvder(this, Subscription, PrivateLinkResourceType);
4486
if (provider == null)
4587
{
4688
throw new ArgumentException(string.Format(Properties.Resources.InvalidResourceId, this.PrivateLinkResourceId));
4789
}
48-
49-
var plrs = provider.ListPrivateLinkResource(ResourceGroupName, Name);
90+
91+
var plrs = provider.ListPrivateLinkResource(ResourceGroupName, ServiceName);
5092
WriteObject(plrs, true);
5193

5294
}

src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Management.Automation;
36
using System.Text;
47

58
namespace Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkServiceProvider
@@ -50,5 +53,35 @@ public static ProviderConfiguration GetProviderConfiguration(string type)
5053
{
5154
return _configurations[type];
5255
}
56+
57+
/// <summary>
58+
/// Generate a runtime parameter with ValidateSet matching the current context
59+
/// </summary>
60+
/// <param name="name">The name of the parameter</param>
61+
/// <param name="runtimeParameter">The returned runtime parameter for context, with appropriate validate set</param>
62+
/// <returns>True if one or more contexts were found, otherwise false</returns>
63+
public static bool TryGetProvideServiceParameter(string name, string parameterSetName, out RuntimeDefinedParameter runtimeParameter)
64+
{
65+
var result = false;
66+
runtimeParameter = null;
67+
if (_configurations != null && _configurations.Values != null)
68+
{
69+
var ObjArray = _configurations.Values.ToArray();
70+
var ProvideTypeList = ObjArray.Select(c => c.Type).ToArray();
71+
runtimeParameter = new RuntimeDefinedParameter(
72+
name, typeof(string),
73+
new Collection<Attribute>()
74+
{
75+
new ParameterAttribute { Mandatory = false,
76+
ValueFromPipeline = true,
77+
HelpMessage = "The private link resource type.",
78+
ParameterSetName = parameterSetName },
79+
new ValidateSetAttribute(ProvideTypeList)
80+
}
81+
);
82+
result = true;
83+
}
84+
return result;
85+
}
5386
}
5487
}

src/Network/Network/help/Get-AzPrivateEndpointConnection.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ Gets a private endpoint connection resource.
1212

1313
## SYNTAX
1414

15-
### ByPrivateLinkResourceId (Default)
15+
### ByResourceId (Default)
1616
```
17-
Get-AzPrivateEndpointConnection -PrivateLinkResourceId <String>
17+
Get-AzPrivateEndpointConnection [-Description <String>] -ResourceId <String>
1818
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

21-
### ByResourceId
21+
### ByPrivateLinkResourceId
2222
```
23-
Get-AzPrivateEndpointConnection -ResourceId <String>
23+
Get-AzPrivateEndpointConnection -PrivateLinkResourceId <String> [-Description <String>]
2424
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2525
```
2626

2727
### ByResource
2828
```
29-
Get-AzPrivateEndpointConnection -ServiceName <String> -ResourceGroupName <String>
30-
[-Name <String>] [-PrivateLinkResourceType <String>] [-Description <String>]
31-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
29+
Get-AzPrivateEndpointConnection [-Description <String>] [-Name <String>] -ResourceGroupName <String>
30+
-ServiceName <String> [-DefaultProfile <IAzureContextContainer>] [-PrivateLinkResourceType <String>]
31+
[<CommonParameters>]
3232
```
3333

3434
## DESCRIPTION
@@ -67,6 +67,21 @@ Accept pipeline input: False
6767
Accept wildcard characters: False
6868
```
6969
70+
### -Description
71+
The reason of action.
72+
73+
```yaml
74+
Type: System.String
75+
Parameter Sets: (All)
76+
Aliases:
77+
78+
Required: False
79+
Position: Named
80+
Default value: None
81+
Accept pipeline input: True (ByPropertyName)
82+
Accept wildcard characters: False
83+
```
84+
7085
### -Name
7186
The name of the private endpoint connection.
7287
@@ -104,11 +119,12 @@ The private link resource type.
104119
Type: System.String
105120
Parameter Sets: ByResource
106121
Aliases:
122+
Accepted values:
107123

108124
Required: False
109125
Position: Named
110126
Default value: 'Microsoft.Network/privateLinkServices'
111-
Accept pipeline input: True (ByPropertyName)
127+
Accept pipeline input: True (ByValue)
112128
Accept wildcard characters: False
113129
```
114130

src/Network/Network/help/Get-AzPrivateLinkResource.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ Gets a private link resource.
1414

1515
### ByPrivateLinkResourceId (Default)
1616
```
17-
Get-AzPrivateLinkResource -PrivateLinkResourceId <String>
18-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
17+
Get-AzPrivateLinkResource -PrivateLinkResourceId <String> [-DefaultProfile <IAzureContextContainer>]
18+
[<CommonParameters>]
19+
```
20+
21+
### ByResource
22+
```
23+
Get-AzPrivateLinkResource -ResourceGroupName <String> -ServiceName <String>
24+
[-DefaultProfile <IAzureContextContainer>] [-PrivateLinkResourceType <String>] [<CommonParameters>]
1925
```
2026

2127
## DESCRIPTION
@@ -62,6 +68,52 @@ Accept pipeline input: True (ByPropertyName)
6268
Accept wildcard characters: False
6369
```
6470
71+
### -PrivateLinkResourceType
72+
The private link resource type.
73+
74+
```yaml
75+
Type: System.String
76+
Parameter Sets: ByResource
77+
Aliases:
78+
Accepted values:
79+
80+
Required: False
81+
Position: Named
82+
Default value: None
83+
Accept pipeline input: True (ByValue)
84+
Accept wildcard characters: False
85+
```
86+
87+
### -ResourceGroupName
88+
The resource group name.
89+
90+
```yaml
91+
Type: System.String
92+
Parameter Sets: ByResource
93+
Aliases:
94+
95+
Required: True
96+
Position: Named
97+
Default value: None
98+
Accept pipeline input: True (ByPropertyName)
99+
Accept wildcard characters: False
100+
```
101+
102+
### -ServiceName
103+
The private link service name.
104+
105+
```yaml
106+
Type: System.String
107+
Parameter Sets: ByResource
108+
Aliases:
109+
110+
Required: True
111+
Position: Named
112+
Default value: None
113+
Accept pipeline input: True (ByPropertyName)
114+
Accept wildcard characters: False
115+
```
116+
65117
### CommonParameters
66118
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).
67119

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,16 @@
585585
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.RemoveAzureVirtualRouterCommand","Remove-AzVirtualRouter","0","3010","The property 'HostedGateway' of type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouter' has been removed.","Add the property 'HostedGateway' back to type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouter'."
586586
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.RemoveAzureVirtualRouterCommand","Remove-AzVirtualRouter","0","3010","The property 'HostedGatewayText' of type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouter' has been removed.","Add the property 'HostedGatewayText' back to type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouter'."
587587
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.GetAzureRmVirtualRouterPeer","Get-AzVirtualRouterPeer","0","3010","The property 'Type' of type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer' has been removed.","Add the property 'Type' back to type 'Microsoft.Azure.Commands.Network.Models.PSVirtualRouterPeer'."
588+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.ApproveAzurePrivateEndpointConnection","Approve-AzPrivateEndpointConnection","0","2000","The cmdlet 'Approve-AzPrivateEndpointConnection' no longer supports the parameter 'PrivateLinkResourceType' and no alias was found for the original parameter name.","Add the parameter 'PrivateLinkResourceType' back to the cmdlet 'Approve-AzPrivateEndpointConnection', or add an alias to the original parameter name."
589+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.ApproveAzurePrivateEndpointConnection","Approve-AzPrivateEndpointConnection","0","1050","The parameter set 'ByResource' for cmdlet 'Approve-AzPrivateEndpointConnection' has been removed.","Add parameter set 'ByResource' back to cmdlet 'Approve-AzPrivateEndpointConnection'."
590+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.DenyAzurePrivateEndpointConnection","Deny-AzPrivateEndpointConnection","0","2000","The cmdlet 'Deny-AzPrivateEndpointConnection' no longer supports the parameter 'PrivateLinkResourceType' and no alias was found for the original parameter name.","Add the parameter 'PrivateLinkResourceType' back to the cmdlet 'Deny-AzPrivateEndpointConnection', or add an alias to the original parameter name."
591+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.DenyAzurePrivateEndpointConnection","Deny-AzPrivateEndpointConnection","0","1050","The parameter set 'ByResource' for cmdlet 'Deny-AzPrivateEndpointConnection' has been removed.","Add parameter set 'ByResource' back to cmdlet 'Deny-AzPrivateEndpointConnection'."
592+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.GetAzurePrivateEndpointConnection","Get-AzPrivateEndpointConnection","0","2000","The cmdlet 'Get-AzPrivateEndpointConnection' no longer supports the parameter 'PrivateLinkResourceType' and no alias was found for the original parameter name.","Add the parameter 'PrivateLinkResourceType' back to the cmdlet 'Get-AzPrivateEndpointConnection', or add an alias to the original parameter name."
593+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.GetAzurePrivateEndpointConnection","Get-AzPrivateEndpointConnection","0","1050","The parameter set 'ByResource' for cmdlet 'Get-AzPrivateEndpointConnection' has been removed.","Add parameter set 'ByResource' back to cmdlet 'Get-AzPrivateEndpointConnection'."
594+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.RemoveAzurePrivateEndpointConnection","Remove-AzPrivateEndpointConnection","0","2000","The cmdlet 'Remove-AzPrivateEndpointConnection' no longer supports the parameter 'PrivateLinkResourceType' and no alias was found for the original parameter name.","Add the parameter 'PrivateLinkResourceType' back to the cmdlet 'Remove-AzPrivateEndpointConnection', or add an alias to the original parameter name."
595+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.RemoveAzurePrivateEndpointConnection","Remove-AzPrivateEndpointConnection","0","1050","The parameter set 'ByResource' for cmdlet 'Remove-AzPrivateEndpointConnection' has been removed.","Add parameter set 'ByResource' back to cmdlet 'Remove-AzPrivateEndpointConnection'."
596+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.SetAzurePrivateEndpointConnection","Set-AzPrivateEndpointConnection","0","2000","The cmdlet 'Set-AzPrivateEndpointConnection' no longer supports the parameter 'PrivateLinkResourceType' and no alias was found for the original parameter name.","Add the parameter 'PrivateLinkResourceType' back to the cmdlet 'Set-AzPrivateEndpointConnection', or add an alias to the original parameter name."
597+
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.SetAzurePrivateEndpointConnection","Set-AzPrivateEndpointConnection","0","1050","The parameter set 'ByResource' for cmdlet 'Set-AzPrivateEndpointConnection' has been removed.","Add parameter set 'ByResource' back to cmdlet 'Set-AzPrivateEndpointConnection'."
588598
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.NewAzureRmExpressRouteGatewayCommand","New-AzExpressRouteGateway","0","3010","The property 'HostedSubnet' of type 'Microsoft.Azure.Commands.Network.Models.PSHubIpConfiguration' has been removed.","Add the property 'HostedSubnet' back to type 'Microsoft.Azure.Commands.Network.Models.PSHubIpConfiguration'."
589599
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.NewAzureFirewallDnsSettingCommand","New-AzFirewallPolicyDnsSetting","0","3010","The property 'RequireProxyForNetworkRules' of type 'Microsoft.Azure.Commands.Network.Models.PSAzureFirewallPolicyDnsSettings' has been removed.","Add the property 'RequireProxyForNetworkRules' back to type 'Microsoft.Azure.Commands.Network.Models.PSAzureFirewallPolicyDnsSettings'."
590600
"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.NewAzureFirewallDnsSettingCommand","New-AzFirewallPolicyDnsSetting","0","2000","The cmdlet 'New-AzFirewallPolicyDnsSetting' no longer supports the parameter 'ProxyNotRequiredForNetworkRule' and no alias was found for the original parameter name.","Add the parameter 'ProxyNotRequiredForNetworkRule' back to the cmdlet 'New-AzFirewallPolicyDnsSetting', or add an alias to the original parameter name."

0 commit comments

Comments
 (0)