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	"net/http"
26)
27
28// DiagnosticLoggerClient is the apiManagement Client
29type DiagnosticLoggerClient struct {
30	BaseClient
31}
32
33// NewDiagnosticLoggerClient creates an instance of the DiagnosticLoggerClient client.
34func NewDiagnosticLoggerClient(subscriptionID string) DiagnosticLoggerClient {
35	return NewDiagnosticLoggerClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewDiagnosticLoggerClientWithBaseURI creates an instance of the DiagnosticLoggerClient client.
39func NewDiagnosticLoggerClientWithBaseURI(baseURI string, subscriptionID string) DiagnosticLoggerClient {
40	return DiagnosticLoggerClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CheckEntityExists checks that logger entity specified by identifier is associated with the diagnostics entity.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// serviceName - the name of the API Management service.
47// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance.
48// loggerid - logger identifier. Must be unique in the API Management service instance.
49func (client DiagnosticLoggerClient) CheckEntityExists(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (result autorest.Response, err error) {
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: serviceName,
52			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
53				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
54				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
55		{TargetValue: diagnosticID,
56			Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil},
57				{Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}},
59		{TargetValue: loggerid,
60			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 80, Chain: nil},
61				{Target: "loggerid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil {
62		return result, validation.NewError("apimanagement.DiagnosticLoggerClient", "CheckEntityExists", err.Error())
63	}
64
65	req, err := client.CheckEntityExistsPreparer(ctx, resourceGroupName, serviceName, diagnosticID, loggerid)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CheckEntityExists", nil, "Failure preparing request")
68		return
69	}
70
71	resp, err := client.CheckEntityExistsSender(req)
72	if err != nil {
73		result.Response = resp
74		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CheckEntityExists", resp, "Failure sending request")
75		return
76	}
77
78	result, err = client.CheckEntityExistsResponder(resp)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CheckEntityExists", resp, "Failure responding to request")
81	}
82
83	return
84}
85
86// CheckEntityExistsPreparer prepares the CheckEntityExists request.
87func (client DiagnosticLoggerClient) CheckEntityExistsPreparer(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (*http.Request, error) {
88	pathParameters := map[string]interface{}{
89		"diagnosticId":      autorest.Encode("path", diagnosticID),
90		"loggerid":          autorest.Encode("path", loggerid),
91		"resourceGroupName": autorest.Encode("path", resourceGroupName),
92		"serviceName":       autorest.Encode("path", serviceName),
93		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
94	}
95
96	const APIVersion = "2018-01-01"
97	queryParameters := map[string]interface{}{
98		"api-version": APIVersion,
99	}
100
101	preparer := autorest.CreatePreparer(
102		autorest.AsHead(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/diagnostics/{diagnosticId}/loggers/{loggerid}", pathParameters),
105		autorest.WithQueryParameters(queryParameters))
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// CheckEntityExistsSender sends the CheckEntityExists request. The method will close the
110// http.Response Body if it receives an error.
111func (client DiagnosticLoggerClient) CheckEntityExistsSender(req *http.Request) (*http.Response, error) {
112	return autorest.SendWithSender(client, req,
113		azure.DoRetryWithRegistration(client.Client))
114}
115
116// CheckEntityExistsResponder handles the response to the CheckEntityExists request. The method always
117// closes the http.Response Body.
118func (client DiagnosticLoggerClient) CheckEntityExistsResponder(resp *http.Response) (result autorest.Response, err error) {
119	err = autorest.Respond(
120		resp,
121		client.ByInspecting(),
122		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound),
123		autorest.ByClosing())
124	result.Response = resp
125	return
126}
127
128// CreateOrUpdate attaches a logger to a dignostic.
129// Parameters:
130// resourceGroupName - the name of the resource group.
131// serviceName - the name of the API Management service.
132// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance.
133// loggerid - logger identifier. Must be unique in the API Management service instance.
134func (client DiagnosticLoggerClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (result LoggerContract, err error) {
135	if err := validation.Validate([]validation.Validation{
136		{TargetValue: serviceName,
137			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
138				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
139				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
140		{TargetValue: diagnosticID,
141			Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil},
142				{Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil},
143				{Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}},
144		{TargetValue: loggerid,
145			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 80, Chain: nil},
146				{Target: "loggerid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil {
147		return result, validation.NewError("apimanagement.DiagnosticLoggerClient", "CreateOrUpdate", err.Error())
148	}
149
150	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, diagnosticID, loggerid)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CreateOrUpdate", nil, "Failure preparing request")
153		return
154	}
155
156	resp, err := client.CreateOrUpdateSender(req)
157	if err != nil {
158		result.Response = autorest.Response{Response: resp}
159		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CreateOrUpdate", resp, "Failure sending request")
160		return
161	}
162
163	result, err = client.CreateOrUpdateResponder(resp)
164	if err != nil {
165		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "CreateOrUpdate", resp, "Failure responding to request")
166	}
167
168	return
169}
170
171// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
172func (client DiagnosticLoggerClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (*http.Request, error) {
173	pathParameters := map[string]interface{}{
174		"diagnosticId":      autorest.Encode("path", diagnosticID),
175		"loggerid":          autorest.Encode("path", loggerid),
176		"resourceGroupName": autorest.Encode("path", resourceGroupName),
177		"serviceName":       autorest.Encode("path", serviceName),
178		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
179	}
180
181	const APIVersion = "2018-01-01"
182	queryParameters := map[string]interface{}{
183		"api-version": APIVersion,
184	}
185
186	preparer := autorest.CreatePreparer(
187		autorest.AsPut(),
188		autorest.WithBaseURL(client.BaseURI),
189		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/diagnostics/{diagnosticId}/loggers/{loggerid}", pathParameters),
190		autorest.WithQueryParameters(queryParameters))
191	return preparer.Prepare((&http.Request{}).WithContext(ctx))
192}
193
194// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
195// http.Response Body if it receives an error.
196func (client DiagnosticLoggerClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
197	return autorest.SendWithSender(client, req,
198		azure.DoRetryWithRegistration(client.Client))
199}
200
201// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
202// closes the http.Response Body.
203func (client DiagnosticLoggerClient) CreateOrUpdateResponder(resp *http.Response) (result LoggerContract, err error) {
204	err = autorest.Respond(
205		resp,
206		client.ByInspecting(),
207		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
208		autorest.ByUnmarshallingJSON(&result),
209		autorest.ByClosing())
210	result.Response = autorest.Response{Response: resp}
211	return
212}
213
214// Delete deletes the specified Logger from Diagnostic.
215// Parameters:
216// resourceGroupName - the name of the resource group.
217// serviceName - the name of the API Management service.
218// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance.
219// loggerid - logger identifier. Must be unique in the API Management service instance.
220func (client DiagnosticLoggerClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (result autorest.Response, err error) {
221	if err := validation.Validate([]validation.Validation{
222		{TargetValue: serviceName,
223			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
224				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
225				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
226		{TargetValue: diagnosticID,
227			Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil},
228				{Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil},
229				{Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}},
230		{TargetValue: loggerid,
231			Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 80, Chain: nil},
232				{Target: "loggerid", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}}}); err != nil {
233		return result, validation.NewError("apimanagement.DiagnosticLoggerClient", "Delete", err.Error())
234	}
235
236	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, diagnosticID, loggerid)
237	if err != nil {
238		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "Delete", nil, "Failure preparing request")
239		return
240	}
241
242	resp, err := client.DeleteSender(req)
243	if err != nil {
244		result.Response = resp
245		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "Delete", resp, "Failure sending request")
246		return
247	}
248
249	result, err = client.DeleteResponder(resp)
250	if err != nil {
251		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "Delete", resp, "Failure responding to request")
252	}
253
254	return
255}
256
257// DeletePreparer prepares the Delete request.
258func (client DiagnosticLoggerClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, loggerid string) (*http.Request, error) {
259	pathParameters := map[string]interface{}{
260		"diagnosticId":      autorest.Encode("path", diagnosticID),
261		"loggerid":          autorest.Encode("path", loggerid),
262		"resourceGroupName": autorest.Encode("path", resourceGroupName),
263		"serviceName":       autorest.Encode("path", serviceName),
264		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
265	}
266
267	const APIVersion = "2018-01-01"
268	queryParameters := map[string]interface{}{
269		"api-version": APIVersion,
270	}
271
272	preparer := autorest.CreatePreparer(
273		autorest.AsDelete(),
274		autorest.WithBaseURL(client.BaseURI),
275		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/diagnostics/{diagnosticId}/loggers/{loggerid}", pathParameters),
276		autorest.WithQueryParameters(queryParameters))
277	return preparer.Prepare((&http.Request{}).WithContext(ctx))
278}
279
280// DeleteSender sends the Delete request. The method will close the
281// http.Response Body if it receives an error.
282func (client DiagnosticLoggerClient) DeleteSender(req *http.Request) (*http.Response, error) {
283	return autorest.SendWithSender(client, req,
284		azure.DoRetryWithRegistration(client.Client))
285}
286
287// DeleteResponder handles the response to the Delete request. The method always
288// closes the http.Response Body.
289func (client DiagnosticLoggerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
290	err = autorest.Respond(
291		resp,
292		client.ByInspecting(),
293		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
294		autorest.ByClosing())
295	result.Response = resp
296	return
297}
298
299// ListByService lists all loggers assosiated with the specified Diagnostic of the API Management service instance.
300// Parameters:
301// resourceGroupName - the name of the resource group.
302// serviceName - the name of the API Management service.
303// diagnosticID - diagnostic identifier. Must be unique in the current API Management service instance.
304// filter - | Field       | Supported operators    | Supported functions               |
305// |-------------|------------------------|-----------------------------------|
306// | id          | ge, le, eq, ne, gt, lt | substringof, startswith, endswith |
307// | type        | eq                     |                                   |
308// top - number of records to return.
309// skip - number of records to skip.
310func (client DiagnosticLoggerClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, filter string, top *int32, skip *int32) (result LoggerCollectionPage, err error) {
311	if err := validation.Validate([]validation.Validation{
312		{TargetValue: serviceName,
313			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
314				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
315				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
316		{TargetValue: diagnosticID,
317			Constraints: []validation.Constraint{{Target: "diagnosticID", Name: validation.MaxLength, Rule: 80, Chain: nil},
318				{Target: "diagnosticID", Name: validation.MinLength, Rule: 1, Chain: nil},
319				{Target: "diagnosticID", Name: validation.Pattern, Rule: `(^[\w]+$)|(^[\w][\w\-]+[\w]$)`, Chain: nil}}},
320		{TargetValue: top,
321			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
322				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
323		{TargetValue: skip,
324			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
325				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
326		return result, validation.NewError("apimanagement.DiagnosticLoggerClient", "ListByService", err.Error())
327	}
328
329	result.fn = client.listByServiceNextResults
330	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, diagnosticID, filter, top, skip)
331	if err != nil {
332		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "ListByService", nil, "Failure preparing request")
333		return
334	}
335
336	resp, err := client.ListByServiceSender(req)
337	if err != nil {
338		result.lc.Response = autorest.Response{Response: resp}
339		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "ListByService", resp, "Failure sending request")
340		return
341	}
342
343	result.lc, err = client.ListByServiceResponder(resp)
344	if err != nil {
345		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "ListByService", resp, "Failure responding to request")
346	}
347
348	return
349}
350
351// ListByServicePreparer prepares the ListByService request.
352func (client DiagnosticLoggerClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, filter string, top *int32, skip *int32) (*http.Request, error) {
353	pathParameters := map[string]interface{}{
354		"diagnosticId":      autorest.Encode("path", diagnosticID),
355		"resourceGroupName": autorest.Encode("path", resourceGroupName),
356		"serviceName":       autorest.Encode("path", serviceName),
357		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
358	}
359
360	const APIVersion = "2018-01-01"
361	queryParameters := map[string]interface{}{
362		"api-version": APIVersion,
363	}
364	if len(filter) > 0 {
365		queryParameters["$filter"] = autorest.Encode("query", filter)
366	}
367	if top != nil {
368		queryParameters["$top"] = autorest.Encode("query", *top)
369	}
370	if skip != nil {
371		queryParameters["$skip"] = autorest.Encode("query", *skip)
372	}
373
374	preparer := autorest.CreatePreparer(
375		autorest.AsGet(),
376		autorest.WithBaseURL(client.BaseURI),
377		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/diagnostics/{diagnosticId}/loggers", pathParameters),
378		autorest.WithQueryParameters(queryParameters))
379	return preparer.Prepare((&http.Request{}).WithContext(ctx))
380}
381
382// ListByServiceSender sends the ListByService request. The method will close the
383// http.Response Body if it receives an error.
384func (client DiagnosticLoggerClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
385	return autorest.SendWithSender(client, req,
386		azure.DoRetryWithRegistration(client.Client))
387}
388
389// ListByServiceResponder handles the response to the ListByService request. The method always
390// closes the http.Response Body.
391func (client DiagnosticLoggerClient) ListByServiceResponder(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// listByServiceNextResults retrieves the next set of results, if any.
403func (client DiagnosticLoggerClient) listByServiceNextResults(lastResults LoggerCollection) (result LoggerCollection, err error) {
404	req, err := lastResults.loggerCollectionPreparer()
405	if err != nil {
406		return result, autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "listByServiceNextResults", nil, "Failure preparing next results request")
407	}
408	if req == nil {
409		return
410	}
411	resp, err := client.ListByServiceSender(req)
412	if err != nil {
413		result.Response = autorest.Response{Response: resp}
414		return result, autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "listByServiceNextResults", resp, "Failure sending next results request")
415	}
416	result, err = client.ListByServiceResponder(resp)
417	if err != nil {
418		err = autorest.NewErrorWithError(err, "apimanagement.DiagnosticLoggerClient", "listByServiceNextResults", resp, "Failure responding to next results request")
419	}
420	return
421}
422
423// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
424func (client DiagnosticLoggerClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, diagnosticID string, filter string, top *int32, skip *int32) (result LoggerCollectionIterator, err error) {
425	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, diagnosticID, filter, top, skip)
426	return
427}
428