16
16
using Microsoft . Azure . Commands . Network . PrivateLinkService . PrivateLinkServiceProvider ;
17
17
using Microsoft . Azure . Management . Internal . Resources . Utilities . Models ;
18
18
using Microsoft . Azure . Management . Network . Models ;
19
+ using Microsoft . WindowsAzure . Commands . Utilities . Common ;
19
20
using System ;
20
21
using System . Management . Automation ;
21
22
22
23
namespace Microsoft . Azure . Commands . Network
23
24
{
24
25
[ Cmdlet ( "Get" , ResourceManager . Common . AzureRMConstants . AzureRMPrefix + "PrivateLinkResource" , DefaultParameterSetName = "ByPrivateLinkResourceId" ) , OutputType ( typeof ( PSPrivateLinkResource ) ) ]
25
- public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet
26
+ public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet , IDynamicParameters
26
27
{
27
28
[ Parameter (
28
29
Mandatory = true ,
@@ -31,22 +32,62 @@ public class GetAzurePrivateLinkResourceCommand : NetworkBaseCmdlet
31
32
[ ValidateNotNullOrEmpty ]
32
33
public string PrivateLinkResourceId { get ; set ; }
33
34
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 string Subscription { get ; set ; }
55
+
56
+ public object GetDynamicParameters ( )
57
+ {
58
+ var parameters = new RuntimeDefinedParameterDictionary ( ) ;
59
+ RuntimeDefinedParameter namedParameter ;
60
+ if ( ProviderConfiguration . TryGetProvideServiceParameter ( "PrivateLinkResourceType" , NamedContextParameterSet , out namedParameter ) )
61
+ {
62
+ parameters . Add ( "PrivateLinkResourceType" , namedParameter ) ;
63
+ }
64
+ DynamicParameters = parameters ;
65
+ return parameters ;
66
+ }
67
+
34
68
public override void Execute ( )
35
69
{
36
70
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 ) ;
71
+ if ( this . IsParameterBound ( c => c . PrivateLinkResourceId ) )
72
+ {
73
+ var resourceIdentifier = new ResourceIdentifier ( this . PrivateLinkResourceId ) ;
74
+ this . ResourceGroupName = resourceIdentifier . ResourceGroupName ;
75
+ this . ServiceName = resourceIdentifier . ResourceName ;
76
+ this . PrivateLinkResourceType = resourceIdentifier . ResourceType ;
77
+ this . Subscription = resourceIdentifier . Subscription ;
78
+ }
79
+ else
80
+ {
81
+ this . Subscription = DefaultProfile . DefaultContext . Subscription . Id ;
82
+ this . PrivateLinkResourceType = DynamicParameters [ "PrivateLinkResourceType" ] . Value as string ;
83
+ }
84
+ IPrivateLinkProvider provider = PrivateLinkProviderFactory . CreatePrivateLinkProvder ( this , Subscription , PrivateLinkResourceType ) ;
44
85
if ( provider == null )
45
86
{
46
87
throw new ArgumentException ( string . Format ( Properties . Resources . InvalidResourceId , this . PrivateLinkResourceId ) ) ;
47
88
}
48
-
49
- var plrs = provider . ListPrivateLinkResource ( ResourceGroupName , Name ) ;
89
+
90
+ var plrs = provider . ListPrivateLinkResource ( ResourceGroupName , ServiceName ) ;
50
91
WriteObject ( plrs , true ) ;
51
92
52
93
}
0 commit comments