1package apimanagement
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
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// LoggerClient is the apiManagement Client
19type LoggerClient struct {
20	BaseClient
21}
22
23// NewLoggerClient creates an instance of the LoggerClient client.
24func NewLoggerClient(subscriptionID string) LoggerClient {
25	return NewLoggerClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewLoggerClientWithBaseURI creates an instance of the LoggerClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewLoggerClientWithBaseURI(baseURI string, subscriptionID string) LoggerClient {
31	return LoggerClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or Updates a logger.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// serviceName - the name of the API Management service.
38// loggerID - logger identifier. Must be unique in the API Management service instance.
39// parameters - create parameters.
40// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
41func (client LoggerClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, parameters LoggerContract, ifMatch string) (result LoggerContract, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: serviceName,
54			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
57		{TargetValue: loggerID,
58			Constraints: []validation.Constraint{{Target: "loggerID", Name: validation.MaxLength, Rule: 256, Chain: nil},
59				{Target: "loggerID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
60		{TargetValue: parameters,
61			Constraints: []validation.Constraint{{Target: "parameters.LoggerContractProperties", Name: validation.Null, Rule: false,
62				Chain: []validation.Constraint{{Target: "parameters.LoggerContractProperties.Description", Name: validation.Null, Rule: false,
63					Chain: []validation.Constraint{{Target: "parameters.LoggerContractProperties.Description", Name: validation.MaxLength, Rule: 256, Chain: nil}}},
64					{Target: "parameters.LoggerContractProperties.Credentials", Name: validation.Null, Rule: true, Chain: nil},
65				}}}}}); err != nil {
66		return result, validation.NewError("apimanagement.LoggerClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, loggerID, parameters, ifMatch)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.CreateOrUpdateSender(req)
76	if err != nil {
77		result.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure sending request")
79		return
80	}
81
82	result, err = client.CreateOrUpdateResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure responding to request")
85		return
86	}
87
88	return
89}
90
91// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
92func (client LoggerClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, parameters LoggerContract, ifMatch string) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"loggerId":          autorest.Encode("path", loggerID),
95		"resourceGroupName": autorest.Encode("path", resourceGroupName),
96		"serviceName":       autorest.Encode("path", serviceName),
97		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
98	}
99
100	const APIVersion = "2019-12-01-preview"
101	queryParameters := map[string]interface{}{
102		"api-version": APIVersion,
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsContentType("application/json; charset=utf-8"),
107		autorest.AsPut(),
108		autorest.WithBaseURL(client.BaseURI),
109		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}", pathParameters),
110		autorest.WithJSON(parameters),
111		autorest.WithQueryParameters(queryParameters))
112	if len(ifMatch) > 0 {
113		preparer = autorest.DecoratePreparer(preparer,
114			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
115	}
116	return preparer.Prepare((&http.Request{}).WithContext(ctx))
117}
118
119// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
120// http.Response Body if it receives an error.
121func (client LoggerClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
122	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
123}
124
125// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
126// closes the http.Response Body.
127func (client LoggerClient) CreateOrUpdateResponder(resp *http.Response) (result LoggerContract, err error) {
128	err = autorest.Respond(
129		resp,
130		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
131		autorest.ByUnmarshallingJSON(&result),
132		autorest.ByClosing())
133	result.Response = autorest.Response{Response: resp}
134	return
135}
136
137// Delete deletes the specified logger.
138// Parameters:
139// resourceGroupName - the name of the resource group.
140// serviceName - the name of the API Management service.
141// loggerID - logger identifier. Must be unique in the API Management service instance.
142// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
143// request or it should be * for unconditional update.
144// force - force deletion even if diagnostic is attached.
145func (client LoggerClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, ifMatch string, force *bool) (result autorest.Response, err error) {
146	if tracing.IsEnabled() {
147		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.Delete")
148		defer func() {
149			sc := -1
150			if result.Response != nil {
151				sc = result.Response.StatusCode
152			}
153			tracing.EndSpan(ctx, sc, err)
154		}()
155	}
156	if err := validation.Validate([]validation.Validation{
157		{TargetValue: serviceName,
158			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
159				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
160				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
161		{TargetValue: loggerID,
162			Constraints: []validation.Constraint{{Target: "loggerID", Name: validation.MaxLength, Rule: 256, Chain: nil},
163				{Target: "loggerID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
164		return result, validation.NewError("apimanagement.LoggerClient", "Delete", err.Error())
165	}
166
167	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, loggerID, ifMatch, force)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", nil, "Failure preparing request")
170		return
171	}
172
173	resp, err := client.DeleteSender(req)
174	if err != nil {
175		result.Response = resp
176		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure sending request")
177		return
178	}
179
180	result, err = client.DeleteResponder(resp)
181	if err != nil {
182		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure responding to request")
183		return
184	}
185
186	return
187}
188
189// DeletePreparer prepares the Delete request.
190func (client LoggerClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, ifMatch string, force *bool) (*http.Request, error) {
191	pathParameters := map[string]interface{}{
192		"loggerId":          autorest.Encode("path", loggerID),
193		"resourceGroupName": autorest.Encode("path", resourceGroupName),
194		"serviceName":       autorest.Encode("path", serviceName),
195		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
196	}
197
198	const APIVersion = "2019-12-01-preview"
199	queryParameters := map[string]interface{}{
200		"api-version": APIVersion,
201	}
202	if force != nil {
203		queryParameters["force"] = autorest.Encode("query", *force)
204	}
205
206	preparer := autorest.CreatePreparer(
207		autorest.AsDelete(),
208		autorest.WithBaseURL(client.BaseURI),
209		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}", pathParameters),
210		autorest.WithQueryParameters(queryParameters),
211		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
212	return preparer.Prepare((&http.Request{}).WithContext(ctx))
213}
214
215// DeleteSender sends the Delete request. The method will close the
216// http.Response Body if it receives an error.
217func (client LoggerClient) DeleteSender(req *http.Request) (*http.Response, error) {
218	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
219}
220
221// DeleteResponder handles the response to the Delete request. The method always
222// closes the http.Response Body.
223func (client LoggerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
224	err = autorest.Respond(
225		resp,
226		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
227		autorest.ByClosing())
228	result.Response = resp
229	return
230}
231
232// Get gets the details of the logger specified by its identifier.
233// Parameters:
234// resourceGroupName - the name of the resource group.
235// serviceName - the name of the API Management service.
236// loggerID - logger identifier. Must be unique in the API Management service instance.
237func (client LoggerClient) Get(ctx context.Context, resourceGroupName string, serviceName string, loggerID string) (result LoggerContract, err error) {
238	if tracing.IsEnabled() {
239		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.Get")
240		defer func() {
241			sc := -1
242			if result.Response.Response != nil {
243				sc = result.Response.Response.StatusCode
244			}
245			tracing.EndSpan(ctx, sc, err)
246		}()
247	}
248	if err := validation.Validate([]validation.Validation{
249		{TargetValue: serviceName,
250			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
251				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
252				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
253		{TargetValue: loggerID,
254			Constraints: []validation.Constraint{{Target: "loggerID", Name: validation.MaxLength, Rule: 256, Chain: nil},
255				{Target: "loggerID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
256		return result, validation.NewError("apimanagement.LoggerClient", "Get", err.Error())
257	}
258
259	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, loggerID)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", nil, "Failure preparing request")
262		return
263	}
264
265	resp, err := client.GetSender(req)
266	if err != nil {
267		result.Response = autorest.Response{Response: resp}
268		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure sending request")
269		return
270	}
271
272	result, err = client.GetResponder(resp)
273	if err != nil {
274		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure responding to request")
275		return
276	}
277
278	return
279}
280
281// GetPreparer prepares the Get request.
282func (client LoggerClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, loggerID string) (*http.Request, error) {
283	pathParameters := map[string]interface{}{
284		"loggerId":          autorest.Encode("path", loggerID),
285		"resourceGroupName": autorest.Encode("path", resourceGroupName),
286		"serviceName":       autorest.Encode("path", serviceName),
287		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
288	}
289
290	const APIVersion = "2019-12-01-preview"
291	queryParameters := map[string]interface{}{
292		"api-version": APIVersion,
293	}
294
295	preparer := autorest.CreatePreparer(
296		autorest.AsGet(),
297		autorest.WithBaseURL(client.BaseURI),
298		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}", pathParameters),
299		autorest.WithQueryParameters(queryParameters))
300	return preparer.Prepare((&http.Request{}).WithContext(ctx))
301}
302
303// GetSender sends the Get request. The method will close the
304// http.Response Body if it receives an error.
305func (client LoggerClient) GetSender(req *http.Request) (*http.Response, error) {
306	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
307}
308
309// GetResponder handles the response to the Get request. The method always
310// closes the http.Response Body.
311func (client LoggerClient) GetResponder(resp *http.Response) (result LoggerContract, err error) {
312	err = autorest.Respond(
313		resp,
314		azure.WithErrorUnlessStatusCode(http.StatusOK),
315		autorest.ByUnmarshallingJSON(&result),
316		autorest.ByClosing())
317	result.Response = autorest.Response{Response: resp}
318	return
319}
320
321// GetEntityTag gets the entity state (Etag) version of the logger specified by its identifier.
322// Parameters:
323// resourceGroupName - the name of the resource group.
324// serviceName - the name of the API Management service.
325// loggerID - logger identifier. Must be unique in the API Management service instance.
326func (client LoggerClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, loggerID string) (result autorest.Response, err error) {
327	if tracing.IsEnabled() {
328		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.GetEntityTag")
329		defer func() {
330			sc := -1
331			if result.Response != nil {
332				sc = result.Response.StatusCode
333			}
334			tracing.EndSpan(ctx, sc, err)
335		}()
336	}
337	if err := validation.Validate([]validation.Validation{
338		{TargetValue: serviceName,
339			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
340				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
341				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
342		{TargetValue: loggerID,
343			Constraints: []validation.Constraint{{Target: "loggerID", Name: validation.MaxLength, Rule: 256, Chain: nil},
344				{Target: "loggerID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
345		return result, validation.NewError("apimanagement.LoggerClient", "GetEntityTag", err.Error())
346	}
347
348	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, loggerID)
349	if err != nil {
350		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "GetEntityTag", nil, "Failure preparing request")
351		return
352	}
353
354	resp, err := client.GetEntityTagSender(req)
355	if err != nil {
356		result.Response = resp
357		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "GetEntityTag", resp, "Failure sending request")
358		return
359	}
360
361	result, err = client.GetEntityTagResponder(resp)
362	if err != nil {
363		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "GetEntityTag", resp, "Failure responding to request")
364		return
365	}
366
367	return
368}
369
370// GetEntityTagPreparer prepares the GetEntityTag request.
371func (client LoggerClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, loggerID string) (*http.Request, error) {
372	pathParameters := map[string]interface{}{
373		"loggerId":          autorest.Encode("path", loggerID),
374		"resourceGroupName": autorest.Encode("path", resourceGroupName),
375		"serviceName":       autorest.Encode("path", serviceName),
376		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
377	}
378
379	const APIVersion = "2019-12-01-preview"
380	queryParameters := map[string]interface{}{
381		"api-version": APIVersion,
382	}
383
384	preparer := autorest.CreatePreparer(
385		autorest.AsHead(),
386		autorest.WithBaseURL(client.BaseURI),
387		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}", pathParameters),
388		autorest.WithQueryParameters(queryParameters))
389	return preparer.Prepare((&http.Request{}).WithContext(ctx))
390}
391
392// GetEntityTagSender sends the GetEntityTag request. The method will close the
393// http.Response Body if it receives an error.
394func (client LoggerClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
395	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
396}
397
398// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
399// closes the http.Response Body.
400func (client LoggerClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
401	err = autorest.Respond(
402		resp,
403		azure.WithErrorUnlessStatusCode(http.StatusOK),
404		autorest.ByClosing())
405	result.Response = resp
406	return
407}
408
409// ListByService lists a collection of loggers in the specified service instance.
410// Parameters:
411// resourceGroupName - the name of the resource group.
412// serviceName - the name of the API Management service.
413// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
414// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
415// | substringof, contains, startswith, endswith | </br>| description | filter | ge, le, eq, ne, gt, lt |
416// substringof, contains, startswith, endswith | </br>| loggerType | filter | eq |     | </br>| resourceId |
417// filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | </br>
418// top - number of records to return.
419// skip - number of records to skip.
420func (client LoggerClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result LoggerCollectionPage, err error) {
421	if tracing.IsEnabled() {
422		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.ListByService")
423		defer func() {
424			sc := -1
425			if result.lc.Response.Response != nil {
426				sc = result.lc.Response.Response.StatusCode
427			}
428			tracing.EndSpan(ctx, sc, err)
429		}()
430	}
431	if err := validation.Validate([]validation.Validation{
432		{TargetValue: serviceName,
433			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
434				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
435				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
436		{TargetValue: top,
437			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
438				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
439		{TargetValue: skip,
440			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
441				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
442		return result, validation.NewError("apimanagement.LoggerClient", "ListByService", err.Error())
443	}
444
445	result.fn = client.listByServiceNextResults
446	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
447	if err != nil {
448		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "ListByService", nil, "Failure preparing request")
449		return
450	}
451
452	resp, err := client.ListByServiceSender(req)
453	if err != nil {
454		result.lc.Response = autorest.Response{Response: resp}
455		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "ListByService", resp, "Failure sending request")
456		return
457	}
458
459	result.lc, err = client.ListByServiceResponder(resp)
460	if err != nil {
461		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "ListByService", resp, "Failure responding to request")
462		return
463	}
464	if result.lc.hasNextLink() && result.lc.IsEmpty() {
465		err = result.NextWithContext(ctx)
466		return
467	}
468
469	return
470}
471
472// ListByServicePreparer prepares the ListByService request.
473func (client LoggerClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
474	pathParameters := map[string]interface{}{
475		"resourceGroupName": autorest.Encode("path", resourceGroupName),
476		"serviceName":       autorest.Encode("path", serviceName),
477		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
478	}
479
480	const APIVersion = "2019-12-01-preview"
481	queryParameters := map[string]interface{}{
482		"api-version": APIVersion,
483	}
484	if len(filter) > 0 {
485		queryParameters["$filter"] = autorest.Encode("query", filter)
486	}
487	if top != nil {
488		queryParameters["$top"] = autorest.Encode("query", *top)
489	}
490	if skip != nil {
491		queryParameters["$skip"] = autorest.Encode("query", *skip)
492	}
493
494	preparer := autorest.CreatePreparer(
495		autorest.AsGet(),
496		autorest.WithBaseURL(client.BaseURI),
497		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers", pathParameters),
498		autorest.WithQueryParameters(queryParameters))
499	return preparer.Prepare((&http.Request{}).WithContext(ctx))
500}
501
502// ListByServiceSender sends the ListByService request. The method will close the
503// http.Response Body if it receives an error.
504func (client LoggerClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
505	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
506}
507
508// ListByServiceResponder handles the response to the ListByService request. The method always
509// closes the http.Response Body.
510func (client LoggerClient) ListByServiceResponder(resp *http.Response) (result LoggerCollection, err error) {
511	err = autorest.Respond(
512		resp,
513		azure.WithErrorUnlessStatusCode(http.StatusOK),
514		autorest.ByUnmarshallingJSON(&result),
515		autorest.ByClosing())
516	result.Response = autorest.Response{Response: resp}
517	return
518}
519
520// listByServiceNextResults retrieves the next set of results, if any.
521func (client LoggerClient) listByServiceNextResults(ctx context.Context, lastResults LoggerCollection) (result LoggerCollection, err error) {
522	req, err := lastResults.loggerCollectionPreparer(ctx)
523	if err != nil {
524		return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listByServiceNextResults", nil, "Failure preparing next results request")
525	}
526	if req == nil {
527		return
528	}
529	resp, err := client.ListByServiceSender(req)
530	if err != nil {
531		result.Response = autorest.Response{Response: resp}
532		return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listByServiceNextResults", resp, "Failure sending next results request")
533	}
534	result, err = client.ListByServiceResponder(resp)
535	if err != nil {
536		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listByServiceNextResults", resp, "Failure responding to next results request")
537	}
538	return
539}
540
541// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
542func (client LoggerClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result LoggerCollectionIterator, err error) {
543	if tracing.IsEnabled() {
544		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.ListByService")
545		defer func() {
546			sc := -1
547			if result.Response().Response.Response != nil {
548				sc = result.page.Response().Response.Response.StatusCode
549			}
550			tracing.EndSpan(ctx, sc, err)
551		}()
552	}
553	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
554	return
555}
556
557// Update updates an existing logger.
558// Parameters:
559// resourceGroupName - the name of the resource group.
560// serviceName - the name of the API Management service.
561// loggerID - logger identifier. Must be unique in the API Management service instance.
562// parameters - update parameters.
563// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
564// request or it should be * for unconditional update.
565func (client LoggerClient) Update(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, parameters LoggerUpdateContract, ifMatch string) (result autorest.Response, err error) {
566	if tracing.IsEnabled() {
567		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.Update")
568		defer func() {
569			sc := -1
570			if result.Response != nil {
571				sc = result.Response.StatusCode
572			}
573			tracing.EndSpan(ctx, sc, err)
574		}()
575	}
576	if err := validation.Validate([]validation.Validation{
577		{TargetValue: serviceName,
578			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
579				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
580				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
581		{TargetValue: loggerID,
582			Constraints: []validation.Constraint{{Target: "loggerID", Name: validation.MaxLength, Rule: 256, Chain: nil},
583				{Target: "loggerID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
584		return result, validation.NewError("apimanagement.LoggerClient", "Update", err.Error())
585	}
586
587	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, loggerID, parameters, ifMatch)
588	if err != nil {
589		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", nil, "Failure preparing request")
590		return
591	}
592
593	resp, err := client.UpdateSender(req)
594	if err != nil {
595		result.Response = resp
596		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure sending request")
597		return
598	}
599
600	result, err = client.UpdateResponder(resp)
601	if err != nil {
602		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure responding to request")
603		return
604	}
605
606	return
607}
608
609// UpdatePreparer prepares the Update request.
610func (client LoggerClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, loggerID string, parameters LoggerUpdateContract, ifMatch string) (*http.Request, error) {
611	pathParameters := map[string]interface{}{
612		"loggerId":          autorest.Encode("path", loggerID),
613		"resourceGroupName": autorest.Encode("path", resourceGroupName),
614		"serviceName":       autorest.Encode("path", serviceName),
615		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
616	}
617
618	const APIVersion = "2019-12-01-preview"
619	queryParameters := map[string]interface{}{
620		"api-version": APIVersion,
621	}
622
623	preparer := autorest.CreatePreparer(
624		autorest.AsContentType("application/json; charset=utf-8"),
625		autorest.AsPatch(),
626		autorest.WithBaseURL(client.BaseURI),
627		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}", pathParameters),
628		autorest.WithJSON(parameters),
629		autorest.WithQueryParameters(queryParameters),
630		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
631	return preparer.Prepare((&http.Request{}).WithContext(ctx))
632}
633
634// UpdateSender sends the Update request. The method will close the
635// http.Response Body if it receives an error.
636func (client LoggerClient) UpdateSender(req *http.Request) (*http.Response, error) {
637	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
638}
639
640// UpdateResponder handles the response to the Update request. The method always
641// closes the http.Response Body.
642func (client LoggerClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
643	err = autorest.Respond(
644		resp,
645		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
646		autorest.ByClosing())
647	result.Response = resp
648	return
649}
650