From 1c5d1df1d04074a0716fc77f7c5e798584d72be6 Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Mon, 26 Apr 2021 12:05:08 +0800 Subject: [PATCH] Added support for getting a single private link resource (#14785) * Added support for getting a single private link resource * update help file * Update src/Network/Network/help/Get-AzPrivateLinkResource.md * Update src/Network/Network/help/Get-AzPrivateLinkResource.md Co-authored-by: Beisi Zhou --- src/Network/Network/ChangeLog.md | 1 + .../GetAzurePrivateLinkResourceCommand.cs | 21 +++++- .../GenericProvider.cs | 14 +++- .../ProviderConfiguration.cs | 74 ++++++++++--------- .../Network/help/Get-AzPrivateLinkResource.md | 23 +++++- 5 files changed, 86 insertions(+), 47 deletions(-) diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 686da84ea690..30e3daca7ea6 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -19,6 +19,7 @@ ---> ## Upcoming Release +* Added support for getting a single private link resource. * Added more detailed description about GroupId in `New-AzPrivateLinkServiceConnection` * Updated cmdlets to enable setting of PrivateRange on AzureFirewallPolicy. - `New-AzFirewallPolicy` diff --git a/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs b/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs index 98ac2ccd1ab2..cc8b3cc27041 100644 --- a/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs +++ b/src/Network/Network/PrivateLinkService/PrivateLinkResource/GetAzurePrivateLinkResourceCommand.cs @@ -25,6 +25,7 @@ namespace Microsoft.Azure.Commands.Network [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PrivateLinkResource", DefaultParameterSetName = "ByPrivateLinkResourceId"), OutputType(typeof(PSPrivateLinkResource))] public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet, IDynamicParameters { + [Alias("PrivateLinkServiceId")] [Parameter( Mandatory = true, ParameterSetName = "ByPrivateLinkResourceId", @@ -48,6 +49,12 @@ public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet, IDynamicPar [ValidateNotNullOrEmpty] public string ServiceName { get; set; } + [Alias("GroupName")] + [Parameter( + ValueFromPipelineByPropertyName = true, + HelpMessage = "The private link resource name.")] + public string Name { get; set; } + public string PrivateLinkResourceType { get; set; } string NamedContextParameterSet = "ByResource"; private RuntimeDefinedParameterDictionary DynamicParameters; @@ -87,10 +94,16 @@ public override void Execute() { throw new ArgumentException(string.Format(Properties.Resources.InvalidResourceId, this.PrivateLinkResourceId)); } - - var plrs = provider.ListPrivateLinkResource(ResourceGroupName, ServiceName); - WriteObject(plrs, true); - + if (this.IsParameterBound(c => c.Name)) + { + var plr = provider.GetPrivateLinkResource(ResourceGroupName, ServiceName, Name); + WriteObject(plr); + } + else + { + var plrs = provider.ListPrivateLinkResource(ResourceGroupName, ServiceName); + WriteObject(plrs, true); + } } } } diff --git a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/GenericProvider.cs b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/GenericProvider.cs index 37b9c4bb8414..8bae2ce58a53 100644 --- a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/GenericProvider.cs +++ b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/GenericProvider.cs @@ -19,6 +19,7 @@ using Microsoft.Rest.Azure; using Microsoft.Azure.Internal.Common; using System.Collections.Generic; +using System.Linq; namespace Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkServiceProvider { @@ -132,9 +133,16 @@ public void DeletePrivateEndpointConnection(string resourceGroupName, string ser public PSPrivateLinkResource GetPrivateLinkResource(string resourceGroupName, string serviceName, string name) { - string url = BuildPrivateLinkResourceURL(resourceGroupName, serviceName, name); - PrivateLinkResource resource = ServiceClient.Operations.GetResource(url, _configuration.ApiVersion); - return ToPsPrivateLinkResource(resource); + if (_configuration.HasResourceURI) + { + string url = BuildPrivateLinkResourceURL(resourceGroupName, serviceName, name); + PrivateLinkResource resource = ServiceClient.Operations.GetResource(url, _configuration.ApiVersion); + return ToPsPrivateLinkResource(resource); + } + else + { + return ListPrivateLinkResource(resourceGroupName, serviceName).Single(plr => plr.Name.Equals(name)); + } } public List ListPrivateLinkResource(string resourceGroupName, string serviceName) diff --git a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs index 81b201bdcc18..6b44c9aa1549 100644 --- a/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs +++ b/src/Network/Network/PrivateLinkService/PrivateLinkServiceProvider/ProviderConfiguration.cs @@ -14,49 +14,50 @@ internal class ProviderConfiguration static ProviderConfiguration() { - RegisterConfiguration("Microsoft.Automation/automationAccounts", "2020-01-13-preview"); - RegisterConfiguration("Microsoft.AppConfiguration/configurationStores", "2020-06-01"); - RegisterConfiguration("Microsoft.Batch/batchAccounts", "2020-03-01"); - RegisterConfiguration("Microsoft.Cache/redisEnterprise", "2021-03-01"); - RegisterConfiguration("Microsoft.CognitiveServices/accounts", "2017-04-18"); - RegisterConfiguration("Microsoft.Compute/diskAccesses", "2020-09-30"); - RegisterConfiguration("Microsoft.ContainerRegistry/registries", "2019-12-01-preview"); - RegisterConfiguration("Microsoft.DBforMySQL/servers", "2018-06-01"); - RegisterConfiguration("Microsoft.DBforMariaDB/servers", "2018-06-01"); - RegisterConfiguration("Microsoft.DBforPostgreSQL/servers", "2018-06-01"); - RegisterConfiguration("Microsoft.Devices/IotHubs", "2020-03-01"); - RegisterConfiguration("Microsoft.DocumentDB/databaseAccounts", "2019-08-01-preview"); - RegisterConfiguration("Microsoft.DigitalTwins/digitalTwinsInstances", "2020-12-01"); - RegisterConfiguration("Microsoft.EventGrid/topics", "2020-04-01-preview"); - RegisterConfiguration("Microsoft.EventGrid/domains", "2020-04-01-preview"); - RegisterConfiguration("Microsoft.EventHub/namespaces", "2018-01-01-preview"); - RegisterConfiguration("Microsoft.HealthcareApis/services", "2020-03-30", false); - RegisterConfiguration("Microsoft.Insights/privateLinkScopes", "2019-10-17-preview"); - RegisterConfiguration("Microsoft.KeyVault/vaults", "2018-02-14", false); - RegisterConfiguration("Microsoft.Media/mediaservices", "2020-05-01"); - RegisterConfiguration("Microsoft.Migrate/assessmentProjects", "2020-05-01-preview", false); - RegisterConfiguration("Microsoft.Migrate/migrateProjects", "2020-06-01-preview", false); - RegisterConfiguration("Microsoft.Network/applicationgateways", "2020-05-01"); - RegisterConfiguration("Microsoft.OffAzure/masterSites", "2020-07-07", false); - RegisterConfiguration("Microsoft.Purview/accounts", "2020-12-01-preview"); - RegisterConfiguration("Microsoft.Search/searchServices", "2020-08-01"); - RegisterConfiguration("Microsoft.ServiceBus/namespaces", "2018-01-01-preview"); - RegisterConfiguration("Microsoft.SignalRService/signalr", "2020-05-01", false); - RegisterConfiguration("Microsoft.Sql/servers", "2018-06-01-preview"); - RegisterConfiguration("Microsoft.Storage/storageAccounts", "2019-06-01", false); - RegisterConfiguration("Microsoft.StorageSync/storageSyncServices", "2020-03-01"); - RegisterConfiguration("Microsoft.Synapse/workspaces", "2019-06-01-preview"); - RegisterConfiguration("Microsoft.Web/sites", "2019-08-01"); - RegisterConfiguration("Microsoft.Web/hostingEnvironments", "2020-10-01"); + RegisterConfiguration("Microsoft.AppConfiguration/configurationStores", "2020-06-01", true, true); + RegisterConfiguration("Microsoft.Automation/automationAccounts", "2020-01-13-preview", true, false); + RegisterConfiguration("Microsoft.Batch/batchAccounts", "2020-03-01", true, true); + RegisterConfiguration("Microsoft.Cache/redisEnterprise", "2021-03-01", true, false); + RegisterConfiguration("Microsoft.CognitiveServices/accounts", "2017-04-18", true, false); + RegisterConfiguration("Microsoft.Compute/diskAccesses", "2020-09-30", true, false); + RegisterConfiguration("Microsoft.ContainerRegistry/registries", "2019-12-01-preview", true, false); + RegisterConfiguration("Microsoft.DBforMariaDB/servers", "2018-06-01", true, true); + RegisterConfiguration("Microsoft.DBforMySQL/servers", "2018-06-01", true, true); + RegisterConfiguration("Microsoft.DBforPostgreSQL/servers", "2018-06-01", true, true); + RegisterConfiguration("Microsoft.Devices/IotHubs", "2020-03-01", true, true); + RegisterConfiguration("Microsoft.DigitalTwins/digitalTwinsInstances", "2020-12-01", true, true); + RegisterConfiguration("Microsoft.DocumentDB/databaseAccounts", "2019-08-01-preview", true, true); + RegisterConfiguration("Microsoft.EventGrid/topics", "2020-04-01-preview", true, true); + RegisterConfiguration("Microsoft.EventGrid/domains", "2020-04-01-preview", true, true); + RegisterConfiguration("Microsoft.EventHub/namespaces", "2018-01-01-preview", true, false); + RegisterConfiguration("Microsoft.HealthcareApis/services", "2020-03-30", false, true); + RegisterConfiguration("Microsoft.Insights/privateLinkScopes", "2019-10-17-preview", true, true); + RegisterConfiguration("Microsoft.KeyVault/vaults", "2018-02-14", false, false); + RegisterConfiguration("Microsoft.Media/mediaservices", "2020-05-01", true, true); + RegisterConfiguration("Microsoft.Migrate/assessmentProjects", "2020-05-01-preview", false, false); + RegisterConfiguration("Microsoft.Migrate/migrateProjects", "2020-06-01-preview", false, false); + RegisterConfiguration("Microsoft.Network/applicationgateways", "2020-05-01", true, false); + RegisterConfiguration("Microsoft.OffAzure/masterSites", "2020-07-07", false, false); + RegisterConfiguration("Microsoft.Purview/accounts", "2020-12-01-preview", true, true); + RegisterConfiguration("Microsoft.Search/searchServices", "2020-08-01", true, false); + RegisterConfiguration("Microsoft.ServiceBus/namespaces", "2018-01-01-preview", true, false); + RegisterConfiguration("Microsoft.SignalRService/signalr", "2020-05-01", false, false); + RegisterConfiguration("Microsoft.Sql/servers", "2018-06-01-preview", true, true); + RegisterConfiguration("Microsoft.Storage/storageAccounts", "2019-06-01", false, false); + RegisterConfiguration("Microsoft.StorageSync/storageSyncServices", "2020-03-01", true, false); + RegisterConfiguration("Microsoft.Synapse/workspaces", "2019-06-01-preview", true, true); + RegisterConfiguration("Microsoft.Web/sites", "2019-08-01", true, false); + RegisterConfiguration("Microsoft.Web/hostingEnvironments", "2020-10-01", true, false); } - private static void RegisterConfiguration(string type, string apiVersion, bool hasConnectionsURI = true) + private static void RegisterConfiguration(string type, string apiVersion, bool hasConnectionsURI = true, bool hasResourceURI = true) { ProviderConfiguration configuration = new ProviderConfiguration { Type = type, ApiVersion = apiVersion, - HasConnectionsURI = hasConnectionsURI + HasConnectionsURI = hasConnectionsURI, + HasResourceURI = hasResourceURI }; _configurations.Add(type, configuration); } @@ -64,6 +65,7 @@ private static void RegisterConfiguration(string type, string apiVersion, bool h public string Type { get; set; } public string ApiVersion { get; set; } public bool HasConnectionsURI { get; set; } + public bool HasResourceURI { get; set; } public static ProviderConfiguration GetProviderConfiguration(string type) { diff --git a/src/Network/Network/help/Get-AzPrivateLinkResource.md b/src/Network/Network/help/Get-AzPrivateLinkResource.md index 935f06baa8f0..116bd187b7f1 100644 --- a/src/Network/Network/help/Get-AzPrivateLinkResource.md +++ b/src/Network/Network/help/Get-AzPrivateLinkResource.md @@ -14,13 +14,13 @@ Gets a private link resource. ### ByPrivateLinkResourceId (Default) ``` -Get-AzPrivateLinkResource -PrivateLinkResourceId [-DefaultProfile ] - [] +Get-AzPrivateLinkResource -PrivateLinkResourceId [-Name ] + [-DefaultProfile ] [] ``` ### ByResource ``` -Get-AzPrivateLinkResource -ResourceGroupName -ServiceName +Get-AzPrivateLinkResource -ResourceGroupName -ServiceName [-Name ] [-DefaultProfile ] [-PrivateLinkResourceType ] [] ``` @@ -53,13 +53,28 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Name +The private link resource name. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: GroupName + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -PrivateLinkResourceId The Azure resource manager id of the private link resource. ```yaml Type: System.String Parameter Sets: ByPrivateLinkResourceId -Aliases: +Aliases: PrivateLinkServiceId Required: True Position: Named