Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Language;

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,
ParameterSetName = "ByPrivateLinkResourceId",
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string PrivateLinkResourceId { get; set; }

[CmdletParameterBreakingChange("Description", ChangeDescription = "Parameter is being deprecated without being replaced")]
[Parameter(
Mandatory = false,
Expand Down Expand Up @@ -60,18 +61,22 @@ public override void Execute()
this.PrivateLinkResourceType = resourceIdentifier.ResourceType;
this.ServiceName = resourceIdentifier.ResourceName;
}

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

if (ShouldGetByName(this.ResourceGroupName, this.Name))
{
var pec = provider.GetPrivateEndpointConnection(this.ResourceGroupName, this.ServiceName, this.Name);
WriteObject(pec);
}
else
{
var pecs = provider.ListPrivateEndpointConnections(this.ResourceGroupName, this.ServiceName);
WriteObject(SubResourceWildcardFilter(Name, pecs), true);
this.Subscription = DefaultProfile.DefaultContext.Subscription.Id;
this.PrivateLinkResourceType = DynamicParameters["PrivateLinkResourceType"].Value as string;

IPrivateLinkProvider provider = BuildProvider(this.Subscription, this.PrivateLinkResourceType);
if (ShouldGetByName(this.ResourceGroupName, this.Name))
{
var pec = provider.GetPrivateEndpointConnection(this.ResourceGroupName, this.ServiceName, this.Name);
WriteObject(pec);
}
else
{
var pecs = provider.ListPrivateEndpointConnections(this.ResourceGroupName, this.ServiceName);
WriteObject(SubResourceWildcardFilter(Name, pecs), true);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Network
{
public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet
public abstract class PrivateEndpointConnectionBaseCmdlet : NetworkBaseCmdlet, IDynamicParameters
{
[Parameter(
Mandatory = true,
Expand All @@ -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,
Expand All @@ -55,10 +47,28 @@ 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;

string NamedContextParameterSet = "ByResource";
public object GetDynamicParameters()
{
var parameters = new RuntimeDefinedParameterDictionary();
RuntimeDefinedParameter namedParameter;
if (ProviderConfiguration.TryGetProvideServiceParameter("PrivateLinkResourceType", NamedContextParameterSet, out namedParameter))
{
parameters.Add("PrivateLinkResourceType", namedParameter);
}
DynamicParameters = parameters;
return parameters;
}

public string PrivateLinkResourceType { get; set; }

public string Subscription { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,22 +32,62 @@ 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 string Subscription { get; set; }

public object GetDynamicParameters()
{
var parameters = new RuntimeDefinedParameterDictionary();
RuntimeDefinedParameter namedParameter;
if (ProviderConfiguration.TryGetProvideServiceParameter("PrivateLinkResourceType", NamedContextParameterSet, out namedParameter))
{
parameters.Add("PrivateLinkResourceType", 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["PrivateLinkResourceType"].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);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +14,7 @@ internal class ProviderConfiguration

static ProviderConfiguration()
{
RegisterConfiguration("Microsoft.AppConfiguration/configurationStores", "2019-11-01-preview");
RegisterConfiguration("Microsoft.AppConfiguration/configurationStores", "2020-06-01");
RegisterConfiguration("Microsoft.Sql/servers", "2018-06-01-preview");
RegisterConfiguration("Microsoft.DBforMySQL/servers", "2018-06-01");
RegisterConfiguration("Microsoft.DBforMariaDB/servers", "2018-06-01");
Expand Down Expand Up @@ -50,5 +53,35 @@ public static ProviderConfiguration GetProviderConfiguration(string type)
{
return _configurations[type];
}

/// <summary>
/// Generate a runtime parameter with ValidateSet matching the current context
/// </summary>
/// <param name="name">The name of the parameter</param>
/// <param name="runtimeParameter">The returned runtime parameter for context, with appropriate validate set</param>
/// <returns>True if one or more contexts were found, otherwise false</returns>
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<Attribute>()
{
new ParameterAttribute { Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The private link resource type.",
ParameterSetName = "ByResource" },
new ValidateSetAttribute(ProvideTypeList)
}
);
result = true;
}
return result;
}
}
}