1package batch
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/date"
14	"github.com/Azure/go-autorest/autorest/validation"
15	"github.com/Azure/go-autorest/tracing"
16	"github.com/gofrs/uuid"
17	"net/http"
18)
19
20// CertificateClient is the a client for issuing REST requests to the Azure Batch service.
21type CertificateClient struct {
22	BaseClient
23}
24
25// NewCertificateClient creates an instance of the CertificateClient client.
26func NewCertificateClient() CertificateClient {
27	return NewCertificateClientWithBaseURI(DefaultBaseURI)
28}
29
30// NewCertificateClientWithBaseURI creates an instance of the CertificateClient client using a custom endpoint.  Use
31// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewCertificateClientWithBaseURI(baseURI string) CertificateClient {
33	return CertificateClient{NewWithBaseURI(baseURI)}
34}
35
36// Add sends the add request.
37// Parameters:
38// certificate - the certificate to be added.
39// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
40// seconds.
41// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
42// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
43// returnClientRequestID - whether the server should return the client-request-id in the response.
44// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
45// time; set it explicitly if you are calling the REST API directly.
46func (client CertificateClient) Add(ctx context.Context, certificate CertificateAddParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result autorest.Response, err error) {
47	if tracing.IsEnabled() {
48		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Add")
49		defer func() {
50			sc := -1
51			if result.Response != nil {
52				sc = result.Response.StatusCode
53			}
54			tracing.EndSpan(ctx, sc, err)
55		}()
56	}
57	if err := validation.Validate([]validation.Validation{
58		{TargetValue: certificate,
59			Constraints: []validation.Constraint{{Target: "certificate.Thumbprint", Name: validation.Null, Rule: true, Chain: nil},
60				{Target: "certificate.ThumbprintAlgorithm", Name: validation.Null, Rule: true, Chain: nil},
61				{Target: "certificate.Data", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
62		return result, validation.NewError("batch.CertificateClient", "Add", err.Error())
63	}
64
65	req, err := client.AddPreparer(ctx, certificate, timeout, clientRequestID, returnClientRequestID, ocpDate)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Add", nil, "Failure preparing request")
68		return
69	}
70
71	resp, err := client.AddSender(req)
72	if err != nil {
73		result.Response = resp
74		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Add", resp, "Failure sending request")
75		return
76	}
77
78	result, err = client.AddResponder(resp)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Add", resp, "Failure responding to request")
81		return
82	}
83
84	return
85}
86
87// AddPreparer prepares the Add request.
88func (client CertificateClient) AddPreparer(ctx context.Context, certificate CertificateAddParameter, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
89	const APIVersion = "2017-05-01.5.0"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93	if timeout != nil {
94		queryParameters["timeout"] = autorest.Encode("query", *timeout)
95	} else {
96		queryParameters["timeout"] = autorest.Encode("query", 30)
97	}
98
99	preparer := autorest.CreatePreparer(
100		autorest.AsContentType("application/json; odata=minimalmetadata; charset=utf-8"),
101		autorest.AsPost(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPath("/certificates"),
104		autorest.WithJSON(certificate),
105		autorest.WithQueryParameters(queryParameters))
106	if clientRequestID != nil {
107		preparer = autorest.DecoratePreparer(preparer,
108			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
109	}
110	if returnClientRequestID != nil {
111		preparer = autorest.DecoratePreparer(preparer,
112			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
113	} else {
114		preparer = autorest.DecoratePreparer(preparer,
115			autorest.WithHeader("return-client-request-id", autorest.String(false)))
116	}
117	if ocpDate != nil {
118		preparer = autorest.DecoratePreparer(preparer,
119			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
120	}
121	return preparer.Prepare((&http.Request{}).WithContext(ctx))
122}
123
124// AddSender sends the Add request. The method will close the
125// http.Response Body if it receives an error.
126func (client CertificateClient) AddSender(req *http.Request) (*http.Response, error) {
127	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
128}
129
130// AddResponder handles the response to the Add request. The method always
131// closes the http.Response Body.
132func (client CertificateClient) AddResponder(resp *http.Response) (result autorest.Response, err error) {
133	err = autorest.Respond(
134		resp,
135		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
136		autorest.ByClosing())
137	result.Response = resp
138	return
139}
140
141// CancelDeletion if you try to delete a certificate that is being used by a pool or compute node, the status of the
142// certificate changes to deleteFailed. If you decide that you want to continue using the certificate, you can use this
143// operation to set the status of the certificate back to active. If you intend to delete the certificate, you do not
144// need to run this operation after the deletion failed. You must make sure that the certificate is not being used by
145// any resources, and then you can try again to delete the certificate.
146// Parameters:
147// thumbprintAlgorithm - the algorithm used to derive the thumbprint parameter. This must be sha1.
148// thumbprint - the thumbprint of the certificate being deleted.
149// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
150// seconds.
151// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
152// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
153// returnClientRequestID - whether the server should return the client-request-id in the response.
154// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
155// time; set it explicitly if you are calling the REST API directly.
156func (client CertificateClient) CancelDeletion(ctx context.Context, thumbprintAlgorithm string, thumbprint string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result autorest.Response, err error) {
157	if tracing.IsEnabled() {
158		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.CancelDeletion")
159		defer func() {
160			sc := -1
161			if result.Response != nil {
162				sc = result.Response.StatusCode
163			}
164			tracing.EndSpan(ctx, sc, err)
165		}()
166	}
167	req, err := client.CancelDeletionPreparer(ctx, thumbprintAlgorithm, thumbprint, timeout, clientRequestID, returnClientRequestID, ocpDate)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", nil, "Failure preparing request")
170		return
171	}
172
173	resp, err := client.CancelDeletionSender(req)
174	if err != nil {
175		result.Response = resp
176		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", resp, "Failure sending request")
177		return
178	}
179
180	result, err = client.CancelDeletionResponder(resp)
181	if err != nil {
182		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", resp, "Failure responding to request")
183		return
184	}
185
186	return
187}
188
189// CancelDeletionPreparer prepares the CancelDeletion request.
190func (client CertificateClient) CancelDeletionPreparer(ctx context.Context, thumbprintAlgorithm string, thumbprint string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
191	pathParameters := map[string]interface{}{
192		"thumbprint":          autorest.Encode("path", thumbprint),
193		"thumbprintAlgorithm": autorest.Encode("path", thumbprintAlgorithm),
194	}
195
196	const APIVersion = "2017-05-01.5.0"
197	queryParameters := map[string]interface{}{
198		"api-version": APIVersion,
199	}
200	if timeout != nil {
201		queryParameters["timeout"] = autorest.Encode("query", *timeout)
202	} else {
203		queryParameters["timeout"] = autorest.Encode("query", 30)
204	}
205
206	preparer := autorest.CreatePreparer(
207		autorest.AsPost(),
208		autorest.WithBaseURL(client.BaseURI),
209		autorest.WithPathParameters("/certificates(thumbprintAlgorithm={thumbprintAlgorithm},thumbprint={thumbprint})/canceldelete", pathParameters),
210		autorest.WithQueryParameters(queryParameters))
211	if clientRequestID != nil {
212		preparer = autorest.DecoratePreparer(preparer,
213			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
214	}
215	if returnClientRequestID != nil {
216		preparer = autorest.DecoratePreparer(preparer,
217			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
218	} else {
219		preparer = autorest.DecoratePreparer(preparer,
220			autorest.WithHeader("return-client-request-id", autorest.String(false)))
221	}
222	if ocpDate != nil {
223		preparer = autorest.DecoratePreparer(preparer,
224			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
225	}
226	return preparer.Prepare((&http.Request{}).WithContext(ctx))
227}
228
229// CancelDeletionSender sends the CancelDeletion request. The method will close the
230// http.Response Body if it receives an error.
231func (client CertificateClient) CancelDeletionSender(req *http.Request) (*http.Response, error) {
232	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
233}
234
235// CancelDeletionResponder handles the response to the CancelDeletion request. The method always
236// closes the http.Response Body.
237func (client CertificateClient) CancelDeletionResponder(resp *http.Response) (result autorest.Response, err error) {
238	err = autorest.Respond(
239		resp,
240		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
241		autorest.ByClosing())
242	result.Response = resp
243	return
244}
245
246// Delete you cannot delete a certificate if a resource (pool or compute node) is using it. Before you can delete a
247// certificate, you must therefore make sure that the certificate is not associated with any existing pools, the
248// certificate is not installed on any compute nodes (even if you remove a certificate from a pool, it is not removed
249// from existing compute nodes in that pool until they restart), and no running tasks depend on the certificate. If you
250// try to delete a certificate that is in use, the deletion fails. The certificate status changes to deleteFailed. You
251// can use Cancel Delete Certificate to set the status back to active if you decide that you want to continue using the
252// certificate.
253// Parameters:
254// thumbprintAlgorithm - the algorithm used to derive the thumbprint parameter. This must be sha1.
255// thumbprint - the thumbprint of the certificate to be deleted.
256// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
257// seconds.
258// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
259// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
260// returnClientRequestID - whether the server should return the client-request-id in the response.
261// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
262// time; set it explicitly if you are calling the REST API directly.
263func (client CertificateClient) Delete(ctx context.Context, thumbprintAlgorithm string, thumbprint string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result autorest.Response, err error) {
264	if tracing.IsEnabled() {
265		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Delete")
266		defer func() {
267			sc := -1
268			if result.Response != nil {
269				sc = result.Response.StatusCode
270			}
271			tracing.EndSpan(ctx, sc, err)
272		}()
273	}
274	req, err := client.DeletePreparer(ctx, thumbprintAlgorithm, thumbprint, timeout, clientRequestID, returnClientRequestID, ocpDate)
275	if err != nil {
276		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", nil, "Failure preparing request")
277		return
278	}
279
280	resp, err := client.DeleteSender(req)
281	if err != nil {
282		result.Response = resp
283		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", resp, "Failure sending request")
284		return
285	}
286
287	result, err = client.DeleteResponder(resp)
288	if err != nil {
289		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", resp, "Failure responding to request")
290		return
291	}
292
293	return
294}
295
296// DeletePreparer prepares the Delete request.
297func (client CertificateClient) DeletePreparer(ctx context.Context, thumbprintAlgorithm string, thumbprint string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
298	pathParameters := map[string]interface{}{
299		"thumbprint":          autorest.Encode("path", thumbprint),
300		"thumbprintAlgorithm": autorest.Encode("path", thumbprintAlgorithm),
301	}
302
303	const APIVersion = "2017-05-01.5.0"
304	queryParameters := map[string]interface{}{
305		"api-version": APIVersion,
306	}
307	if timeout != nil {
308		queryParameters["timeout"] = autorest.Encode("query", *timeout)
309	} else {
310		queryParameters["timeout"] = autorest.Encode("query", 30)
311	}
312
313	preparer := autorest.CreatePreparer(
314		autorest.AsDelete(),
315		autorest.WithBaseURL(client.BaseURI),
316		autorest.WithPathParameters("/certificates(thumbprintAlgorithm={thumbprintAlgorithm},thumbprint={thumbprint})", pathParameters),
317		autorest.WithQueryParameters(queryParameters))
318	if clientRequestID != nil {
319		preparer = autorest.DecoratePreparer(preparer,
320			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
321	}
322	if returnClientRequestID != nil {
323		preparer = autorest.DecoratePreparer(preparer,
324			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
325	} else {
326		preparer = autorest.DecoratePreparer(preparer,
327			autorest.WithHeader("return-client-request-id", autorest.String(false)))
328	}
329	if ocpDate != nil {
330		preparer = autorest.DecoratePreparer(preparer,
331			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
332	}
333	return preparer.Prepare((&http.Request{}).WithContext(ctx))
334}
335
336// DeleteSender sends the Delete request. The method will close the
337// http.Response Body if it receives an error.
338func (client CertificateClient) DeleteSender(req *http.Request) (*http.Response, error) {
339	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
340}
341
342// DeleteResponder handles the response to the Delete request. The method always
343// closes the http.Response Body.
344func (client CertificateClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
345	err = autorest.Respond(
346		resp,
347		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
348		autorest.ByClosing())
349	result.Response = resp
350	return
351}
352
353// Get gets information about the specified certificate.
354// Parameters:
355// thumbprintAlgorithm - the algorithm used to derive the thumbprint parameter. This must be sha1.
356// thumbprint - the thumbprint of the certificate to get.
357// selectParameter - an OData $select clause.
358// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
359// seconds.
360// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
361// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
362// returnClientRequestID - whether the server should return the client-request-id in the response.
363// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
364// time; set it explicitly if you are calling the REST API directly.
365func (client CertificateClient) Get(ctx context.Context, thumbprintAlgorithm string, thumbprint string, selectParameter string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result Certificate, err error) {
366	if tracing.IsEnabled() {
367		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Get")
368		defer func() {
369			sc := -1
370			if result.Response.Response != nil {
371				sc = result.Response.Response.StatusCode
372			}
373			tracing.EndSpan(ctx, sc, err)
374		}()
375	}
376	req, err := client.GetPreparer(ctx, thumbprintAlgorithm, thumbprint, selectParameter, timeout, clientRequestID, returnClientRequestID, ocpDate)
377	if err != nil {
378		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", nil, "Failure preparing request")
379		return
380	}
381
382	resp, err := client.GetSender(req)
383	if err != nil {
384		result.Response = autorest.Response{Response: resp}
385		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure sending request")
386		return
387	}
388
389	result, err = client.GetResponder(resp)
390	if err != nil {
391		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure responding to request")
392		return
393	}
394
395	return
396}
397
398// GetPreparer prepares the Get request.
399func (client CertificateClient) GetPreparer(ctx context.Context, thumbprintAlgorithm string, thumbprint string, selectParameter string, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
400	pathParameters := map[string]interface{}{
401		"thumbprint":          autorest.Encode("path", thumbprint),
402		"thumbprintAlgorithm": autorest.Encode("path", thumbprintAlgorithm),
403	}
404
405	const APIVersion = "2017-05-01.5.0"
406	queryParameters := map[string]interface{}{
407		"api-version": APIVersion,
408	}
409	if len(selectParameter) > 0 {
410		queryParameters["$select"] = autorest.Encode("query", selectParameter)
411	}
412	if timeout != nil {
413		queryParameters["timeout"] = autorest.Encode("query", *timeout)
414	} else {
415		queryParameters["timeout"] = autorest.Encode("query", 30)
416	}
417
418	preparer := autorest.CreatePreparer(
419		autorest.AsGet(),
420		autorest.WithBaseURL(client.BaseURI),
421		autorest.WithPathParameters("/certificates(thumbprintAlgorithm={thumbprintAlgorithm},thumbprint={thumbprint})", pathParameters),
422		autorest.WithQueryParameters(queryParameters))
423	if clientRequestID != nil {
424		preparer = autorest.DecoratePreparer(preparer,
425			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
426	}
427	if returnClientRequestID != nil {
428		preparer = autorest.DecoratePreparer(preparer,
429			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
430	} else {
431		preparer = autorest.DecoratePreparer(preparer,
432			autorest.WithHeader("return-client-request-id", autorest.String(false)))
433	}
434	if ocpDate != nil {
435		preparer = autorest.DecoratePreparer(preparer,
436			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
437	}
438	return preparer.Prepare((&http.Request{}).WithContext(ctx))
439}
440
441// GetSender sends the Get request. The method will close the
442// http.Response Body if it receives an error.
443func (client CertificateClient) GetSender(req *http.Request) (*http.Response, error) {
444	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
445}
446
447// GetResponder handles the response to the Get request. The method always
448// closes the http.Response Body.
449func (client CertificateClient) GetResponder(resp *http.Response) (result Certificate, err error) {
450	err = autorest.Respond(
451		resp,
452		azure.WithErrorUnlessStatusCode(http.StatusOK),
453		autorest.ByUnmarshallingJSON(&result),
454		autorest.ByClosing())
455	result.Response = autorest.Response{Response: resp}
456	return
457}
458
459// List sends the list request.
460// Parameters:
461// filter - an OData $filter clause.
462// selectParameter - an OData $select clause.
463// maxResults - the maximum number of items to return in the response. A maximum of 1000 certificates can be
464// returned.
465// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
466// seconds.
467// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
468// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
469// returnClientRequestID - whether the server should return the client-request-id in the response.
470// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
471// time; set it explicitly if you are calling the REST API directly.
472func (client CertificateClient) List(ctx context.Context, filter string, selectParameter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result CertificateListResultPage, err error) {
473	if tracing.IsEnabled() {
474		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.List")
475		defer func() {
476			sc := -1
477			if result.clr.Response.Response != nil {
478				sc = result.clr.Response.Response.StatusCode
479			}
480			tracing.EndSpan(ctx, sc, err)
481		}()
482	}
483	if err := validation.Validate([]validation.Validation{
484		{TargetValue: maxResults,
485			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
486				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
487					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
488				}}}}}); err != nil {
489		return result, validation.NewError("batch.CertificateClient", "List", err.Error())
490	}
491
492	result.fn = client.listNextResults
493	req, err := client.ListPreparer(ctx, filter, selectParameter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
494	if err != nil {
495		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "List", nil, "Failure preparing request")
496		return
497	}
498
499	resp, err := client.ListSender(req)
500	if err != nil {
501		result.clr.Response = autorest.Response{Response: resp}
502		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "List", resp, "Failure sending request")
503		return
504	}
505
506	result.clr, err = client.ListResponder(resp)
507	if err != nil {
508		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "List", resp, "Failure responding to request")
509		return
510	}
511	if result.clr.hasNextLink() && result.clr.IsEmpty() {
512		err = result.NextWithContext(ctx)
513		return
514	}
515
516	return
517}
518
519// ListPreparer prepares the List request.
520func (client CertificateClient) ListPreparer(ctx context.Context, filter string, selectParameter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
521	const APIVersion = "2017-05-01.5.0"
522	queryParameters := map[string]interface{}{
523		"api-version": APIVersion,
524	}
525	if len(filter) > 0 {
526		queryParameters["$filter"] = autorest.Encode("query", filter)
527	}
528	if len(selectParameter) > 0 {
529		queryParameters["$select"] = autorest.Encode("query", selectParameter)
530	}
531	if maxResults != nil {
532		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
533	} else {
534		queryParameters["maxresults"] = autorest.Encode("query", 1000)
535	}
536	if timeout != nil {
537		queryParameters["timeout"] = autorest.Encode("query", *timeout)
538	} else {
539		queryParameters["timeout"] = autorest.Encode("query", 30)
540	}
541
542	preparer := autorest.CreatePreparer(
543		autorest.AsGet(),
544		autorest.WithBaseURL(client.BaseURI),
545		autorest.WithPath("/certificates"),
546		autorest.WithQueryParameters(queryParameters))
547	if clientRequestID != nil {
548		preparer = autorest.DecoratePreparer(preparer,
549			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
550	}
551	if returnClientRequestID != nil {
552		preparer = autorest.DecoratePreparer(preparer,
553			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
554	} else {
555		preparer = autorest.DecoratePreparer(preparer,
556			autorest.WithHeader("return-client-request-id", autorest.String(false)))
557	}
558	if ocpDate != nil {
559		preparer = autorest.DecoratePreparer(preparer,
560			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
561	}
562	return preparer.Prepare((&http.Request{}).WithContext(ctx))
563}
564
565// ListSender sends the List request. The method will close the
566// http.Response Body if it receives an error.
567func (client CertificateClient) ListSender(req *http.Request) (*http.Response, error) {
568	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
569}
570
571// ListResponder handles the response to the List request. The method always
572// closes the http.Response Body.
573func (client CertificateClient) ListResponder(resp *http.Response) (result CertificateListResult, err error) {
574	err = autorest.Respond(
575		resp,
576		azure.WithErrorUnlessStatusCode(http.StatusOK),
577		autorest.ByUnmarshallingJSON(&result),
578		autorest.ByClosing())
579	result.Response = autorest.Response{Response: resp}
580	return
581}
582
583// listNextResults retrieves the next set of results, if any.
584func (client CertificateClient) listNextResults(ctx context.Context, lastResults CertificateListResult) (result CertificateListResult, err error) {
585	req, err := lastResults.certificateListResultPreparer(ctx)
586	if err != nil {
587		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listNextResults", nil, "Failure preparing next results request")
588	}
589	if req == nil {
590		return
591	}
592	resp, err := client.ListSender(req)
593	if err != nil {
594		result.Response = autorest.Response{Response: resp}
595		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listNextResults", resp, "Failure sending next results request")
596	}
597	result, err = client.ListResponder(resp)
598	if err != nil {
599		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "listNextResults", resp, "Failure responding to next results request")
600	}
601	return
602}
603
604// ListComplete enumerates all values, automatically crossing page boundaries as required.
605func (client CertificateClient) ListComplete(ctx context.Context, filter string, selectParameter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result CertificateListResultIterator, err error) {
606	if tracing.IsEnabled() {
607		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.List")
608		defer func() {
609			sc := -1
610			if result.Response().Response.Response != nil {
611				sc = result.page.Response().Response.Response.StatusCode
612			}
613			tracing.EndSpan(ctx, sc, err)
614		}()
615	}
616	result.page, err = client.List(ctx, filter, selectParameter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
617	return
618}
619