diff --git a/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/GetAzurePrivateEndpointConnection.cs b/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/GetAzurePrivateEndpointConnection.cs index 6759932276ab..3aaddb3ad1b6 100644 --- a/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/GetAzurePrivateEndpointConnection.cs +++ b/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/GetAzurePrivateEndpointConnection.cs @@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.Network { [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PrivateEndpointConnection", DefaultParameterSetName = "ByResourceId"), OutputType(typeof(PSPrivateEndpointConnection))] - public class GetAzurePrivateEndpointConnection : PrivateEndpointConnectionBaseCmdlet + public class GetAzurePrivateEndpointConnection : PrivateEndpointConnectionBaseCmdlet, IDynamicParameters { [Parameter( Mandatory = true, @@ -60,6 +60,11 @@ public override void Execute() this.PrivateLinkResourceType = resourceIdentifier.ResourceType; this.ServiceName = resourceIdentifier.ResourceName; } + else if (this.IsParameterBound(c => c.PrivateLinkResourceType)) + { + this.Subscription = DefaultProfile.DefaultContext.Subscription.Id; + this.PrivateLinkResourceType = DynamicParameters[privateEndpointTypeName].Value as string; + } IPrivateLinkProvider provider = BuildProvider(this.Subscription, this.PrivateLinkResourceType); diff --git a/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/PrivateEndpointConnectionBaseCmdlet.cs b/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/PrivateEndpointConnectionBaseCmdlet.cs index 2b2894b3f6c3..49c9275ea581 100644 --- a/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/PrivateEndpointConnectionBaseCmdlet.cs +++ b/src/Network/Network/PrivateLinkService/PrivateEndpointConnection/PrivateEndpointConnectionBaseCmdlet.cs @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.Network { - public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet + public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet, IDynamicParameters { [Parameter( Mandatory = true, @@ -37,14 +37,6 @@ public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet [SupportsWildcards] public virtual string Name { get; set; } - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The private link service name.", - ParameterSetName = "ByResource")] - [ValidateNotNullOrEmpty] - public string ServiceName { get; set; } - [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, @@ -55,10 +47,29 @@ public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet public virtual string ResourceGroupName { get; set; } [Parameter( - Mandatory = false, + Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The private link resource type.", - ParameterSetName = "ByResource")] + HelpMessage = "The private link service name.", + ParameterSetName = "ByResource")] + [ValidateNotNullOrEmpty] + public string ServiceName { get; set; } + + protected RuntimeDefinedParameterDictionary DynamicParameters; + + public const string privateEndpointTypeName = "PrivateLinkResourceType"; + string NamedContextParameterSet = "ByResource"; + public object GetDynamicParameters() + { + var parameters = new RuntimeDefinedParameterDictionary(); + RuntimeDefinedParameter namedParameter; + if (ProviderConfiguration.TryGetProvideServiceParameter(privateEndpointTypeName, NamedContextParameterSet, out namedParameter)) + { + parameters.Add(privateEndpointTypeName, namedParameter); + } + DynamicParameters = parameters; + return parameters; + } + public string PrivateLinkResourceType { get; set; } public string Subscription { get; set; } diff --git a/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs b/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs index 9400e059f2d0..98ac2ccd1ab2 100644 --- a/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs +++ b/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs @@ -16,13 +16,14 @@ using Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkServiceProvider; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.Network.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; using System.Management.Automation; namespace Microsoft.Azure.Commands.Network { [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PrivateLinkResource", DefaultParameterSetName = "ByPrivateLinkResourceId"), OutputType(typeof(PSPrivateLinkResource))] - public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet + public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet, IDynamicParameters { [Parameter( Mandatory = true, @@ -31,22 +32,63 @@ public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet [ValidateNotNullOrEmpty] public string PrivateLinkResourceId { get; set; } + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", + ParameterSetName = "ByResource")] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The private link service name.", + ParameterSetName = "ByResource")] + [ValidateNotNullOrEmpty] + public string ServiceName { get; set; } + + public string PrivateLinkResourceType { get; set; } + string NamedContextParameterSet = "ByResource"; + private RuntimeDefinedParameterDictionary DynamicParameters; + public const string privateEndpointTypeName = "PrivateLinkResourceType"; + public string Subscription { get; set; } + + public object GetDynamicParameters() + { + var parameters = new RuntimeDefinedParameterDictionary(); + RuntimeDefinedParameter namedParameter; + if (ProviderConfiguration.TryGetProvideServiceParameter(privateEndpointTypeName, NamedContextParameterSet, out namedParameter)) + { + parameters.Add(privateEndpointTypeName, namedParameter); + } + DynamicParameters = parameters; + return parameters; + } + public override void Execute() { base.Execute(); - - var resourceIdentifier = new ResourceIdentifier(this.PrivateLinkResourceId); - string ResourceGroupName = resourceIdentifier.ResourceGroupName; - string Name = resourceIdentifier.ResourceName; - string ResourceType = resourceIdentifier.ResourceType; - - IPrivateLinkProvider provider = PrivateLinkProviderFactory.CreatePrivateLinkProvder(this, resourceIdentifier.Subscription, ResourceType); + if (this.IsParameterBound(c => c.PrivateLinkResourceId)) + { + var resourceIdentifier = new ResourceIdentifier(this.PrivateLinkResourceId); + this.ResourceGroupName = resourceIdentifier.ResourceGroupName; + this.ServiceName = resourceIdentifier.ResourceName; + this.PrivateLinkResourceType = resourceIdentifier.ResourceType; + this.Subscription = resourceIdentifier.Subscription; + } + else + { + this.Subscription = DefaultProfile.DefaultContext.Subscription.Id; + this.PrivateLinkResourceType = DynamicParameters[privateEndpointTypeName].Value as string; + } + IPrivateLinkProvider provider = PrivateLinkProviderFactory.CreatePrivateLinkProvder(this, Subscription, PrivateLinkResourceType); if (provider == null) { throw new ArgumentException(string.Format(Properties.Resources.InvalidResourceId, this.PrivateLinkResourceId)); } - - var plrs = provider.ListPrivateLinkResource(ResourceGroupName, Name); + + var plrs = provider.ListPrivateLinkResource(ResourceGroupName, ServiceName); WriteObject(plrs, true); } diff --git a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs index 329396dd5468..1dd23bd09dfb 100644 --- a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs +++ b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Management.Automation; using System.Text; namespace Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkServiceProvider @@ -50,5 +53,35 @@ public static ProviderConfiguration GetProviderConfiguration(string type) { return _configurations[type]; } + + /// + /// Generate a runtime parameter with ValidateSet matching the current context + /// + /// The name of the parameter + /// The returned runtime parameter for context, with appropriate validate set + /// True if one or more contexts were found, otherwise false + public static bool TryGetProvideServiceParameter(string name, string parameterSetName, out RuntimeDefinedParameter runtimeParameter) + { + var result = false; + runtimeParameter = null; + if (_configurations != null && _configurations.Values != null) + { + var ObjArray = _configurations.Values.ToArray(); + var ProvideTypeList = ObjArray.Select(c => c.Type).ToArray(); + runtimeParameter = new RuntimeDefinedParameter( + name, typeof(string), + new Collection() + { + new ParameterAttribute { Mandatory = false, + ValueFromPipeline = true, + HelpMessage = "The private link resource type.", + ParameterSetName = parameterSetName }, + new ValidateSetAttribute(ProvideTypeList) + } + ); + result = true; + } + return result; + } } } diff --git a/src/Network/Network/help/Get-AzPrivateEndpointConnection.md b/src/Network/Network/help/Get-AzPrivateEndpointConnection.md index d54003995000..7012ea3d1c4e 100644 --- a/src/Network/Network/help/Get-AzPrivateEndpointConnection.md +++ b/src/Network/Network/help/Get-AzPrivateEndpointConnection.md @@ -12,23 +12,23 @@ Gets a private endpoint connection resource. ## SYNTAX -### ByPrivateLinkResourceId (Default) +### ByResourceId (Default) ``` -Get-AzPrivateEndpointConnection -PrivateLinkResourceId +Get-AzPrivateEndpointConnection [-Description ] -ResourceId [-DefaultProfile ] [] ``` -### ByResourceId +### ByPrivateLinkResourceId ``` -Get-AzPrivateEndpointConnection -ResourceId +Get-AzPrivateEndpointConnection -PrivateLinkResourceId [-Description ] [-DefaultProfile ] [] ``` ### ByResource ``` -Get-AzPrivateEndpointConnection -ServiceName -ResourceGroupName -[-Name ] [-PrivateLinkResourceType ] [-Description ] -[-DefaultProfile ] [] +Get-AzPrivateEndpointConnection [-Description ] [-Name ] -ResourceGroupName + -ServiceName [-DefaultProfile ] [-PrivateLinkResourceType ] + [] ``` ## DESCRIPTION @@ -67,6 +67,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Description +The reason of action. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -Name The name of the private endpoint connection. @@ -104,11 +119,12 @@ The private link resource type. Type: System.String Parameter Sets: ByResource Aliases: +Accepted values: Required: False Position: Named Default value: 'Microsoft.Network/privateLinkServices' -Accept pipeline input: True (ByPropertyName) +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` diff --git a/src/Network/Network/help/Get-AzPrivateLinkResource.md b/src/Network/Network/help/Get-AzPrivateLinkResource.md index e057c29f0913..2d7f34505092 100644 --- a/src/Network/Network/help/Get-AzPrivateLinkResource.md +++ b/src/Network/Network/help/Get-AzPrivateLinkResource.md @@ -14,8 +14,14 @@ Gets a private link resource. ### ByPrivateLinkResourceId (Default) ``` -Get-AzPrivateLinkResource -PrivateLinkResourceId - [-DefaultProfile ] [] +Get-AzPrivateLinkResource -PrivateLinkResourceId [-DefaultProfile ] + [] +``` + +### ByResource +``` +Get-AzPrivateLinkResource -ResourceGroupName -ServiceName + [-DefaultProfile ] [-PrivateLinkResourceType ] [] ``` ## DESCRIPTION @@ -62,6 +68,52 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -PrivateLinkResourceType +The private link resource type. + +```yaml +Type: System.String +Parameter Sets: ByResource +Aliases: +Accepted values: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name. + +```yaml +Type: System.String +Parameter Sets: ByResource +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ServiceName +The private link service name. + +```yaml +Type: System.String +Parameter Sets: ByResource +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### CommonParameters 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). diff --git a/tools/StaticAnalysis/Exceptions/Az.Network/BreakingChangeIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Network/BreakingChangeIssues.csv index eba14ebaebf5..d3493609b7a1 100644 --- a/tools/StaticAnalysis/Exceptions/Az.Network/BreakingChangeIssues.csv +++ b/tools/StaticAnalysis/Exceptions/Az.Network/BreakingChangeIssues.csv @@ -585,6 +585,16 @@ "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'." "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'." "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'." +"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." +"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'." +"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." +"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'." +"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." +"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'." +"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." +"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'." +"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." +"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'." "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'." "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'." "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."