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: `^[-\w\._]+$`, 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 = "2019-04-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 CertificateCreateFuture, err error) {
141	if tracing.IsEnabled() {
142		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Create")
143		defer func() {
144			sc := -1
145			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
146				sc = result.FutureAPI.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: `^[-\w\._]+$`, 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	result, err = client.CreateSender(req)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Create", nil, "Failure sending request")
175		return
176	}
177
178	return
179}
180
181// CreatePreparer prepares the Create request.
182func (client CertificateClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string, ifNoneMatch string) (*http.Request, error) {
183	pathParameters := map[string]interface{}{
184		"accountName":       autorest.Encode("path", accountName),
185		"certificateName":   autorest.Encode("path", certificateName),
186		"resourceGroupName": autorest.Encode("path", resourceGroupName),
187		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
188	}
189
190	const APIVersion = "2019-04-01"
191	queryParameters := map[string]interface{}{
192		"api-version": APIVersion,
193	}
194
195	preparer := autorest.CreatePreparer(
196		autorest.AsContentType("application/json; charset=utf-8"),
197		autorest.AsPut(),
198		autorest.WithBaseURL(client.BaseURI),
199		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
200		autorest.WithJSON(parameters),
201		autorest.WithQueryParameters(queryParameters))
202	if len(ifMatch) > 0 {
203		preparer = autorest.DecoratePreparer(preparer,
204			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
205	}
206	if len(ifNoneMatch) > 0 {
207		preparer = autorest.DecoratePreparer(preparer,
208			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
209	}
210	return preparer.Prepare((&http.Request{}).WithContext(ctx))
211}
212
213// CreateSender sends the Create request. The method will close the
214// http.Response Body if it receives an error.
215func (client CertificateClient) CreateSender(req *http.Request) (future CertificateCreateFuture, err error) {
216	var resp *http.Response
217	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
218	if err != nil {
219		return
220	}
221	var azf azure.Future
222	azf, err = azure.NewFutureFromResponse(resp)
223	future.FutureAPI = &azf
224	future.Result = future.result
225	return
226}
227
228// CreateResponder handles the response to the Create request. The method always
229// closes the http.Response Body.
230func (client CertificateClient) CreateResponder(resp *http.Response) (result Certificate, err error) {
231	err = autorest.Respond(
232		resp,
233		azure.WithErrorUnlessStatusCode(http.StatusOK),
234		autorest.ByUnmarshallingJSON(&result),
235		autorest.ByClosing())
236	result.Response = autorest.Response{Response: resp}
237	return
238}
239
240// Delete deletes the specified certificate.
241// Parameters:
242// resourceGroupName - the name of the resource group that contains the Batch account.
243// accountName - the name of the Batch account.
244// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
245// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
246func (client CertificateClient) Delete(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (result CertificateDeleteFuture, err error) {
247	if tracing.IsEnabled() {
248		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Delete")
249		defer func() {
250			sc := -1
251			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
252				sc = result.FutureAPI.Response().StatusCode
253			}
254			tracing.EndSpan(ctx, sc, err)
255		}()
256	}
257	if err := validation.Validate([]validation.Validation{
258		{TargetValue: accountName,
259			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
260				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
261				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
262		{TargetValue: certificateName,
263			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
264				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
265				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
266		return result, validation.NewError("batch.CertificateClient", "Delete", err.Error())
267	}
268
269	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, certificateName)
270	if err != nil {
271		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", nil, "Failure preparing request")
272		return
273	}
274
275	result, err = client.DeleteSender(req)
276	if err != nil {
277		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Delete", nil, "Failure sending request")
278		return
279	}
280
281	return
282}
283
284// DeletePreparer prepares the Delete request.
285func (client CertificateClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (*http.Request, error) {
286	pathParameters := map[string]interface{}{
287		"accountName":       autorest.Encode("path", accountName),
288		"certificateName":   autorest.Encode("path", certificateName),
289		"resourceGroupName": autorest.Encode("path", resourceGroupName),
290		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
291	}
292
293	const APIVersion = "2019-04-01"
294	queryParameters := map[string]interface{}{
295		"api-version": APIVersion,
296	}
297
298	preparer := autorest.CreatePreparer(
299		autorest.AsDelete(),
300		autorest.WithBaseURL(client.BaseURI),
301		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
302		autorest.WithQueryParameters(queryParameters))
303	return preparer.Prepare((&http.Request{}).WithContext(ctx))
304}
305
306// DeleteSender sends the Delete request. The method will close the
307// http.Response Body if it receives an error.
308func (client CertificateClient) DeleteSender(req *http.Request) (future CertificateDeleteFuture, err error) {
309	var resp *http.Response
310	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
311	if err != nil {
312		return
313	}
314	var azf azure.Future
315	azf, err = azure.NewFutureFromResponse(resp)
316	future.FutureAPI = &azf
317	future.Result = future.result
318	return
319}
320
321// DeleteResponder handles the response to the Delete request. The method always
322// closes the http.Response Body.
323func (client CertificateClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
324	err = autorest.Respond(
325		resp,
326		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
327		autorest.ByClosing())
328	result.Response = resp
329	return
330}
331
332// Get gets information about the specified certificate.
333// Parameters:
334// resourceGroupName - the name of the resource group that contains the Batch account.
335// accountName - the name of the Batch account.
336// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
337// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
338func (client CertificateClient) Get(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (result Certificate, err error) {
339	if tracing.IsEnabled() {
340		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Get")
341		defer func() {
342			sc := -1
343			if result.Response.Response != nil {
344				sc = result.Response.Response.StatusCode
345			}
346			tracing.EndSpan(ctx, sc, err)
347		}()
348	}
349	if err := validation.Validate([]validation.Validation{
350		{TargetValue: accountName,
351			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
352				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
353				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
354		{TargetValue: certificateName,
355			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
356				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
357				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
358		return result, validation.NewError("batch.CertificateClient", "Get", err.Error())
359	}
360
361	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, certificateName)
362	if err != nil {
363		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", nil, "Failure preparing request")
364		return
365	}
366
367	resp, err := client.GetSender(req)
368	if err != nil {
369		result.Response = autorest.Response{Response: resp}
370		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure sending request")
371		return
372	}
373
374	result, err = client.GetResponder(resp)
375	if err != nil {
376		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Get", resp, "Failure responding to request")
377		return
378	}
379
380	return
381}
382
383// GetPreparer prepares the Get request.
384func (client CertificateClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string) (*http.Request, error) {
385	pathParameters := map[string]interface{}{
386		"accountName":       autorest.Encode("path", accountName),
387		"certificateName":   autorest.Encode("path", certificateName),
388		"resourceGroupName": autorest.Encode("path", resourceGroupName),
389		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
390	}
391
392	const APIVersion = "2019-04-01"
393	queryParameters := map[string]interface{}{
394		"api-version": APIVersion,
395	}
396
397	preparer := autorest.CreatePreparer(
398		autorest.AsGet(),
399		autorest.WithBaseURL(client.BaseURI),
400		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
401		autorest.WithQueryParameters(queryParameters))
402	return preparer.Prepare((&http.Request{}).WithContext(ctx))
403}
404
405// GetSender sends the Get request. The method will close the
406// http.Response Body if it receives an error.
407func (client CertificateClient) GetSender(req *http.Request) (*http.Response, error) {
408	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
409}
410
411// GetResponder handles the response to the Get request. The method always
412// closes the http.Response Body.
413func (client CertificateClient) GetResponder(resp *http.Response) (result Certificate, err error) {
414	err = autorest.Respond(
415		resp,
416		azure.WithErrorUnlessStatusCode(http.StatusOK),
417		autorest.ByUnmarshallingJSON(&result),
418		autorest.ByClosing())
419	result.Response = autorest.Response{Response: resp}
420	return
421}
422
423// ListByBatchAccount lists all of the certificates in the specified account.
424// Parameters:
425// resourceGroupName - the name of the resource group that contains the Batch account.
426// accountName - the name of the Batch account.
427// maxresults - the maximum number of items to return in the response.
428// selectParameter - comma separated list of properties that should be returned. e.g.
429// "properties/provisioningState". Only top level properties under properties/ are valid for selection.
430// filter - oData filter expression. Valid properties for filtering are "properties/provisioningState",
431// "properties/provisioningStateTransitionTime", "name".
432func (client CertificateClient) ListByBatchAccount(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (result ListCertificatesResultPage, err error) {
433	if tracing.IsEnabled() {
434		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.ListByBatchAccount")
435		defer func() {
436			sc := -1
437			if result.lcr.Response.Response != nil {
438				sc = result.lcr.Response.Response.StatusCode
439			}
440			tracing.EndSpan(ctx, sc, err)
441		}()
442	}
443	if err := validation.Validate([]validation.Validation{
444		{TargetValue: accountName,
445			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
446				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
447				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
448		return result, validation.NewError("batch.CertificateClient", "ListByBatchAccount", err.Error())
449	}
450
451	result.fn = client.listByBatchAccountNextResults
452	req, err := client.ListByBatchAccountPreparer(ctx, resourceGroupName, accountName, maxresults, selectParameter, filter)
453	if err != nil {
454		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", nil, "Failure preparing request")
455		return
456	}
457
458	resp, err := client.ListByBatchAccountSender(req)
459	if err != nil {
460		result.lcr.Response = autorest.Response{Response: resp}
461		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", resp, "Failure sending request")
462		return
463	}
464
465	result.lcr, err = client.ListByBatchAccountResponder(resp)
466	if err != nil {
467		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "ListByBatchAccount", resp, "Failure responding to request")
468		return
469	}
470	if result.lcr.hasNextLink() && result.lcr.IsEmpty() {
471		err = result.NextWithContext(ctx)
472		return
473	}
474
475	return
476}
477
478// ListByBatchAccountPreparer prepares the ListByBatchAccount request.
479func (client CertificateClient) ListByBatchAccountPreparer(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (*http.Request, error) {
480	pathParameters := map[string]interface{}{
481		"accountName":       autorest.Encode("path", accountName),
482		"resourceGroupName": autorest.Encode("path", resourceGroupName),
483		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
484	}
485
486	const APIVersion = "2019-04-01"
487	queryParameters := map[string]interface{}{
488		"api-version": APIVersion,
489	}
490	if maxresults != nil {
491		queryParameters["maxresults"] = autorest.Encode("query", *maxresults)
492	}
493	if len(selectParameter) > 0 {
494		queryParameters["$select"] = autorest.Encode("query", selectParameter)
495	}
496	if len(filter) > 0 {
497		queryParameters["$filter"] = autorest.Encode("query", filter)
498	}
499
500	preparer := autorest.CreatePreparer(
501		autorest.AsGet(),
502		autorest.WithBaseURL(client.BaseURI),
503		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates", pathParameters),
504		autorest.WithQueryParameters(queryParameters))
505	return preparer.Prepare((&http.Request{}).WithContext(ctx))
506}
507
508// ListByBatchAccountSender sends the ListByBatchAccount request. The method will close the
509// http.Response Body if it receives an error.
510func (client CertificateClient) ListByBatchAccountSender(req *http.Request) (*http.Response, error) {
511	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
512}
513
514// ListByBatchAccountResponder handles the response to the ListByBatchAccount request. The method always
515// closes the http.Response Body.
516func (client CertificateClient) ListByBatchAccountResponder(resp *http.Response) (result ListCertificatesResult, err error) {
517	err = autorest.Respond(
518		resp,
519		azure.WithErrorUnlessStatusCode(http.StatusOK),
520		autorest.ByUnmarshallingJSON(&result),
521		autorest.ByClosing())
522	result.Response = autorest.Response{Response: resp}
523	return
524}
525
526// listByBatchAccountNextResults retrieves the next set of results, if any.
527func (client CertificateClient) listByBatchAccountNextResults(ctx context.Context, lastResults ListCertificatesResult) (result ListCertificatesResult, err error) {
528	req, err := lastResults.listCertificatesResultPreparer(ctx)
529	if err != nil {
530		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", nil, "Failure preparing next results request")
531	}
532	if req == nil {
533		return
534	}
535	resp, err := client.ListByBatchAccountSender(req)
536	if err != nil {
537		result.Response = autorest.Response{Response: resp}
538		return result, autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", resp, "Failure sending next results request")
539	}
540	result, err = client.ListByBatchAccountResponder(resp)
541	if err != nil {
542		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "listByBatchAccountNextResults", resp, "Failure responding to next results request")
543	}
544	return
545}
546
547// ListByBatchAccountComplete enumerates all values, automatically crossing page boundaries as required.
548func (client CertificateClient) ListByBatchAccountComplete(ctx context.Context, resourceGroupName string, accountName string, maxresults *int32, selectParameter string, filter string) (result ListCertificatesResultIterator, err error) {
549	if tracing.IsEnabled() {
550		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.ListByBatchAccount")
551		defer func() {
552			sc := -1
553			if result.Response().Response.Response != nil {
554				sc = result.page.Response().Response.Response.StatusCode
555			}
556			tracing.EndSpan(ctx, sc, err)
557		}()
558	}
559	result.page, err = client.ListByBatchAccount(ctx, resourceGroupName, accountName, maxresults, selectParameter, filter)
560	return
561}
562
563// Update updates the properties of an existing certificate.
564// Parameters:
565// resourceGroupName - the name of the resource group that contains the Batch account.
566// accountName - the name of the Batch account.
567// certificateName - the identifier for the certificate. This must be made up of algorithm and thumbprint
568// separated by a dash, and must match the certificate data in the request. For example SHA1-a3d1c5.
569// parameters - certificate entity to update.
570// ifMatch - the entity state (ETag) version of the certificate to update. This value can be omitted or set to
571// "*" to apply the operation unconditionally.
572func (client CertificateClient) Update(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (result Certificate, err error) {
573	if tracing.IsEnabled() {
574		ctx = tracing.StartSpan(ctx, fqdn+"/CertificateClient.Update")
575		defer func() {
576			sc := -1
577			if result.Response.Response != nil {
578				sc = result.Response.Response.StatusCode
579			}
580			tracing.EndSpan(ctx, sc, err)
581		}()
582	}
583	if err := validation.Validate([]validation.Validation{
584		{TargetValue: accountName,
585			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
586				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
587				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
588		{TargetValue: certificateName,
589			Constraints: []validation.Constraint{{Target: "certificateName", Name: validation.MaxLength, Rule: 45, Chain: nil},
590				{Target: "certificateName", Name: validation.MinLength, Rule: 5, Chain: nil},
591				{Target: "certificateName", Name: validation.Pattern, Rule: `^[\w]+-[\w]+$`, Chain: nil}}}}); err != nil {
592		return result, validation.NewError("batch.CertificateClient", "Update", err.Error())
593	}
594
595	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, certificateName, parameters, ifMatch)
596	if err != nil {
597		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", nil, "Failure preparing request")
598		return
599	}
600
601	resp, err := client.UpdateSender(req)
602	if err != nil {
603		result.Response = autorest.Response{Response: resp}
604		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", resp, "Failure sending request")
605		return
606	}
607
608	result, err = client.UpdateResponder(resp)
609	if err != nil {
610		err = autorest.NewErrorWithError(err, "batch.CertificateClient", "Update", resp, "Failure responding to request")
611		return
612	}
613
614	return
615}
616
617// UpdatePreparer prepares the Update request.
618func (client CertificateClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, certificateName string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (*http.Request, error) {
619	pathParameters := map[string]interface{}{
620		"accountName":       autorest.Encode("path", accountName),
621		"certificateName":   autorest.Encode("path", certificateName),
622		"resourceGroupName": autorest.Encode("path", resourceGroupName),
623		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
624	}
625
626	const APIVersion = "2019-04-01"
627	queryParameters := map[string]interface{}{
628		"api-version": APIVersion,
629	}
630
631	preparer := autorest.CreatePreparer(
632		autorest.AsContentType("application/json; charset=utf-8"),
633		autorest.AsPatch(),
634		autorest.WithBaseURL(client.BaseURI),
635		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates/{certificateName}", pathParameters),
636		autorest.WithJSON(parameters),
637		autorest.WithQueryParameters(queryParameters))
638	if len(ifMatch) > 0 {
639		preparer = autorest.DecoratePreparer(preparer,
640			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
641	}
642	return preparer.Prepare((&http.Request{}).WithContext(ctx))
643}
644
645// UpdateSender sends the Update request. The method will close the
646// http.Response Body if it receives an error.
647func (client CertificateClient) UpdateSender(req *http.Request) (*http.Response, error) {
648	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
649}
650
651// UpdateResponder handles the response to the Update request. The method always
652// closes the http.Response Body.
653func (client CertificateClient) UpdateResponder(resp *http.Response) (result Certificate, err error) {
654	err = autorest.Respond(
655		resp,
656		azure.WithErrorUnlessStatusCode(http.StatusOK),
657		autorest.ByUnmarshallingJSON(&result),
658		autorest.ByClosing())
659	result.Response = autorest.Response{Response: resp}
660	return
661}
662