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