1 package insights
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 PrivateLinkScopedResourcesClient struct {
20 BaseClient
21 }
22
23
24 func NewPrivateLinkScopedResourcesClient(subscriptionID string) PrivateLinkScopedResourcesClient {
25 return NewPrivateLinkScopedResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewPrivateLinkScopedResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkScopedResourcesClient {
32 return PrivateLinkScopedResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40 func (client PrivateLinkScopedResourcesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, scopeName string, name string, parameters ScopedResource) (result PrivateLinkScopedResourcesCreateOrUpdateFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.CreateOrUpdate")
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 if err := validation.Validate([]validation.Validation{
52 {TargetValue: client.SubscriptionID,
53 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54 {TargetValue: resourceGroupName,
55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
57 return result, validation.NewError("insights.PrivateLinkScopedResourcesClient", "CreateOrUpdate", err.Error())
58 }
59
60 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, scopeName, name, parameters)
61 if err != nil {
62 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "CreateOrUpdate", nil, "Failure preparing request")
63 return
64 }
65
66 result, err = client.CreateOrUpdateSender(req)
67 if err != nil {
68 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
69 return
70 }
71
72 return
73 }
74
75
76 func (client PrivateLinkScopedResourcesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, scopeName string, name string, parameters ScopedResource) (*http.Request, error) {
77 pathParameters := map[string]interface{}{
78 "name": autorest.Encode("path", name),
79 "resourceGroupName": autorest.Encode("path", resourceGroupName),
80 "scopeName": autorest.Encode("path", scopeName),
81 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
82 }
83
84 const APIVersion = "2019-10-17-preview"
85 queryParameters := map[string]interface{}{
86 "api-version": APIVersion,
87 }
88
89 preparer := autorest.CreatePreparer(
90 autorest.AsContentType("application/json; charset=utf-8"),
91 autorest.AsPut(),
92 autorest.WithBaseURL(client.BaseURI),
93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", pathParameters),
94 autorest.WithJSON(parameters),
95 autorest.WithQueryParameters(queryParameters))
96 return preparer.Prepare((&http.Request{}).WithContext(ctx))
97 }
98
99
100
101 func (client PrivateLinkScopedResourcesClient) CreateOrUpdateSender(req *http.Request) (future PrivateLinkScopedResourcesCreateOrUpdateFuture, err error) {
102 var resp *http.Response
103 future.FutureAPI = &azure.Future{}
104 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
105 if err != nil {
106 return
107 }
108 var azf azure.Future
109 azf, err = azure.NewFutureFromResponse(resp)
110 future.FutureAPI = &azf
111 future.Result = future.result
112 return
113 }
114
115
116
117 func (client PrivateLinkScopedResourcesClient) CreateOrUpdateResponder(resp *http.Response) (result ScopedResource, err error) {
118 err = autorest.Respond(
119 resp,
120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
121 autorest.ByUnmarshallingJSON(&result),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124 return
125 }
126
127
128
129
130
131
132 func (client PrivateLinkScopedResourcesClient) Delete(ctx context.Context, resourceGroupName string, scopeName string, name string) (result PrivateLinkScopedResourcesDeleteFuture, err error) {
133 if tracing.IsEnabled() {
134 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.Delete")
135 defer func() {
136 sc := -1
137 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
138 sc = result.FutureAPI.Response().StatusCode
139 }
140 tracing.EndSpan(ctx, sc, err)
141 }()
142 }
143 if err := validation.Validate([]validation.Validation{
144 {TargetValue: client.SubscriptionID,
145 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
146 {TargetValue: resourceGroupName,
147 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
148 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
149 return result, validation.NewError("insights.PrivateLinkScopedResourcesClient", "Delete", err.Error())
150 }
151
152 req, err := client.DeletePreparer(ctx, resourceGroupName, scopeName, name)
153 if err != nil {
154 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "Delete", nil, "Failure preparing request")
155 return
156 }
157
158 result, err = client.DeleteSender(req)
159 if err != nil {
160 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "Delete", result.Response(), "Failure sending request")
161 return
162 }
163
164 return
165 }
166
167
168 func (client PrivateLinkScopedResourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, scopeName string, name string) (*http.Request, error) {
169 pathParameters := map[string]interface{}{
170 "name": autorest.Encode("path", name),
171 "resourceGroupName": autorest.Encode("path", resourceGroupName),
172 "scopeName": autorest.Encode("path", scopeName),
173 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
174 }
175
176 const APIVersion = "2019-10-17-preview"
177 queryParameters := map[string]interface{}{
178 "api-version": APIVersion,
179 }
180
181 preparer := autorest.CreatePreparer(
182 autorest.AsDelete(),
183 autorest.WithBaseURL(client.BaseURI),
184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", pathParameters),
185 autorest.WithQueryParameters(queryParameters))
186 return preparer.Prepare((&http.Request{}).WithContext(ctx))
187 }
188
189
190
191 func (client PrivateLinkScopedResourcesClient) DeleteSender(req *http.Request) (future PrivateLinkScopedResourcesDeleteFuture, err error) {
192 var resp *http.Response
193 future.FutureAPI = &azure.Future{}
194 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
195 if err != nil {
196 return
197 }
198 var azf azure.Future
199 azf, err = azure.NewFutureFromResponse(resp)
200 future.FutureAPI = &azf
201 future.Result = future.result
202 return
203 }
204
205
206
207 func (client PrivateLinkScopedResourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
208 err = autorest.Respond(
209 resp,
210 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
211 autorest.ByClosing())
212 result.Response = resp
213 return
214 }
215
216
217
218
219
220
221 func (client PrivateLinkScopedResourcesClient) Get(ctx context.Context, resourceGroupName string, scopeName string, name string) (result ScopedResource, err error) {
222 if tracing.IsEnabled() {
223 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.Get")
224 defer func() {
225 sc := -1
226 if result.Response.Response != nil {
227 sc = result.Response.Response.StatusCode
228 }
229 tracing.EndSpan(ctx, sc, err)
230 }()
231 }
232 if err := validation.Validate([]validation.Validation{
233 {TargetValue: client.SubscriptionID,
234 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
235 {TargetValue: resourceGroupName,
236 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
237 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
238 return result, validation.NewError("insights.PrivateLinkScopedResourcesClient", "Get", err.Error())
239 }
240
241 req, err := client.GetPreparer(ctx, resourceGroupName, scopeName, name)
242 if err != nil {
243 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "Get", nil, "Failure preparing request")
244 return
245 }
246
247 resp, err := client.GetSender(req)
248 if err != nil {
249 result.Response = autorest.Response{Response: resp}
250 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "Get", resp, "Failure sending request")
251 return
252 }
253
254 result, err = client.GetResponder(resp)
255 if err != nil {
256 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "Get", resp, "Failure responding to request")
257 return
258 }
259
260 return
261 }
262
263
264 func (client PrivateLinkScopedResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, scopeName string, name string) (*http.Request, error) {
265 pathParameters := map[string]interface{}{
266 "name": autorest.Encode("path", name),
267 "resourceGroupName": autorest.Encode("path", resourceGroupName),
268 "scopeName": autorest.Encode("path", scopeName),
269 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
270 }
271
272 const APIVersion = "2019-10-17-preview"
273 queryParameters := map[string]interface{}{
274 "api-version": APIVersion,
275 }
276
277 preparer := autorest.CreatePreparer(
278 autorest.AsGet(),
279 autorest.WithBaseURL(client.BaseURI),
280 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", pathParameters),
281 autorest.WithQueryParameters(queryParameters))
282 return preparer.Prepare((&http.Request{}).WithContext(ctx))
283 }
284
285
286
287 func (client PrivateLinkScopedResourcesClient) GetSender(req *http.Request) (*http.Response, error) {
288 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
289 }
290
291
292
293 func (client PrivateLinkScopedResourcesClient) GetResponder(resp *http.Response) (result ScopedResource, err error) {
294 err = autorest.Respond(
295 resp,
296 azure.WithErrorUnlessStatusCode(http.StatusOK),
297 autorest.ByUnmarshallingJSON(&result),
298 autorest.ByClosing())
299 result.Response = autorest.Response{Response: resp}
300 return
301 }
302
303
304
305
306
307 func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScope(ctx context.Context, resourceGroupName string, scopeName string) (result ScopedResourceListResultPage, err error) {
308 if tracing.IsEnabled() {
309 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.ListByPrivateLinkScope")
310 defer func() {
311 sc := -1
312 if result.srlr.Response.Response != nil {
313 sc = result.srlr.Response.Response.StatusCode
314 }
315 tracing.EndSpan(ctx, sc, err)
316 }()
317 }
318 if err := validation.Validate([]validation.Validation{
319 {TargetValue: client.SubscriptionID,
320 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
321 {TargetValue: resourceGroupName,
322 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
323 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
324 return result, validation.NewError("insights.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", err.Error())
325 }
326
327 result.fn = client.listByPrivateLinkScopeNextResults
328 req, err := client.ListByPrivateLinkScopePreparer(ctx, resourceGroupName, scopeName)
329 if err != nil {
330 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", nil, "Failure preparing request")
331 return
332 }
333
334 resp, err := client.ListByPrivateLinkScopeSender(req)
335 if err != nil {
336 result.srlr.Response = autorest.Response{Response: resp}
337 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", resp, "Failure sending request")
338 return
339 }
340
341 result.srlr, err = client.ListByPrivateLinkScopeResponder(resp)
342 if err != nil {
343 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", resp, "Failure responding to request")
344 return
345 }
346 if result.srlr.hasNextLink() && result.srlr.IsEmpty() {
347 err = result.NextWithContext(ctx)
348 return
349 }
350
351 return
352 }
353
354
355 func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopePreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
356 pathParameters := map[string]interface{}{
357 "resourceGroupName": autorest.Encode("path", resourceGroupName),
358 "scopeName": autorest.Encode("path", scopeName),
359 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
360 }
361
362 const APIVersion = "2019-10-17-preview"
363 queryParameters := map[string]interface{}{
364 "api-version": APIVersion,
365 }
366
367 preparer := autorest.CreatePreparer(
368 autorest.AsGet(),
369 autorest.WithBaseURL(client.BaseURI),
370 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources", pathParameters),
371 autorest.WithQueryParameters(queryParameters))
372 return preparer.Prepare((&http.Request{}).WithContext(ctx))
373 }
374
375
376
377 func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeSender(req *http.Request) (*http.Response, error) {
378 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
379 }
380
381
382
383 func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeResponder(resp *http.Response) (result ScopedResourceListResult, err error) {
384 err = autorest.Respond(
385 resp,
386 azure.WithErrorUnlessStatusCode(http.StatusOK),
387 autorest.ByUnmarshallingJSON(&result),
388 autorest.ByClosing())
389 result.Response = autorest.Response{Response: resp}
390 return
391 }
392
393
394 func (client PrivateLinkScopedResourcesClient) listByPrivateLinkScopeNextResults(ctx context.Context, lastResults ScopedResourceListResult) (result ScopedResourceListResult, err error) {
395 req, err := lastResults.scopedResourceListResultPreparer(ctx)
396 if err != nil {
397 return result, autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", nil, "Failure preparing next results request")
398 }
399 if req == nil {
400 return
401 }
402 resp, err := client.ListByPrivateLinkScopeSender(req)
403 if err != nil {
404 result.Response = autorest.Response{Response: resp}
405 return result, autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure sending next results request")
406 }
407 result, err = client.ListByPrivateLinkScopeResponder(resp)
408 if err != nil {
409 err = autorest.NewErrorWithError(err, "insights.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure responding to next results request")
410 }
411 return
412 }
413
414
415 func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeComplete(ctx context.Context, resourceGroupName string, scopeName string) (result ScopedResourceListResultIterator, err error) {
416 if tracing.IsEnabled() {
417 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.ListByPrivateLinkScope")
418 defer func() {
419 sc := -1
420 if result.Response().Response.Response != nil {
421 sc = result.page.Response().Response.Response.StatusCode
422 }
423 tracing.EndSpan(ctx, sc, err)
424 }()
425 }
426 result.page, err = client.ListByPrivateLinkScope(ctx, resourceGroupName, scopeName)
427 return
428 }
429
View as plain text