1 package devices
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type PrivateEndpointConnectionsClient struct {
20 BaseClient
21 }
22
23
24 func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient {
25 return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient {
32 return PrivateEndpointConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40 func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete")
43 defer func() {
44 sc := -1
45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46 sc = result.FutureAPI.Response().StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName)
52 if err != nil {
53 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request")
54 return
55 }
56
57 result, err = client.DeleteSender(req)
58 if err != nil {
59 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Delete", result.Response(), "Failure sending request")
60 return
61 }
62
63 return
64 }
65
66
67 func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (*http.Request, error) {
68 pathParameters := map[string]interface{}{
69 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
70 "resourceGroupName": autorest.Encode("path", resourceGroupName),
71 "resourceName": autorest.Encode("path", resourceName),
72 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
73 }
74
75 const APIVersion = "2021-03-31"
76 queryParameters := map[string]interface{}{
77 "api-version": APIVersion,
78 }
79
80 preparer := autorest.CreatePreparer(
81 autorest.AsDelete(),
82 autorest.WithBaseURL(client.BaseURI),
83 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
84 autorest.WithQueryParameters(queryParameters))
85 return preparer.Prepare((&http.Request{}).WithContext(ctx))
86 }
87
88
89
90 func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) {
91 var resp *http.Response
92 future.FutureAPI = &azure.Future{}
93 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
94 if err != nil {
95 return
96 }
97 var azf azure.Future
98 azf, err = azure.NewFutureFromResponse(resp)
99 future.FutureAPI = &azf
100 future.Result = future.result
101 return
102 }
103
104
105
106 func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
107 err = autorest.Respond(
108 resp,
109 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
110 autorest.ByUnmarshallingJSON(&result),
111 autorest.ByClosing())
112 result.Response = autorest.Response{Response: resp}
113 return
114 }
115
116
117
118
119
120
121 func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) {
122 if tracing.IsEnabled() {
123 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get")
124 defer func() {
125 sc := -1
126 if result.Response.Response != nil {
127 sc = result.Response.Response.StatusCode
128 }
129 tracing.EndSpan(ctx, sc, err)
130 }()
131 }
132 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName)
133 if err != nil {
134 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request")
135 return
136 }
137
138 resp, err := client.GetSender(req)
139 if err != nil {
140 result.Response = autorest.Response{Response: resp}
141 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request")
142 return
143 }
144
145 result, err = client.GetResponder(resp)
146 if err != nil {
147 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request")
148 return
149 }
150
151 return
152 }
153
154
155 func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (*http.Request, error) {
156 pathParameters := map[string]interface{}{
157 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
158 "resourceGroupName": autorest.Encode("path", resourceGroupName),
159 "resourceName": autorest.Encode("path", resourceName),
160 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
161 }
162
163 const APIVersion = "2021-03-31"
164 queryParameters := map[string]interface{}{
165 "api-version": APIVersion,
166 }
167
168 preparer := autorest.CreatePreparer(
169 autorest.AsGet(),
170 autorest.WithBaseURL(client.BaseURI),
171 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
172 autorest.WithQueryParameters(queryParameters))
173 return preparer.Prepare((&http.Request{}).WithContext(ctx))
174 }
175
176
177
178 func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
179 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
180 }
181
182
183
184 func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
185 err = autorest.Respond(
186 resp,
187 azure.WithErrorUnlessStatusCode(http.StatusOK),
188 autorest.ByUnmarshallingJSON(&result),
189 autorest.ByClosing())
190 result.Response = autorest.Response{Response: resp}
191 return
192 }
193
194
195
196
197
198 func (client PrivateEndpointConnectionsClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result ListPrivateEndpointConnection, err error) {
199 if tracing.IsEnabled() {
200 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.List")
201 defer func() {
202 sc := -1
203 if result.Response.Response != nil {
204 sc = result.Response.Response.StatusCode
205 }
206 tracing.EndSpan(ctx, sc, err)
207 }()
208 }
209 req, err := client.ListPreparer(ctx, resourceGroupName, resourceName)
210 if err != nil {
211 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", nil, "Failure preparing request")
212 return
213 }
214
215 resp, err := client.ListSender(req)
216 if err != nil {
217 result.Response = autorest.Response{Response: resp}
218 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", resp, "Failure sending request")
219 return
220 }
221
222 result, err = client.ListResponder(resp)
223 if err != nil {
224 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", resp, "Failure responding to request")
225 return
226 }
227
228 return
229 }
230
231
232 func (client PrivateEndpointConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
233 pathParameters := map[string]interface{}{
234 "resourceGroupName": autorest.Encode("path", resourceGroupName),
235 "resourceName": autorest.Encode("path", resourceName),
236 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
237 }
238
239 const APIVersion = "2021-03-31"
240 queryParameters := map[string]interface{}{
241 "api-version": APIVersion,
242 }
243
244 preparer := autorest.CreatePreparer(
245 autorest.AsGet(),
246 autorest.WithBaseURL(client.BaseURI),
247 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections", pathParameters),
248 autorest.WithQueryParameters(queryParameters))
249 return preparer.Prepare((&http.Request{}).WithContext(ctx))
250 }
251
252
253
254 func (client PrivateEndpointConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
255 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
256 }
257
258
259
260 func (client PrivateEndpointConnectionsClient) ListResponder(resp *http.Response) (result ListPrivateEndpointConnection, err error) {
261 err = autorest.Respond(
262 resp,
263 azure.WithErrorUnlessStatusCode(http.StatusOK),
264 autorest.ByUnmarshallingJSON(&result.Value),
265 autorest.ByClosing())
266 result.Response = autorest.Response{Response: resp}
267 return
268 }
269
270
271
272
273
274
275
276 func (client PrivateEndpointConnectionsClient) Update(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateFuture, err error) {
277 if tracing.IsEnabled() {
278 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Update")
279 defer func() {
280 sc := -1
281 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
282 sc = result.FutureAPI.Response().StatusCode
283 }
284 tracing.EndSpan(ctx, sc, err)
285 }()
286 }
287 if err := validation.Validate([]validation.Validation{
288 {TargetValue: privateEndpointConnection,
289 Constraints: []validation.Constraint{{Target: "privateEndpointConnection.Properties", Name: validation.Null, Rule: true,
290 Chain: []validation.Constraint{{Target: "privateEndpointConnection.Properties.PrivateLinkServiceConnectionState", Name: validation.Null, Rule: true,
291 Chain: []validation.Constraint{{Target: "privateEndpointConnection.Properties.PrivateLinkServiceConnectionState.Description", Name: validation.Null, Rule: true, Chain: nil}}},
292 }}}}}); err != nil {
293 return result, validation.NewError("devices.PrivateEndpointConnectionsClient", "Update", err.Error())
294 }
295
296 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName, privateEndpointConnection)
297 if err != nil {
298 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Update", nil, "Failure preparing request")
299 return
300 }
301
302 result, err = client.UpdateSender(req)
303 if err != nil {
304 err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Update", result.Response(), "Failure sending request")
305 return
306 }
307
308 return
309 }
310
311
312 func (client PrivateEndpointConnectionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (*http.Request, error) {
313 pathParameters := map[string]interface{}{
314 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
315 "resourceGroupName": autorest.Encode("path", resourceGroupName),
316 "resourceName": autorest.Encode("path", resourceName),
317 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
318 }
319
320 const APIVersion = "2021-03-31"
321 queryParameters := map[string]interface{}{
322 "api-version": APIVersion,
323 }
324
325 privateEndpointConnection.ID = nil
326 privateEndpointConnection.Name = nil
327 privateEndpointConnection.Type = nil
328 preparer := autorest.CreatePreparer(
329 autorest.AsContentType("application/json; charset=utf-8"),
330 autorest.AsPut(),
331 autorest.WithBaseURL(client.BaseURI),
332 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
333 autorest.WithJSON(privateEndpointConnection),
334 autorest.WithQueryParameters(queryParameters))
335 return preparer.Prepare((&http.Request{}).WithContext(ctx))
336 }
337
338
339
340 func (client PrivateEndpointConnectionsClient) UpdateSender(req *http.Request) (future PrivateEndpointConnectionsUpdateFuture, err error) {
341 var resp *http.Response
342 future.FutureAPI = &azure.Future{}
343 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
344 if err != nil {
345 return
346 }
347 var azf azure.Future
348 azf, err = azure.NewFutureFromResponse(resp)
349 future.FutureAPI = &azf
350 future.Result = future.result
351 return
352 }
353
354
355
356 func (client PrivateEndpointConnectionsClient) UpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
357 err = autorest.Respond(
358 resp,
359 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
360 autorest.ByUnmarshallingJSON(&result),
361 autorest.ByClosing())
362 result.Response = autorest.Response{Response: resp}
363 return
364 }
365
View as plain text