1package apimanagement
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// LoggerClient is the client for the Logger methods of the Apimanagement service.
30type LoggerClient struct {
31	BaseClient
32}
33
34// NewLoggerClient creates an instance of the LoggerClient client.
35func NewLoggerClient() LoggerClient {
36	return LoggerClient{New()}
37}
38
39// CreateOrUpdate creates or Updates a logger.
40// Parameters:
41// apimBaseURL - the management endpoint of the API Management service, for example
42// https://myapimservice.management.azure-api.net.
43// loggerid - logger identifier. Must be unique in the API Management service instance.
44// parameters - create parameters.
45func (client LoggerClient) CreateOrUpdate(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerContract) (result LoggerContract, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.CreateOrUpdate")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	if err := validation.Validate([]validation.Validation{
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}}}}); err != nil {
60		return result, validation.NewError("apimanagement.LoggerClient", "CreateOrUpdate", err.Error())
61	}
62
63	req, err := client.CreateOrUpdatePreparer(ctx, apimBaseURL, loggerid, parameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CreateOrUpdateSender(req)
70	if err != nil {
71		result.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CreateOrUpdateResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure responding to request")
79	}
80
81	return
82}
83
84// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
85func (client LoggerClient) CreateOrUpdatePreparer(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerContract) (*http.Request, error) {
86	urlParameters := map[string]interface{}{
87		"apimBaseUrl": apimBaseURL,
88	}
89
90	pathParameters := map[string]interface{}{
91		"loggerid": autorest.Encode("path", loggerid),
92	}
93
94	const APIVersion = "2017-03-01"
95	queryParameters := map[string]interface{}{
96		"api-version": APIVersion,
97	}
98
99	preparer := autorest.CreatePreparer(
100		autorest.AsContentType("application/json; charset=utf-8"),
101		autorest.AsPut(),
102		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
103		autorest.WithPathParameters("/loggers/{loggerid}", pathParameters),
104		autorest.WithJSON(parameters),
105		autorest.WithQueryParameters(queryParameters))
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
110// http.Response Body if it receives an error.
111func (client LoggerClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
112	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
113}
114
115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
116// closes the http.Response Body.
117func (client LoggerClient) CreateOrUpdateResponder(resp *http.Response) (result LoggerContract, err error) {
118	err = autorest.Respond(
119		resp,
120		client.ByInspecting(),
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes the specified logger.
129// Parameters:
130// apimBaseURL - the management endpoint of the API Management service, for example
131// https://myapimservice.management.azure-api.net.
132// loggerid - logger identifier. Must be unique in the API Management service instance.
133// ifMatch - the entity state (Etag) version of the logger to delete. A value of "*" can be used for If-Match
134// to unconditionally apply the operation.
135func (client LoggerClient) Delete(ctx context.Context, apimBaseURL string, loggerid string, ifMatch string) (result autorest.Response, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.Delete")
138		defer func() {
139			sc := -1
140			if result.Response != nil {
141				sc = result.Response.StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	if err := validation.Validate([]validation.Validation{
147		{TargetValue: loggerid,
148			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil},
149				{Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
150		return result, validation.NewError("apimanagement.LoggerClient", "Delete", err.Error())
151	}
152
153	req, err := client.DeletePreparer(ctx, apimBaseURL, loggerid, ifMatch)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.DeleteSender(req)
160	if err != nil {
161		result.Response = resp
162		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure sending request")
163		return
164	}
165
166	result, err = client.DeleteResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure responding to request")
169	}
170
171	return
172}
173
174// DeletePreparer prepares the Delete request.
175func (client LoggerClient) DeletePreparer(ctx context.Context, apimBaseURL string, loggerid string, ifMatch string) (*http.Request, error) {
176	urlParameters := map[string]interface{}{
177		"apimBaseUrl": apimBaseURL,
178	}
179
180	pathParameters := map[string]interface{}{
181		"loggerid": autorest.Encode("path", loggerid),
182	}
183
184	const APIVersion = "2017-03-01"
185	queryParameters := map[string]interface{}{
186		"api-version": APIVersion,
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsDelete(),
191		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
192		autorest.WithPathParameters("/loggers/{loggerid}", pathParameters),
193		autorest.WithQueryParameters(queryParameters),
194		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// DeleteSender sends the Delete request. The method will close the
199// http.Response Body if it receives an error.
200func (client LoggerClient) DeleteSender(req *http.Request) (*http.Response, error) {
201	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
202}
203
204// DeleteResponder handles the response to the Delete request. The method always
205// closes the http.Response Body.
206func (client LoggerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
207	err = autorest.Respond(
208		resp,
209		client.ByInspecting(),
210		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
211		autorest.ByClosing())
212	result.Response = resp
213	return
214}
215
216// Get gets the details of the logger specified by its identifier.
217// Parameters:
218// apimBaseURL - the management endpoint of the API Management service, for example
219// https://myapimservice.management.azure-api.net.
220// loggerid - logger identifier. Must be unique in the API Management service instance.
221func (client LoggerClient) Get(ctx context.Context, apimBaseURL string, loggerid string) (result LoggerContract, err error) {
222	if tracing.IsEnabled() {
223		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.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: loggerid,
234			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil},
235				{Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
236		return result, validation.NewError("apimanagement.LoggerClient", "Get", err.Error())
237	}
238
239	req, err := client.GetPreparer(ctx, apimBaseURL, loggerid)
240	if err != nil {
241		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", nil, "Failure preparing request")
242		return
243	}
244
245	resp, err := client.GetSender(req)
246	if err != nil {
247		result.Response = autorest.Response{Response: resp}
248		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure sending request")
249		return
250	}
251
252	result, err = client.GetResponder(resp)
253	if err != nil {
254		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure responding to request")
255	}
256
257	return
258}
259
260// GetPreparer prepares the Get request.
261func (client LoggerClient) GetPreparer(ctx context.Context, apimBaseURL string, loggerid string) (*http.Request, error) {
262	urlParameters := map[string]interface{}{
263		"apimBaseUrl": apimBaseURL,
264	}
265
266	pathParameters := map[string]interface{}{
267		"loggerid": autorest.Encode("path", loggerid),
268	}
269
270	const APIVersion = "2017-03-01"
271	queryParameters := map[string]interface{}{
272		"api-version": APIVersion,
273	}
274
275	preparer := autorest.CreatePreparer(
276		autorest.AsGet(),
277		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
278		autorest.WithPathParameters("/loggers/{loggerid}", pathParameters),
279		autorest.WithQueryParameters(queryParameters))
280	return preparer.Prepare((&http.Request{}).WithContext(ctx))
281}
282
283// GetSender sends the Get request. The method will close the
284// http.Response Body if it receives an error.
285func (client LoggerClient) GetSender(req *http.Request) (*http.Response, error) {
286	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
287}
288
289// GetResponder handles the response to the Get request. The method always
290// closes the http.Response Body.
291func (client LoggerClient) GetResponder(resp *http.Response) (result LoggerContract, err error) {
292	err = autorest.Respond(
293		resp,
294		client.ByInspecting(),
295		azure.WithErrorUnlessStatusCode(http.StatusOK),
296		autorest.ByUnmarshallingJSON(&result),
297		autorest.ByClosing())
298	result.Response = autorest.Response{Response: resp}
299	return
300}
301
302// List lists a collection of loggers in the specified service instance.
303// Parameters:
304// apimBaseURL - the management endpoint of the API Management service, for example
305// https://myapimservice.management.azure-api.net.
306// filter - | Field | Supported operators    | Supported functions                         |
307// |-------|------------------------|---------------------------------------------|
308// | id    | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
309// | type  | eq                     |                                             |
310// top - number of records to return.
311// skip - number of records to skip.
312func (client LoggerClient) List(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result LoggerCollectionPage, err error) {
313	if tracing.IsEnabled() {
314		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.List")
315		defer func() {
316			sc := -1
317			if result.lc.Response.Response != nil {
318				sc = result.lc.Response.Response.StatusCode
319			}
320			tracing.EndSpan(ctx, sc, err)
321		}()
322	}
323	if err := validation.Validate([]validation.Validation{
324		{TargetValue: top,
325			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
326				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
327		{TargetValue: skip,
328			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
329				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
330		return result, validation.NewError("apimanagement.LoggerClient", "List", err.Error())
331	}
332
333	result.fn = client.listNextResults
334	req, err := client.ListPreparer(ctx, apimBaseURL, filter, top, skip)
335	if err != nil {
336		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", nil, "Failure preparing request")
337		return
338	}
339
340	resp, err := client.ListSender(req)
341	if err != nil {
342		result.lc.Response = autorest.Response{Response: resp}
343		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", resp, "Failure sending request")
344		return
345	}
346
347	result.lc, err = client.ListResponder(resp)
348	if err != nil {
349		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", resp, "Failure responding to request")
350	}
351
352	return
353}
354
355// ListPreparer prepares the List request.
356func (client LoggerClient) ListPreparer(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (*http.Request, error) {
357	urlParameters := map[string]interface{}{
358		"apimBaseUrl": apimBaseURL,
359	}
360
361	const APIVersion = "2017-03-01"
362	queryParameters := map[string]interface{}{
363		"api-version": APIVersion,
364	}
365	if len(filter) > 0 {
366		queryParameters["$filter"] = autorest.Encode("query", filter)
367	}
368	if top != nil {
369		queryParameters["$top"] = autorest.Encode("query", *top)
370	}
371	if skip != nil {
372		queryParameters["$skip"] = autorest.Encode("query", *skip)
373	}
374
375	preparer := autorest.CreatePreparer(
376		autorest.AsGet(),
377		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
378		autorest.WithPath("/loggers"),
379		autorest.WithQueryParameters(queryParameters))
380	return preparer.Prepare((&http.Request{}).WithContext(ctx))
381}
382
383// ListSender sends the List request. The method will close the
384// http.Response Body if it receives an error.
385func (client LoggerClient) ListSender(req *http.Request) (*http.Response, error) {
386	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
387}
388
389// ListResponder handles the response to the List request. The method always
390// closes the http.Response Body.
391func (client LoggerClient) ListResponder(resp *http.Response) (result LoggerCollection, err error) {
392	err = autorest.Respond(
393		resp,
394		client.ByInspecting(),
395		azure.WithErrorUnlessStatusCode(http.StatusOK),
396		autorest.ByUnmarshallingJSON(&result),
397		autorest.ByClosing())
398	result.Response = autorest.Response{Response: resp}
399	return
400}
401
402// listNextResults retrieves the next set of results, if any.
403func (client LoggerClient) listNextResults(ctx context.Context, lastResults LoggerCollection) (result LoggerCollection, err error) {
404	req, err := lastResults.loggerCollectionPreparer(ctx)
405	if err != nil {
406		return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", nil, "Failure preparing next results request")
407	}
408	if req == nil {
409		return
410	}
411	resp, err := client.ListSender(req)
412	if err != nil {
413		result.Response = autorest.Response{Response: resp}
414		return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", resp, "Failure sending next results request")
415	}
416	result, err = client.ListResponder(resp)
417	if err != nil {
418		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", resp, "Failure responding to next results request")
419	}
420	return
421}
422
423// ListComplete enumerates all values, automatically crossing page boundaries as required.
424func (client LoggerClient) ListComplete(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result LoggerCollectionIterator, err error) {
425	if tracing.IsEnabled() {
426		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.List")
427		defer func() {
428			sc := -1
429			if result.Response().Response.Response != nil {
430				sc = result.page.Response().Response.Response.StatusCode
431			}
432			tracing.EndSpan(ctx, sc, err)
433		}()
434	}
435	result.page, err = client.List(ctx, apimBaseURL, filter, top, skip)
436	return
437}
438
439// Update updates an existing logger.
440// Parameters:
441// apimBaseURL - the management endpoint of the API Management service, for example
442// https://myapimservice.management.azure-api.net.
443// loggerid - logger identifier. Must be unique in the API Management service instance.
444// parameters - update parameters.
445// ifMatch - the entity state (Etag) version of the logger to update. A value of "*" can be used for If-Match
446// to unconditionally apply the operation.
447func (client LoggerClient) Update(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerUpdateContract, ifMatch string) (result autorest.Response, err error) {
448	if tracing.IsEnabled() {
449		ctx = tracing.StartSpan(ctx, fqdn+"/LoggerClient.Update")
450		defer func() {
451			sc := -1
452			if result.Response != nil {
453				sc = result.Response.StatusCode
454			}
455			tracing.EndSpan(ctx, sc, err)
456		}()
457	}
458	if err := validation.Validate([]validation.Validation{
459		{TargetValue: loggerid,
460			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil},
461				{Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
462		return result, validation.NewError("apimanagement.LoggerClient", "Update", err.Error())
463	}
464
465	req, err := client.UpdatePreparer(ctx, apimBaseURL, loggerid, parameters, ifMatch)
466	if err != nil {
467		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", nil, "Failure preparing request")
468		return
469	}
470
471	resp, err := client.UpdateSender(req)
472	if err != nil {
473		result.Response = resp
474		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure sending request")
475		return
476	}
477
478	result, err = client.UpdateResponder(resp)
479	if err != nil {
480		err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure responding to request")
481	}
482
483	return
484}
485
486// UpdatePreparer prepares the Update request.
487func (client LoggerClient) UpdatePreparer(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerUpdateContract, ifMatch string) (*http.Request, error) {
488	urlParameters := map[string]interface{}{
489		"apimBaseUrl": apimBaseURL,
490	}
491
492	pathParameters := map[string]interface{}{
493		"loggerid": autorest.Encode("path", loggerid),
494	}
495
496	const APIVersion = "2017-03-01"
497	queryParameters := map[string]interface{}{
498		"api-version": APIVersion,
499	}
500
501	preparer := autorest.CreatePreparer(
502		autorest.AsContentType("application/json; charset=utf-8"),
503		autorest.AsPatch(),
504		autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters),
505		autorest.WithPathParameters("/loggers/{loggerid}", pathParameters),
506		autorest.WithJSON(parameters),
507		autorest.WithQueryParameters(queryParameters),
508		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
509	return preparer.Prepare((&http.Request{}).WithContext(ctx))
510}
511
512// UpdateSender sends the Update request. The method will close the
513// http.Response Body if it receives an error.
514func (client LoggerClient) UpdateSender(req *http.Request) (*http.Response, error) {
515	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
516}
517
518// UpdateResponder handles the response to the Update request. The method always
519// closes the http.Response Body.
520func (client LoggerClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
521	err = autorest.Respond(
522		resp,
523		client.ByInspecting(),
524		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
525		autorest.ByClosing())
526	result.Response = resp
527	return
528}
529