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// AccountClient is the client for the Account methods of the Batch service.
30type AccountClient struct {
31	BaseClient
32}
33
34// NewAccountClient creates an instance of the AccountClient client.
35func NewAccountClient(subscriptionID string) AccountClient {
36	return NewAccountClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAccountClientWithBaseURI creates an instance of the AccountClient client.
40func NewAccountClientWithBaseURI(baseURI string, subscriptionID string) AccountClient {
41	return AccountClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Create creates a new Batch account with the specified parameters. Existing accounts cannot be updated with this API
45// and should instead be updated with the Update Batch Account API.
46// Parameters:
47// resourceGroupName - the name of the resource group that contains the Batch account.
48// accountName - a name for the Batch account which must be unique within the region. Batch account names must
49// be between 3 and 24 characters in length and must use only numbers and lowercase letters. This name is used
50// as part of the DNS name that is used to access the Batch service in the region in which the account is
51// created. For example: http://accountname.region.batch.azure.com/.
52// parameters - additional parameters for account creation.
53func (client AccountClient) Create(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (result AccountCreateFuture, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Create")
56		defer func() {
57			sc := -1
58			if result.Response() != nil {
59				sc = result.Response().StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	if err := validation.Validate([]validation.Validation{
65		{TargetValue: resourceGroupName,
66			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
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: parameters,
72			Constraints: []validation.Constraint{{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil},
73				{Target: "parameters.AccountCreateProperties", Name: validation.Null, Rule: false,
74					Chain: []validation.Constraint{{Target: "parameters.AccountCreateProperties.AutoStorage", Name: validation.Null, Rule: false,
75						Chain: []validation.Constraint{{Target: "parameters.AccountCreateProperties.AutoStorage.StorageAccountID", Name: validation.Null, Rule: true, Chain: nil}}},
76						{Target: "parameters.AccountCreateProperties.KeyVaultReference", Name: validation.Null, Rule: false,
77							Chain: []validation.Constraint{{Target: "parameters.AccountCreateProperties.KeyVaultReference.ID", Name: validation.Null, Rule: true, Chain: nil},
78								{Target: "parameters.AccountCreateProperties.KeyVaultReference.URL", Name: validation.Null, Rule: true, Chain: nil},
79							}},
80					}}}}}); err != nil {
81		return result, validation.NewError("batch.AccountClient", "Create", err.Error())
82	}
83
84	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, parameters)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Create", nil, "Failure preparing request")
87		return
88	}
89
90	result, err = client.CreateSender(req)
91	if err != nil {
92		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Create", result.Response(), "Failure sending request")
93		return
94	}
95
96	return
97}
98
99// CreatePreparer prepares the Create request.
100func (client AccountClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (*http.Request, error) {
101	pathParameters := map[string]interface{}{
102		"accountName":       autorest.Encode("path", accountName),
103		"resourceGroupName": autorest.Encode("path", resourceGroupName),
104		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
105	}
106
107	const APIVersion = "2017-05-01"
108	queryParameters := map[string]interface{}{
109		"api-version": APIVersion,
110	}
111
112	preparer := autorest.CreatePreparer(
113		autorest.AsContentType("application/json; charset=utf-8"),
114		autorest.AsPut(),
115		autorest.WithBaseURL(client.BaseURI),
116		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
117		autorest.WithJSON(parameters),
118		autorest.WithQueryParameters(queryParameters))
119	return preparer.Prepare((&http.Request{}).WithContext(ctx))
120}
121
122// CreateSender sends the Create request. The method will close the
123// http.Response Body if it receives an error.
124func (client AccountClient) CreateSender(req *http.Request) (future AccountCreateFuture, err error) {
125	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
126	var resp *http.Response
127	resp, err = autorest.SendWithSender(client, req, sd...)
128	if err != nil {
129		return
130	}
131	future.Future, err = azure.NewFutureFromResponse(resp)
132	return
133}
134
135// CreateResponder handles the response to the Create request. The method always
136// closes the http.Response Body.
137func (client AccountClient) CreateResponder(resp *http.Response) (result Account, err error) {
138	err = autorest.Respond(
139		resp,
140		client.ByInspecting(),
141		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
142		autorest.ByUnmarshallingJSON(&result),
143		autorest.ByClosing())
144	result.Response = autorest.Response{Response: resp}
145	return
146}
147
148// Delete deletes the specified Batch account.
149// Parameters:
150// resourceGroupName - the name of the resource group that contains the Batch account.
151// accountName - the name of the Batch account.
152func (client AccountClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result AccountDeleteFuture, err error) {
153	if tracing.IsEnabled() {
154		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Delete")
155		defer func() {
156			sc := -1
157			if result.Response() != nil {
158				sc = result.Response().StatusCode
159			}
160			tracing.EndSpan(ctx, sc, err)
161		}()
162	}
163	if err := validation.Validate([]validation.Validation{
164		{TargetValue: resourceGroupName,
165			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
166		{TargetValue: accountName,
167			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
168				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
169				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
170		return result, validation.NewError("batch.AccountClient", "Delete", err.Error())
171	}
172
173	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName)
174	if err != nil {
175		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Delete", nil, "Failure preparing request")
176		return
177	}
178
179	result, err = client.DeleteSender(req)
180	if err != nil {
181		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Delete", result.Response(), "Failure sending request")
182		return
183	}
184
185	return
186}
187
188// DeletePreparer prepares the Delete request.
189func (client AccountClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
190	pathParameters := map[string]interface{}{
191		"accountName":       autorest.Encode("path", accountName),
192		"resourceGroupName": autorest.Encode("path", resourceGroupName),
193		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
194	}
195
196	const APIVersion = "2017-05-01"
197	queryParameters := map[string]interface{}{
198		"api-version": APIVersion,
199	}
200
201	preparer := autorest.CreatePreparer(
202		autorest.AsDelete(),
203		autorest.WithBaseURL(client.BaseURI),
204		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
205		autorest.WithQueryParameters(queryParameters))
206	return preparer.Prepare((&http.Request{}).WithContext(ctx))
207}
208
209// DeleteSender sends the Delete request. The method will close the
210// http.Response Body if it receives an error.
211func (client AccountClient) DeleteSender(req *http.Request) (future AccountDeleteFuture, err error) {
212	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
213	var resp *http.Response
214	resp, err = autorest.SendWithSender(client, req, sd...)
215	if err != nil {
216		return
217	}
218	future.Future, err = azure.NewFutureFromResponse(resp)
219	return
220}
221
222// DeleteResponder handles the response to the Delete request. The method always
223// closes the http.Response Body.
224func (client AccountClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
225	err = autorest.Respond(
226		resp,
227		client.ByInspecting(),
228		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
229		autorest.ByClosing())
230	result.Response = resp
231	return
232}
233
234// Get gets information about the specified Batch account.
235// Parameters:
236// resourceGroupName - the name of the resource group that contains the Batch account.
237// accountName - the name of the Batch account.
238func (client AccountClient) Get(ctx context.Context, resourceGroupName string, accountName string) (result Account, err error) {
239	if tracing.IsEnabled() {
240		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Get")
241		defer func() {
242			sc := -1
243			if result.Response.Response != nil {
244				sc = result.Response.Response.StatusCode
245			}
246			tracing.EndSpan(ctx, sc, err)
247		}()
248	}
249	if err := validation.Validate([]validation.Validation{
250		{TargetValue: resourceGroupName,
251			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
252		{TargetValue: accountName,
253			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
254				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
255				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
256		return result, validation.NewError("batch.AccountClient", "Get", err.Error())
257	}
258
259	req, err := client.GetPreparer(ctx, resourceGroupName, accountName)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", nil, "Failure preparing request")
262		return
263	}
264
265	resp, err := client.GetSender(req)
266	if err != nil {
267		result.Response = autorest.Response{Response: resp}
268		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", resp, "Failure sending request")
269		return
270	}
271
272	result, err = client.GetResponder(resp)
273	if err != nil {
274		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", resp, "Failure responding to request")
275	}
276
277	return
278}
279
280// GetPreparer prepares the Get request.
281func (client AccountClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
282	pathParameters := map[string]interface{}{
283		"accountName":       autorest.Encode("path", accountName),
284		"resourceGroupName": autorest.Encode("path", resourceGroupName),
285		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
286	}
287
288	const APIVersion = "2017-05-01"
289	queryParameters := map[string]interface{}{
290		"api-version": APIVersion,
291	}
292
293	preparer := autorest.CreatePreparer(
294		autorest.AsGet(),
295		autorest.WithBaseURL(client.BaseURI),
296		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
297		autorest.WithQueryParameters(queryParameters))
298	return preparer.Prepare((&http.Request{}).WithContext(ctx))
299}
300
301// GetSender sends the Get request. The method will close the
302// http.Response Body if it receives an error.
303func (client AccountClient) GetSender(req *http.Request) (*http.Response, error) {
304	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
305	return autorest.SendWithSender(client, req, sd...)
306}
307
308// GetResponder handles the response to the Get request. The method always
309// closes the http.Response Body.
310func (client AccountClient) GetResponder(resp *http.Response) (result Account, err error) {
311	err = autorest.Respond(
312		resp,
313		client.ByInspecting(),
314		azure.WithErrorUnlessStatusCode(http.StatusOK),
315		autorest.ByUnmarshallingJSON(&result),
316		autorest.ByClosing())
317	result.Response = autorest.Response{Response: resp}
318	return
319}
320
321// GetKeys this operation applies only to Batch accounts created with a poolAllocationMode of 'BatchService'. If the
322// Batch account was created with a poolAllocationMode of 'UserSubscription', clients cannot use access to keys to
323// authenticate, and must use Azure Active Directory instead. In this case, getting the keys will fail.
324// Parameters:
325// resourceGroupName - the name of the resource group that contains the Batch account.
326// accountName - the name of the Batch account.
327func (client AccountClient) GetKeys(ctx context.Context, resourceGroupName string, accountName string) (result AccountKeys, err error) {
328	if tracing.IsEnabled() {
329		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.GetKeys")
330		defer func() {
331			sc := -1
332			if result.Response.Response != nil {
333				sc = result.Response.Response.StatusCode
334			}
335			tracing.EndSpan(ctx, sc, err)
336		}()
337	}
338	if err := validation.Validate([]validation.Validation{
339		{TargetValue: resourceGroupName,
340			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
341		{TargetValue: accountName,
342			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
343				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
344				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
345		return result, validation.NewError("batch.AccountClient", "GetKeys", err.Error())
346	}
347
348	req, err := client.GetKeysPreparer(ctx, resourceGroupName, accountName)
349	if err != nil {
350		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", nil, "Failure preparing request")
351		return
352	}
353
354	resp, err := client.GetKeysSender(req)
355	if err != nil {
356		result.Response = autorest.Response{Response: resp}
357		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", resp, "Failure sending request")
358		return
359	}
360
361	result, err = client.GetKeysResponder(resp)
362	if err != nil {
363		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", resp, "Failure responding to request")
364	}
365
366	return
367}
368
369// GetKeysPreparer prepares the GetKeys request.
370func (client AccountClient) GetKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
371	pathParameters := map[string]interface{}{
372		"accountName":       autorest.Encode("path", accountName),
373		"resourceGroupName": autorest.Encode("path", resourceGroupName),
374		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
375	}
376
377	const APIVersion = "2017-05-01"
378	queryParameters := map[string]interface{}{
379		"api-version": APIVersion,
380	}
381
382	preparer := autorest.CreatePreparer(
383		autorest.AsPost(),
384		autorest.WithBaseURL(client.BaseURI),
385		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/listKeys", pathParameters),
386		autorest.WithQueryParameters(queryParameters))
387	return preparer.Prepare((&http.Request{}).WithContext(ctx))
388}
389
390// GetKeysSender sends the GetKeys request. The method will close the
391// http.Response Body if it receives an error.
392func (client AccountClient) GetKeysSender(req *http.Request) (*http.Response, error) {
393	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
394	return autorest.SendWithSender(client, req, sd...)
395}
396
397// GetKeysResponder handles the response to the GetKeys request. The method always
398// closes the http.Response Body.
399func (client AccountClient) GetKeysResponder(resp *http.Response) (result AccountKeys, err error) {
400	err = autorest.Respond(
401		resp,
402		client.ByInspecting(),
403		azure.WithErrorUnlessStatusCode(http.StatusOK),
404		autorest.ByUnmarshallingJSON(&result),
405		autorest.ByClosing())
406	result.Response = autorest.Response{Response: resp}
407	return
408}
409
410// List gets information about the Batch accounts associated with the subscription.
411func (client AccountClient) List(ctx context.Context) (result AccountListResultPage, err error) {
412	if tracing.IsEnabled() {
413		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.List")
414		defer func() {
415			sc := -1
416			if result.alr.Response.Response != nil {
417				sc = result.alr.Response.Response.StatusCode
418			}
419			tracing.EndSpan(ctx, sc, err)
420		}()
421	}
422	result.fn = client.listNextResults
423	req, err := client.ListPreparer(ctx)
424	if err != nil {
425		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", nil, "Failure preparing request")
426		return
427	}
428
429	resp, err := client.ListSender(req)
430	if err != nil {
431		result.alr.Response = autorest.Response{Response: resp}
432		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", resp, "Failure sending request")
433		return
434	}
435
436	result.alr, err = client.ListResponder(resp)
437	if err != nil {
438		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", resp, "Failure responding to request")
439	}
440
441	return
442}
443
444// ListPreparer prepares the List request.
445func (client AccountClient) ListPreparer(ctx context.Context) (*http.Request, error) {
446	pathParameters := map[string]interface{}{
447		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
448	}
449
450	const APIVersion = "2017-05-01"
451	queryParameters := map[string]interface{}{
452		"api-version": APIVersion,
453	}
454
455	preparer := autorest.CreatePreparer(
456		autorest.AsGet(),
457		autorest.WithBaseURL(client.BaseURI),
458		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/batchAccounts", pathParameters),
459		autorest.WithQueryParameters(queryParameters))
460	return preparer.Prepare((&http.Request{}).WithContext(ctx))
461}
462
463// ListSender sends the List request. The method will close the
464// http.Response Body if it receives an error.
465func (client AccountClient) ListSender(req *http.Request) (*http.Response, error) {
466	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
467	return autorest.SendWithSender(client, req, sd...)
468}
469
470// ListResponder handles the response to the List request. The method always
471// closes the http.Response Body.
472func (client AccountClient) ListResponder(resp *http.Response) (result AccountListResult, err error) {
473	err = autorest.Respond(
474		resp,
475		client.ByInspecting(),
476		azure.WithErrorUnlessStatusCode(http.StatusOK),
477		autorest.ByUnmarshallingJSON(&result),
478		autorest.ByClosing())
479	result.Response = autorest.Response{Response: resp}
480	return
481}
482
483// listNextResults retrieves the next set of results, if any.
484func (client AccountClient) listNextResults(ctx context.Context, lastResults AccountListResult) (result AccountListResult, err error) {
485	req, err := lastResults.accountListResultPreparer(ctx)
486	if err != nil {
487		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", nil, "Failure preparing next results request")
488	}
489	if req == nil {
490		return
491	}
492	resp, err := client.ListSender(req)
493	if err != nil {
494		result.Response = autorest.Response{Response: resp}
495		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", resp, "Failure sending next results request")
496	}
497	result, err = client.ListResponder(resp)
498	if err != nil {
499		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", resp, "Failure responding to next results request")
500	}
501	return
502}
503
504// ListComplete enumerates all values, automatically crossing page boundaries as required.
505func (client AccountClient) ListComplete(ctx context.Context) (result AccountListResultIterator, err error) {
506	if tracing.IsEnabled() {
507		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.List")
508		defer func() {
509			sc := -1
510			if result.Response().Response.Response != nil {
511				sc = result.page.Response().Response.Response.StatusCode
512			}
513			tracing.EndSpan(ctx, sc, err)
514		}()
515	}
516	result.page, err = client.List(ctx)
517	return
518}
519
520// ListByResourceGroup gets information about the Batch accounts associated with the specified resource group.
521// Parameters:
522// resourceGroupName - the name of the resource group that contains the Batch account.
523func (client AccountClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResultPage, err error) {
524	if tracing.IsEnabled() {
525		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListByResourceGroup")
526		defer func() {
527			sc := -1
528			if result.alr.Response.Response != nil {
529				sc = result.alr.Response.Response.StatusCode
530			}
531			tracing.EndSpan(ctx, sc, err)
532		}()
533	}
534	if err := validation.Validate([]validation.Validation{
535		{TargetValue: resourceGroupName,
536			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
537		return result, validation.NewError("batch.AccountClient", "ListByResourceGroup", err.Error())
538	}
539
540	result.fn = client.listByResourceGroupNextResults
541	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
542	if err != nil {
543		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", nil, "Failure preparing request")
544		return
545	}
546
547	resp, err := client.ListByResourceGroupSender(req)
548	if err != nil {
549		result.alr.Response = autorest.Response{Response: resp}
550		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", resp, "Failure sending request")
551		return
552	}
553
554	result.alr, err = client.ListByResourceGroupResponder(resp)
555	if err != nil {
556		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", resp, "Failure responding to request")
557	}
558
559	return
560}
561
562// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
563func (client AccountClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
564	pathParameters := map[string]interface{}{
565		"resourceGroupName": autorest.Encode("path", resourceGroupName),
566		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
567	}
568
569	const APIVersion = "2017-05-01"
570	queryParameters := map[string]interface{}{
571		"api-version": APIVersion,
572	}
573
574	preparer := autorest.CreatePreparer(
575		autorest.AsGet(),
576		autorest.WithBaseURL(client.BaseURI),
577		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts", pathParameters),
578		autorest.WithQueryParameters(queryParameters))
579	return preparer.Prepare((&http.Request{}).WithContext(ctx))
580}
581
582// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
583// http.Response Body if it receives an error.
584func (client AccountClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
585	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
586	return autorest.SendWithSender(client, req, sd...)
587}
588
589// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
590// closes the http.Response Body.
591func (client AccountClient) ListByResourceGroupResponder(resp *http.Response) (result AccountListResult, err error) {
592	err = autorest.Respond(
593		resp,
594		client.ByInspecting(),
595		azure.WithErrorUnlessStatusCode(http.StatusOK),
596		autorest.ByUnmarshallingJSON(&result),
597		autorest.ByClosing())
598	result.Response = autorest.Response{Response: resp}
599	return
600}
601
602// listByResourceGroupNextResults retrieves the next set of results, if any.
603func (client AccountClient) listByResourceGroupNextResults(ctx context.Context, lastResults AccountListResult) (result AccountListResult, err error) {
604	req, err := lastResults.accountListResultPreparer(ctx)
605	if err != nil {
606		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
607	}
608	if req == nil {
609		return
610	}
611	resp, err := client.ListByResourceGroupSender(req)
612	if err != nil {
613		result.Response = autorest.Response{Response: resp}
614		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
615	}
616	result, err = client.ListByResourceGroupResponder(resp)
617	if err != nil {
618		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
619	}
620	return
621}
622
623// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
624func (client AccountClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AccountListResultIterator, err error) {
625	if tracing.IsEnabled() {
626		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListByResourceGroup")
627		defer func() {
628			sc := -1
629			if result.Response().Response.Response != nil {
630				sc = result.page.Response().Response.Response.StatusCode
631			}
632			tracing.EndSpan(ctx, sc, err)
633		}()
634	}
635	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
636	return
637}
638
639// RegenerateKey regenerates the specified account key for the Batch account.
640// Parameters:
641// resourceGroupName - the name of the resource group that contains the Batch account.
642// accountName - the name of the Batch account.
643// parameters - the type of key to regenerate.
644func (client AccountClient) RegenerateKey(ctx context.Context, resourceGroupName string, accountName string, parameters AccountRegenerateKeyParameters) (result AccountKeys, err error) {
645	if tracing.IsEnabled() {
646		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.RegenerateKey")
647		defer func() {
648			sc := -1
649			if result.Response.Response != nil {
650				sc = result.Response.Response.StatusCode
651			}
652			tracing.EndSpan(ctx, sc, err)
653		}()
654	}
655	if err := validation.Validate([]validation.Validation{
656		{TargetValue: resourceGroupName,
657			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
658		{TargetValue: accountName,
659			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
660				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
661				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
662		return result, validation.NewError("batch.AccountClient", "RegenerateKey", err.Error())
663	}
664
665	req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, accountName, parameters)
666	if err != nil {
667		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", nil, "Failure preparing request")
668		return
669	}
670
671	resp, err := client.RegenerateKeySender(req)
672	if err != nil {
673		result.Response = autorest.Response{Response: resp}
674		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", resp, "Failure sending request")
675		return
676	}
677
678	result, err = client.RegenerateKeyResponder(resp)
679	if err != nil {
680		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", resp, "Failure responding to request")
681	}
682
683	return
684}
685
686// RegenerateKeyPreparer prepares the RegenerateKey request.
687func (client AccountClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountRegenerateKeyParameters) (*http.Request, error) {
688	pathParameters := map[string]interface{}{
689		"accountName":       autorest.Encode("path", accountName),
690		"resourceGroupName": autorest.Encode("path", resourceGroupName),
691		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
692	}
693
694	const APIVersion = "2017-05-01"
695	queryParameters := map[string]interface{}{
696		"api-version": APIVersion,
697	}
698
699	preparer := autorest.CreatePreparer(
700		autorest.AsContentType("application/json; charset=utf-8"),
701		autorest.AsPost(),
702		autorest.WithBaseURL(client.BaseURI),
703		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/regenerateKeys", pathParameters),
704		autorest.WithJSON(parameters),
705		autorest.WithQueryParameters(queryParameters))
706	return preparer.Prepare((&http.Request{}).WithContext(ctx))
707}
708
709// RegenerateKeySender sends the RegenerateKey request. The method will close the
710// http.Response Body if it receives an error.
711func (client AccountClient) RegenerateKeySender(req *http.Request) (*http.Response, error) {
712	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
713	return autorest.SendWithSender(client, req, sd...)
714}
715
716// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always
717// closes the http.Response Body.
718func (client AccountClient) RegenerateKeyResponder(resp *http.Response) (result AccountKeys, err error) {
719	err = autorest.Respond(
720		resp,
721		client.ByInspecting(),
722		azure.WithErrorUnlessStatusCode(http.StatusOK),
723		autorest.ByUnmarshallingJSON(&result),
724		autorest.ByClosing())
725	result.Response = autorest.Response{Response: resp}
726	return
727}
728
729// SynchronizeAutoStorageKeys synchronizes access keys for the auto-storage account configured for the specified Batch
730// account.
731// Parameters:
732// resourceGroupName - the name of the resource group that contains the Batch account.
733// accountName - the name of the Batch account.
734func (client AccountClient) SynchronizeAutoStorageKeys(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) {
735	if tracing.IsEnabled() {
736		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.SynchronizeAutoStorageKeys")
737		defer func() {
738			sc := -1
739			if result.Response != nil {
740				sc = result.Response.StatusCode
741			}
742			tracing.EndSpan(ctx, sc, err)
743		}()
744	}
745	if err := validation.Validate([]validation.Validation{
746		{TargetValue: resourceGroupName,
747			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
748		{TargetValue: accountName,
749			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
750				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
751				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
752		return result, validation.NewError("batch.AccountClient", "SynchronizeAutoStorageKeys", err.Error())
753	}
754
755	req, err := client.SynchronizeAutoStorageKeysPreparer(ctx, resourceGroupName, accountName)
756	if err != nil {
757		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", nil, "Failure preparing request")
758		return
759	}
760
761	resp, err := client.SynchronizeAutoStorageKeysSender(req)
762	if err != nil {
763		result.Response = resp
764		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", resp, "Failure sending request")
765		return
766	}
767
768	result, err = client.SynchronizeAutoStorageKeysResponder(resp)
769	if err != nil {
770		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", resp, "Failure responding to request")
771	}
772
773	return
774}
775
776// SynchronizeAutoStorageKeysPreparer prepares the SynchronizeAutoStorageKeys request.
777func (client AccountClient) SynchronizeAutoStorageKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
778	pathParameters := map[string]interface{}{
779		"accountName":       autorest.Encode("path", accountName),
780		"resourceGroupName": autorest.Encode("path", resourceGroupName),
781		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
782	}
783
784	const APIVersion = "2017-05-01"
785	queryParameters := map[string]interface{}{
786		"api-version": APIVersion,
787	}
788
789	preparer := autorest.CreatePreparer(
790		autorest.AsPost(),
791		autorest.WithBaseURL(client.BaseURI),
792		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/syncAutoStorageKeys", pathParameters),
793		autorest.WithQueryParameters(queryParameters))
794	return preparer.Prepare((&http.Request{}).WithContext(ctx))
795}
796
797// SynchronizeAutoStorageKeysSender sends the SynchronizeAutoStorageKeys request. The method will close the
798// http.Response Body if it receives an error.
799func (client AccountClient) SynchronizeAutoStorageKeysSender(req *http.Request) (*http.Response, error) {
800	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
801	return autorest.SendWithSender(client, req, sd...)
802}
803
804// SynchronizeAutoStorageKeysResponder handles the response to the SynchronizeAutoStorageKeys request. The method always
805// closes the http.Response Body.
806func (client AccountClient) SynchronizeAutoStorageKeysResponder(resp *http.Response) (result autorest.Response, err error) {
807	err = autorest.Respond(
808		resp,
809		client.ByInspecting(),
810		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
811		autorest.ByClosing())
812	result.Response = resp
813	return
814}
815
816// Update updates the properties of an existing Batch account.
817// Parameters:
818// resourceGroupName - the name of the resource group that contains the Batch account.
819// accountName - the name of the Batch account.
820// parameters - additional parameters for account update.
821func (client AccountClient) Update(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (result Account, err error) {
822	if tracing.IsEnabled() {
823		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Update")
824		defer func() {
825			sc := -1
826			if result.Response.Response != nil {
827				sc = result.Response.Response.StatusCode
828			}
829			tracing.EndSpan(ctx, sc, err)
830		}()
831	}
832	if err := validation.Validate([]validation.Validation{
833		{TargetValue: resourceGroupName,
834			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
835		{TargetValue: accountName,
836			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
837				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
838				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
839		return result, validation.NewError("batch.AccountClient", "Update", err.Error())
840	}
841
842	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, parameters)
843	if err != nil {
844		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", nil, "Failure preparing request")
845		return
846	}
847
848	resp, err := client.UpdateSender(req)
849	if err != nil {
850		result.Response = autorest.Response{Response: resp}
851		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", resp, "Failure sending request")
852		return
853	}
854
855	result, err = client.UpdateResponder(resp)
856	if err != nil {
857		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", resp, "Failure responding to request")
858	}
859
860	return
861}
862
863// UpdatePreparer prepares the Update request.
864func (client AccountClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (*http.Request, error) {
865	pathParameters := map[string]interface{}{
866		"accountName":       autorest.Encode("path", accountName),
867		"resourceGroupName": autorest.Encode("path", resourceGroupName),
868		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
869	}
870
871	const APIVersion = "2017-05-01"
872	queryParameters := map[string]interface{}{
873		"api-version": APIVersion,
874	}
875
876	preparer := autorest.CreatePreparer(
877		autorest.AsContentType("application/json; charset=utf-8"),
878		autorest.AsPatch(),
879		autorest.WithBaseURL(client.BaseURI),
880		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
881		autorest.WithJSON(parameters),
882		autorest.WithQueryParameters(queryParameters))
883	return preparer.Prepare((&http.Request{}).WithContext(ctx))
884}
885
886// UpdateSender sends the Update request. The method will close the
887// http.Response Body if it receives an error.
888func (client AccountClient) UpdateSender(req *http.Request) (*http.Response, error) {
889	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
890	return autorest.SendWithSender(client, req, sd...)
891}
892
893// UpdateResponder handles the response to the Update request. The method always
894// closes the http.Response Body.
895func (client AccountClient) UpdateResponder(resp *http.Response) (result Account, err error) {
896	err = autorest.Respond(
897		resp,
898		client.ByInspecting(),
899		azure.WithErrorUnlessStatusCode(http.StatusOK),
900		autorest.ByUnmarshallingJSON(&result),
901		autorest.ByClosing())
902	result.Response = autorest.Response{Response: resp}
903	return
904}
905