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