@@ -24,32 +24,26 @@ namespace Microsoft.Azure.Commands.Network.PrivateLinkService.PrivateLinkService
24
24
{
25
25
internal class GenericProvider : IPrivateLinkProvider
26
26
{
27
-
28
- private static IDictionary < string , string > _apiVersions = new Dictionary < string , string > {
29
- { "microsoft.sql/servers" , "2018-06-01-preview" }
30
- } ;
31
-
32
27
#region Constructor
33
28
public GenericProvider ( NetworkBaseCmdlet baseCmdlet , string subscription , string privateLinkResourceType )
34
29
{
35
30
this . BaseCmdlet = baseCmdlet ;
36
31
this . _subscription = subscription ;
37
- this . _privateLinkResourceType = privateLinkResourceType ;
38
- this . _apiVersion = _apiVersions [ privateLinkResourceType ? . ToLower ( ) ] ;
32
+ this . _configuration = ProviderConfiguration . GetProviderConfiguration ( privateLinkResourceType ) ;
39
33
}
40
34
#endregion
41
35
42
36
#region Interface Implementation
43
37
44
38
public static bool SupportsPrivateLinkResourceType ( string privateLinkResourceType )
45
39
{
46
- return _apiVersions . ContainsKey ( privateLinkResourceType ? . ToLower ( ) ) ;
40
+ ProviderConfiguration configuration = ProviderConfiguration . GetProviderConfiguration ( privateLinkResourceType ) ;
41
+ return ( configuration != null ) ;
47
42
}
48
43
49
44
public NetworkBaseCmdlet BaseCmdlet { get ; set ; }
50
45
private string _subscription ;
51
- private string _privateLinkResourceType ;
52
- private string _apiVersion ;
46
+ private ProviderConfiguration _configuration ;
53
47
54
48
private IAzureRestClient _client ;
55
49
private IAzureRestClient ServiceClient
@@ -70,36 +64,53 @@ private IAzureRestClient ServiceClient
70
64
public PSPrivateEndpointConnection GetPrivateEndpointConnection ( string resourceGroupName , string serviceName , string name )
71
65
{
72
66
string url = BuildPrivateEndpointConnectionURL ( resourceGroupName , serviceName , name ) ;
73
- PrivateEndpointConnection connnection = ServiceClient . Operations . GetResouce < PrivateEndpointConnection > ( url , _apiVersion ) ;
67
+ PrivateEndpointConnection connnection = ServiceClient . Operations . GetResouce < PrivateEndpointConnection > ( url , _configuration . ApiVersion ) ;
74
68
return ToPsPrivateEndpointConnection ( connnection ) ;
75
69
}
76
70
77
71
public List < PSPrivateEndpointConnection > ListPrivateEndpointConnections ( string resourceGroupName , string serviceName )
78
72
{
79
73
var psPECs = new List < PSPrivateEndpointConnection > ( ) ;
80
- string url = BuildPrivateEndpointConnectionsURL ( resourceGroupName , serviceName ) ;
81
- IPage < PrivateEndpointConnection > list = ServiceClient . Operations . GetResoucePage < Page < PrivateEndpointConnection > , PrivateEndpointConnection > ( url , _apiVersion ) ;
82
- foreach ( var pec in list )
83
- {
84
- var psPec = ToPsPrivateEndpointConnection ( pec ) ;
85
- psPECs . Add ( psPec ) ;
86
- }
87
- while ( list . NextPageLink != null )
74
+ if ( _configuration . HasConnectionsURI )
88
75
{
89
- list = ServiceClient . Operations . GetResoucePage < Page < PrivateEndpointConnection > , PrivateEndpointConnection > ( list . NextPageLink , null ) ;
76
+ string url = BuildPrivateEndpointConnectionsURL ( resourceGroupName , serviceName ) ;
77
+ IPage < PrivateEndpointConnection > list = ServiceClient . Operations . GetResoucePage < Page < PrivateEndpointConnection > , PrivateEndpointConnection > ( url , _configuration . ApiVersion ) ;
90
78
foreach ( var pec in list )
91
79
{
92
80
var psPec = ToPsPrivateEndpointConnection ( pec ) ;
93
81
psPECs . Add ( psPec ) ;
94
82
}
83
+ while ( list . NextPageLink != null )
84
+ {
85
+ list = ServiceClient . Operations . GetResoucePage < Page < PrivateEndpointConnection > , PrivateEndpointConnection > ( list . NextPageLink , null ) ;
86
+ foreach ( var pec in list )
87
+ {
88
+ var psPec = ToPsPrivateEndpointConnection ( pec ) ;
89
+ psPECs . Add ( psPec ) ;
90
+ }
91
+ }
92
+ }
93
+ else
94
+ {
95
+ string url = BuildPrivateEndpointConnectionsOwnerURL ( resourceGroupName , serviceName ) ;
96
+ TrackedResource resource = ServiceClient . Operations . GetResouce < TrackedResource > ( url , _configuration . ApiVersion ) ;
97
+ if ( resource ? . PrivateEndpointConnections != null )
98
+ {
99
+ foreach ( var pec in resource . PrivateEndpointConnections )
100
+ {
101
+ var psPec = ToPsPrivateEndpointConnection ( pec ) ;
102
+ psPECs . Add ( psPec ) ;
103
+ }
104
+ }
95
105
}
106
+
96
107
return psPECs ;
97
108
}
98
109
99
110
public PSPrivateEndpointConnection UpdatePrivateEndpointConnectionStatus ( string resourceGroupName , string serviceName , string name , string status , string description = null )
100
111
{
101
112
string url = BuildPrivateEndpointConnectionURL ( resourceGroupName , serviceName , name ) ;
102
- PrivateEndpointConnection privateEndpointConnection = ServiceClient . Operations . GetResouce < PrivateEndpointConnection > ( url , _apiVersion ) ;
113
+ PrivateEndpointConnection privateEndpointConnection = ServiceClient . Operations . GetResouce < PrivateEndpointConnection > ( url , _configuration . ApiVersion ) ;
103
114
104
115
privateEndpointConnection . PrivateLinkServiceConnectionState . Status = status ;
105
116
@@ -108,29 +119,29 @@ public PSPrivateEndpointConnection UpdatePrivateEndpointConnectionStatus(string
108
119
privateEndpointConnection . PrivateLinkServiceConnectionState . Description = description ;
109
120
}
110
121
111
- ServiceClient . Operations . PutResouce < PrivateEndpointConnection > ( url , _apiVersion , privateEndpointConnection ) ;
122
+ ServiceClient . Operations . PutResouce < PrivateEndpointConnection > ( url , _configuration . ApiVersion , privateEndpointConnection ) ;
112
123
113
124
return GetPrivateEndpointConnection ( resourceGroupName , serviceName , name ) ;
114
125
}
115
126
116
127
public void DeletePrivateEndpointConnection ( string resourceGroupName , string serviceName , string name )
117
128
{
118
129
string url = BuildPrivateEndpointConnectionURL ( resourceGroupName , serviceName , name ) ;
119
- ServiceClient . Operations . DeleteResouce ( url , _apiVersion ) ;
130
+ ServiceClient . Operations . DeleteResouce ( url , _configuration . ApiVersion ) ;
120
131
}
121
132
122
133
public PSPrivateLinkResource GetPrivateLinkResource ( string resourceGroupName , string serviceName , string name )
123
134
{
124
135
string url = BuildPrivateLinkResourceURL ( resourceGroupName , serviceName , name ) ;
125
- PrivateLinkResource resource = ServiceClient . Operations . GetResouce < PrivateLinkResource > ( url , _apiVersion ) ;
136
+ PrivateLinkResource resource = ServiceClient . Operations . GetResouce < PrivateLinkResource > ( url , _configuration . ApiVersion ) ;
126
137
return ToPsPrivateLinkResource ( resource ) ;
127
138
}
128
139
129
140
public List < PSPrivateLinkResource > ListPrivateLinkResource ( string resourceGroupName , string serviceName )
130
141
{
131
142
var psPLRs = new List < PSPrivateLinkResource > ( ) ;
132
143
string url = BuildPrivateLinkResourcesURL ( resourceGroupName , serviceName ) ;
133
- IPage < PrivateLinkResource > list = ServiceClient . Operations . GetResoucePage < Page < PrivateLinkResource > , PrivateLinkResource > ( url , _apiVersion ) ;
144
+ IPage < PrivateLinkResource > list = ServiceClient . Operations . GetResoucePage < Page < PrivateLinkResource > , PrivateLinkResource > ( url , _configuration . ApiVersion ) ;
134
145
foreach ( var plr in list )
135
146
{
136
147
var psPlr = ToPsPrivateLinkResource ( plr ) ;
@@ -156,31 +167,37 @@ public List<PSPrivateLinkResource> ListPrivateLinkResource(string resourceGroupN
156
167
/// </summary>
157
168
private string BuildPrivateLinkResourcesURL ( string resourceGroupName , string serviceName )
158
169
{
159
- return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _privateLinkResourceType } /{ serviceName } /privateLinkResources";
170
+ return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _configuration . Type } /{ serviceName } /privateLinkResources";
160
171
}
161
172
162
173
/// <summary>
163
174
/// /subscriptions/{_subscription}/resourceGroups/{resourceGroupName}/providers/{_privateLinkResourceType}/{serviceName}/privateLinkResources/{name}
164
175
/// </summary>
165
176
private string BuildPrivateLinkResourceURL ( string resourceGroupName , string serviceName , string name )
166
177
{
167
- return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _privateLinkResourceType } /{ serviceName } /privateLinkResources/{ name } ";
178
+ return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _configuration . Type } /{ serviceName } /privateLinkResources/{ name } ";
168
179
}
169
180
170
181
/// <summary>
171
182
/// /subscriptions/{_subscription}/resourceGroups/{resourceGroupName}/providers/{_privateLinkResourceType}/{serviceName}/privateEndpointConnections
172
183
/// </summary>
173
184
private string BuildPrivateEndpointConnectionsURL ( string resourceGroupName , string serviceName )
174
185
{
175
- return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _privateLinkResourceType } /{ serviceName } /privateEndpointConnections";
186
+ return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _configuration . Type } /{ serviceName } /privateEndpointConnections";
176
187
}
177
188
189
+ private string BuildPrivateEndpointConnectionsOwnerURL ( string resourceGroupName , string serviceName )
190
+ {
191
+ return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _configuration . Type } /{ serviceName } ";
192
+ }
193
+
194
+
178
195
/// <summary>
179
196
/// /subscriptions/{_subscription}/resourceGroups/{resourceGroupName}/providers/{_privateLinkResourceType}/{serviceName}/privateEndpointConnections/{name}
180
197
/// </summary>
181
198
private string BuildPrivateEndpointConnectionURL ( string resourceGroupName , string serviceName , string name )
182
199
{
183
- return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _privateLinkResourceType } /{ serviceName } /privateEndpointConnections/{ name } ";
200
+ return $ "/subscriptions/{ _subscription } /resourceGroups/{ resourceGroupName } /providers/{ _configuration . Type } /{ serviceName } /privateEndpointConnections/{ name } ";
184
201
}
185
202
186
203
private PSPrivateEndpointConnection ToPsPrivateEndpointConnection ( PrivateEndpointConnection privateEndpointConnection )
0 commit comments