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/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// CertificateClient is the client for the Certificate methods of the Batch service.
19type CertificateClient struct {
20	BaseClient
21}
22
23// NewCertificateClient creates an instance of the CertificateClient client.
24func NewCertificateClient(subscriptionID string) CertificateClient {
25	return NewCertificateClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewCertificateClientWithBaseURI creates an instance of the CertificateClient client using a custom endpoint.  Use
29// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewCertificateClientWithBaseURI(baseURI string, subscriptionID string) CertificateClient {
31	return CertificateClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CancelDeletion if you try to delete a certificate that is being used by a pool or compute node, the status of the
35// certificate changes to deleteFailed. If you decide that you want to continue using the certificate, you can use this
36// operation to set the status of the certificate back to active. If you intend to delete the certificate, you do not
37// need to run this operation after the deletion failed. You must make sure that the certificate is not being used by
38// any resources, and then you can try again to delete the certificate.
39// Parameters:
40// resourceGroupName - the name of the resource group that contains the Batch account.
41// accountName - the name of the Batch account.
42// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
43// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
44func (client CertificateClient) CancelDeletion(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (result Certificate, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.CancelDeletion")
47		defer func() {
48			sc := -1
49			if result.Response.Response != nil {
50				sc = result.Response.Response.StatusCode
51			}
52			tracing.EndSpan(ctx, sc, err)
53		}()
54	}
55	if err := validation.Validate([]validation.Validation{
56		{TargetValue: accountName,
57			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
58				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
59				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}},
60		{TargetValue: certificateName,
61			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
62				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
63				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
64		return result, validation.NewError("batch.CertificateClient", "CancelDeletion", err.Error())
65	}
66
67	req, err := client.CancelDeletionPreparer(ctx, resourceGroupName, accountName, certificateName)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", nil, "Failure preparing request")
70		return
71	}
72
73	resp, err := client.CancelDeletionSender(req)
74	if err != nil {
75		result.Response = autorest.Response{Response: resp}
76		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", resp, "Failure sending request")
77		return
78	}
79
80	result, err = client.CancelDeletionResponder(resp)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "CancelDeletion", resp, "Failure responding to request")
83		return
84	}
85
86	return
87}
88
89// CancelDeletionPreparer prepares the CancelDeletion request.
90func (client CertificateClient) CancelDeletionPreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (*http.Request, error) {
91	pathParameters := map[string]interface{}{
92		"accountName":       autorest.Encode("path", accountName),
93		"certificateName":   autorest.Encode("path", certificateName),
94		"resourceGroupName": autorest.Encode("path", resourceGroupName),
95		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
96	}
97
98	const APIVersion = "2021-06-01"
99	queryParameters := map[string]interface{}{
100		"api-version": APIVersion,
101	}
102
103	preparer := autorest.CreatePreparer(
104		autorest.AsPost(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}/cancelDelete", pathParameters),
107		autorest.WithQueryParameters(queryParameters))
108	return preparer.Prepare((&http.Request{}).WithContext(ctx))
109}
110
111// CancelDeletionSender sends the CancelDeletion request. The method will close the
112// http.Response Body if it receives an error.
113func (client CertificateClient) CancelDeletionSender(req *http.Request) (*http.Response, error) {
114	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
115}
116
117// CancelDeletionResponder handles the response to the CancelDeletion request. The method always
118// closes the http.Response Body.
119func (client CertificateClient) CancelDeletionResponder(resp *http.Response) (result Certificate, err error) {
120	err = autorest.Respond(
121		resp,
122		azure.WithErrorUnlessStatusCode(http.StatusOK),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// Create creates a new certificate inside the specified account.
130// Parameters:
131// resourceGroupName - the name of the resource group that contains the Batch account.
132// accountName - the name of the Batch account.
133// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
134// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
135// parameters - additional parameters for certificate creation.
136// ifMatch - the entity state (ETag) version of the certificate to update. A value of "*" can be used to apply
137// the operation only if the certificate already exists. If omitted, this operation will always be applied.
138// ifNoneMatch - set to '*' to allow a new certificate to be created, but to prevent updating an existing
139// certificate. Other values will be ignored.
140func (client CertificateClient) Create(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string, ifNoneMatch string) (result Certificate, err error) {
141	if tracing.IsEnabled() {
142		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Create")
143		defer func() {
144			sc := -1
145			if result.Response.Response != nil {
146				sc = result.Response.Response.StatusCode
147			}
148			tracing.EndSpan(ctx, sc, err)
149		}()
150	}
151	if err := validation.Validate([]validation.Validation{
152		{TargetValue: accountName,
153			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
154				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
155				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}},
156		{TargetValue: certificateName,
157			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
158				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
159				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}},
160		{TargetValue: parameters,
161			Constraints: []validation.Constraint{{Target: "parameters.CertificateCreateOrUpdateProperties", Name: validation.Null, Rule: false,
162				Chain: []validation.Constraint{{Target: "parameters.CertificateCreateOrUpdateProperties.Data", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
163		return result, validation.NewError("batch.CertificateClient", "Create", err.Error())
164	}
165
166	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, certificateName, parameters, ifMatch, ifNoneMatch)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Create", nil, "Failure preparing request")
169		return
170	}
171
172	resp, err := client.CreateSender(req)
173	if err != nil {
174		result.Response = autorest.Response{Response: resp}
175		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Create", resp, "Failure sending request")
176		return
177	}
178
179	result, err = client.CreateResponder(resp)
180	if err != nil {
181		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Create", resp, "Failure responding to request")
182		return
183	}
184
185	return
186}
187
188// CreatePreparer prepares the Create request.
189func (client CertificateClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string, ifNoneMatch string) (*http.Request, error) {
190	pathParameters := map[string]interface{}{
191		"accountName":       autorest.Encode("path", accountName),
192		"certificateName":   autorest.Encode("path", certificateName),
193		"resourceGroupName": autorest.Encode("path", resourceGroupName),
194		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
195	}
196
197	const APIVersion = "2021-06-01"
198	queryParameters := map[string]interface{}{
199		"api-version": APIVersion,
200	}
201
202	preparer := autorest.CreatePreparer(
203		autorest.AsContentType("application/json; charset=utf-8"),
204		autorest.AsPut(),
205		autorest.WithBaseURL(client.BaseURI),
206		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
207		autorest.WithJSON(parameters),
208		autorest.WithQueryParameters(queryParameters))
209	if len(ifMatch) > 0 {
210		preparer = autorest.DecoratePreparer(preparer,
211			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
212	}
213	if len(ifNoneMatch) > 0 {
214		preparer = autorest.DecoratePreparer(preparer,
215			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
216	}
217	return preparer.Prepare((&http.Request{}).WithContext(ctx))
218}
219
220// CreateSender sends the Create request. The method will close the
221// http.Response Body if it receives an error.
222func (client CertificateClient) CreateSender(req *http.Request) (*http.Response, error) {
223	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
224}
225
226// CreateResponder handles the response to the Create request. The method always
227// closes the http.Response Body.
228func (client CertificateClient) CreateResponder(resp *http.Response) (result Certificate, err error) {
229	err = autorest.Respond(
230		resp,
231		azure.WithErrorUnlessStatusCode(http.StatusOK),
232		autorest.ByUnmarshallingJSON(&result),
233		autorest.ByClosing())
234	result.Response = autorest.Response{Response: resp}
235	return
236}
237
238// Delete deletes the specified certificate.
239// Parameters:
240// resourceGroupName - the name of the resource group that contains the Batch account.
241// accountName - the name of the Batch account.
242// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
243// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
244func (client CertificateClient) Delete(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (result CertificateDeleteFuture, err error) {
245	if tracing.IsEnabled() {
246		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Delete")
247		defer func() {
248			sc := -1
249			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
250				sc = result.FutureAPI.Response().StatusCode
251			}
252			tracing.EndSpan(ctx, sc, err)
253		}()
254	}
255	if err := validation.Validate([]validation.Validation{
256		{TargetValue: accountName,
257			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
258				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
259				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}},
260		{TargetValue: certificateName,
261			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
262				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
263				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
264		return result, validation.NewError("batch.CertificateClient", "Delete", err.Error())
265	}
266
267	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, certificateName)
268	if err != nil {
269		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", nil, "Failure preparing request")
270		return
271	}
272
273	result, err = client.DeleteSender(req)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", nil, "Failure sending request")
276		return
277	}
278
279	return
280}
281
282// DeletePreparer prepares the Delete request.
283func (client CertificateClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (*http.Request, error) {
284	pathParameters := map[string]interface{}{
285		"accountName":       autorest.Encode("path", accountName),
286		"certificateName":   autorest.Encode("path", certificateName),
287		"resourceGroupName": autorest.Encode("path", resourceGroupName),
288		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
289	}
290
291	const APIVersion = "2021-06-01"
292	queryParameters := map[string]interface{}{
293		"api-version": APIVersion,
294	}
295
296	preparer := autorest.CreatePreparer(
297		autorest.AsDelete(),
298		autorest.WithBaseURL(client.BaseURI),
299		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
300		autorest.WithQueryParameters(queryParameters))
301	return preparer.Prepare((&http.Request{}).WithContext(ctx))
302}
303
304// DeleteSender sends the Delete request. The method will close the
305// http.Response Body if it receives an error.
306func (client CertificateClient) DeleteSender(req *http.Request) (future CertificateDeleteFuture, err error) {
307	var resp *http.Response
308	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
309	if err != nil {
310		return
311	}
312	var azf azure.Future
313	azf, err = azure.NewFutureFromResponse(resp)
314	future.FutureAPI = &azf
315	future.Result = future.result
316	return
317}
318
319// DeleteResponder handles the response to the Delete request. The method always
320// closes the http.Response Body.
321func (client CertificateClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
322	err = autorest.Respond(
323		resp,
324		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
325		autorest.ByClosing())
326	result.Response = resp
327	return
328}
329
330// Get gets information about the specified certificate.
331// Parameters:
332// resourceGroupName - the name of the resource group that contains the Batch account.
333// accountName - the name of the Batch account.
334// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
335// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
336func (client CertificateClient) Get(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (result Certificate, err error) {
337	if tracing.IsEnabled() {
338		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Get")
339		defer func() {
340			sc := -1
341			if result.Response.Response != nil {
342				sc = result.Response.Response.StatusCode
343			}
344			tracing.EndSpan(ctx, sc, err)
345		}()
346	}
347	if err := validation.Validate([]validation.Validation{
348		{TargetValue: accountName,
349			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
350				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
351				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}},
352		{TargetValue: certificateName,
353			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
354				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
355				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
356		return result, validation.NewError("batch.CertificateClient", "Get", err.Error())
357	}
358
359	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, certificateName)
360	if err != nil {
361		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", nil, "Failure preparing request")
362		return
363	}
364
365	resp, err := client.GetSender(req)
366	if err != nil {
367		result.Response = autorest.Response{Response: resp}
368		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure sending request")
369		return
370	}
371
372	result, err = client.GetResponder(resp)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure responding to request")
375		return
376	}
377
378	return
379}
380
381// GetPreparer prepares the Get request.
382func (client CertificateClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (*http.Request, error) {
383	pathParameters := map[string]interface{}{
384		"accountName":       autorest.Encode("path", accountName),
385		"certificateName":   autorest.Encode("path", certificateName),
386		"resourceGroupName": autorest.Encode("path", resourceGroupName),
387		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
388	}
389
390	const APIVersion = "2021-06-01"
391	queryParameters := map[string]interface{}{
392		"api-version": APIVersion,
393	}
394
395	preparer := autorest.CreatePreparer(
396		autorest.AsGet(),
397		autorest.WithBaseURL(client.BaseURI),
398		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
399		autorest.WithQueryParameters(queryParameters))
400	return preparer.Prepare((&http.Request{}).WithContext(ctx))
401}
402
403// GetSender sends the Get request. The method will close the
404// http.Response Body if it receives an error.
405func (client CertificateClient) GetSender(req *http.Request) (*http.Response, error) {
406	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
407}
408
409// GetResponder handles the response to the Get request. The method always
410// closes the http.Response Body.
411func (client CertificateClient) GetResponder(resp *http.Response) (result Certificate, err error) {
412	err = autorest.Respond(
413		resp,
414		azure.WithErrorUnlessStatusCode(http.StatusOK),
415		autorest.ByUnmarshallingJSON(&result),
416		autorest.ByClosing())
417	result.Response = autorest.Response{Response: resp}
418	return
419}
420
421// ListByBatchAccount lists all of the certificates in the specified account.
422// Parameters:
423// resourceGroupName - the name of the resource group that contains the Batch account.
424// accountName - the name of the Batch account.
425// maxresults - the maximum number of items to return in the response.
426// selectParameter - comma separated list of properties that should be returned. e.g.
427// "properties/provisioningState". Only top level properties under properties/ are valid for selection.
428// filter - oData filter expression. Valid properties for filtering are "properties/provisioningState",
429// "properties/provisioningStateTransitionTime", "name".
430func (client CertificateClient) ListByBatchAccount(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (result ListCertificatesResultPage, err error) {
431	if tracing.IsEnabled() {
432		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.ListByBatchAccount")
433		defer func() {
434			sc := -1
435			if result.lcr.Response.Response != nil {
436				sc = result.lcr.Response.Response.StatusCode
437			}
438			tracing.EndSpan(ctx, sc, err)
439		}()
440	}
441	if err := validation.Validate([]validation.Validation{
442		{TargetValue: accountName,
443			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
444				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
445				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}}}); err != nil {
446		return result, validation.NewError("batch.CertificateClient", "ListByBatchAccount", err.Error())
447	}
448
449	result.fn = client.listByBatchAccountNextResults
450	req, err := client.ListByBatchAccountPreparer(ctx, resourceGroupName, accountName, maxresults, selectParameter, filter)
451	if err != nil {
452		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", nil, "Failure preparing request")
453		return
454	}
455
456	resp, err := client.ListByBatchAccountSender(req)
457	if err != nil {
458		result.lcr.Response = autorest.Response{Response: resp}
459		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", resp, "Failure sending request")
460		return
461	}
462
463	result.lcr, err = client.ListByBatchAccountResponder(resp)
464	if err != nil {
465		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", resp, "Failure responding to request")
466		return
467	}
468	if result.lcr.hasNextLink() && result.lcr.IsEmpty() {
469		err = result.NextWithContext(ctx)
470		return
471	}
472
473	return
474}
475
476// ListByBatchAccountPreparer prepares the ListByBatchAccount request.
477func (client CertificateClient) ListByBatchAccountPreparer(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (*http.Request, error) {
478	pathParameters := map[string]interface{}{
479		"accountName":       autorest.Encode("path", accountName),
480		"resourceGroupName": autorest.Encode("path", resourceGroupName),
481		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
482	}
483
484	const APIVersion = "2021-06-01"
485	queryParameters := map[string]interface{}{
486		"api-version": APIVersion,
487	}
488	if maxresults != nil {
489		queryParameters["maxresults"] = autorest.Encode("query", *maxresults)
490	}
491	if len(selectParameter) > 0 {
492		queryParameters["$select"] = autorest.Encode("query", selectParameter)
493	}
494	if len(filter) > 0 {
495		queryParameters["$filter"] = autorest.Encode("query", filter)
496	}
497
498	preparer := autorest.CreatePreparer(
499		autorest.AsGet(),
500		autorest.WithBaseURL(client.BaseURI),
501		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates", pathParameters),
502		autorest.WithQueryParameters(queryParameters))
503	return preparer.Prepare((&http.Request{}).WithContext(ctx))
504}
505
506// ListByBatchAccountSender sends the ListByBatchAccount request. The method will close the
507// http.Response Body if it receives an error.
508func (client CertificateClient) ListByBatchAccountSender(req *http.Request) (*http.Response, error) {
509	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
510}
511
512// ListByBatchAccountResponder handles the response to the ListByBatchAccount request. The method always
513// closes the http.Response Body.
514func (client CertificateClient) ListByBatchAccountResponder(resp *http.Response) (result ListCertificatesResult, err error) {
515	err = autorest.Respond(
516		resp,
517		azure.WithErrorUnlessStatusCode(http.StatusOK),
518		autorest.ByUnmarshallingJSON(&result),
519		autorest.ByClosing())
520	result.Response = autorest.Response{Response: resp}
521	return
522}
523
524// listByBatchAccountNextResults retrieves the next set of results, if any.
525func (client CertificateClient) listByBatchAccountNextResults(ctx context.Context, lastResults ListCertificatesResult) (result ListCertificatesResult, err error) {
526	req, err := lastResults.listCertificatesResultPreparer(ctx)
527	if err != nil {
528		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", nil, "Failure preparing next results request")
529	}
530	if req == nil {
531		return
532	}
533	resp, err := client.ListByBatchAccountSender(req)
534	if err != nil {
535		result.Response = autorest.Response{Response: resp}
536		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", resp, "Failure sending next results request")
537	}
538	result, err = client.ListByBatchAccountResponder(resp)
539	if err != nil {
540		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", resp, "Failure responding to next results request")
541	}
542	return
543}
544
545// ListByBatchAccountComplete enumerates all values, automatically crossing page boundaries as required.
546func (client CertificateClient) ListByBatchAccountComplete(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (result ListCertificatesResultIterator, err error) {
547	if tracing.IsEnabled() {
548		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.ListByBatchAccount")
549		defer func() {
550			sc := -1
551			if result.Response().Response.Response != nil {
552				sc = result.page.Response().Response.Response.StatusCode
553			}
554			tracing.EndSpan(ctx, sc, err)
555		}()
556	}
557	result.page, err = client.ListByBatchAccount(ctx, resourceGroupName, accountName, maxresults, selectParameter, filter)
558	return
559}
560
561// Update updates the properties of an existing certificate.
562// Parameters:
563// resourceGroupName - the name of the resource group that contains the Batch account.
564// accountName - the name of the Batch account.
565// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
566// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
567// parameters - certificate entity to update.
568// ifMatch - the entity state (ETag) version of the certificate to update. This value can be omitted or set to
569// "*" to apply the operation unconditionally.
570func (client CertificateClient) Update(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (result Certificate, err error) {
571	if tracing.IsEnabled() {
572		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Update")
573		defer func() {
574			sc := -1
575			if result.Response.Response != nil {
576				sc = result.Response.Response.StatusCode
577			}
578			tracing.EndSpan(ctx, sc, err)
579		}()
580	}
581	if err := validation.Validate([]validation.Validation{
582		{TargetValue: accountName,
583			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
584				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
585				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+$`, Chain: nil}}},
586		{TargetValue: certificateName,
587			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
588				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
589				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
590		return result, validation.NewError("batch.CertificateClient", "Update", err.Error())
591	}
592
593	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, certificateName, parameters, ifMatch)
594	if err != nil {
595		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", nil, "Failure preparing request")
596		return
597	}
598
599	resp, err := client.UpdateSender(req)
600	if err != nil {
601		result.Response = autorest.Response{Response: resp}
602		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", resp, "Failure sending request")
603		return
604	}
605
606	result, err = client.UpdateResponder(resp)
607	if err != nil {
608		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", resp, "Failure responding to request")
609		return
610	}
611
612	return
613}
614
615// UpdatePreparer prepares the Update request.
616func (client CertificateClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (*http.Request, error) {
617	pathParameters := map[string]interface{}{
618		"accountName":       autorest.Encode("path", accountName),
619		"certificateName":   autorest.Encode("path", certificateName),
620		"resourceGroupName": autorest.Encode("path", resourceGroupName),
621		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
622	}
623
624	const APIVersion = "2021-06-01"
625	queryParameters := map[string]interface{}{
626		"api-version": APIVersion,
627	}
628
629	preparer := autorest.CreatePreparer(
630		autorest.AsContentType("application/json; charset=utf-8"),
631		autorest.AsPatch(),
632		autorest.WithBaseURL(client.BaseURI),
633		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
634		autorest.WithJSON(parameters),
635		autorest.WithQueryParameters(queryParameters))
636	if len(ifMatch) > 0 {
637		preparer = autorest.DecoratePreparer(preparer,
638			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
639	}
640	return preparer.Prepare((&http.Request{}).WithContext(ctx))
641}
642
643// UpdateSender sends the Update request. The method will close the
644// http.Response Body if it receives an error.
645func (client CertificateClient) UpdateSender(req *http.Request) (*http.Response, error) {
646	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
647}
648
649// UpdateResponder handles the response to the Update request. The method always
650// closes the http.Response Body.
651func (client CertificateClient) UpdateResponder(resp *http.Response) (result Certificate, err error) {
652	err = autorest.Respond(
653		resp,
654		azure.WithErrorUnlessStatusCode(http.StatusOK),
655		autorest.ByUnmarshallingJSON(&result),
656		autorest.ByClosing())
657	result.Response = autorest.Response{Response: resp}
658	return
659}
660