1package cognitiveservices
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// AccountsClient is the cognitive Services Management Client
19type AccountsClient struct {
20	BaseClient
21}
22
23// NewAccountsClient creates an instance of the AccountsClient client.
24func NewAccountsClient(subscriptionID string) AccountsClient {
25	return NewAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAccountsClientWithBaseURI creates an instance of the AccountsClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAccountsClientWithBaseURI(baseURI string, subscriptionID string) AccountsClient {
31	return AccountsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Create create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for
35// developer to access intelligent APIs. It's also the resource type for billing.
36// Parameters:
37// resourceGroupName - the name of the resource group within the user's subscription.
38// accountName - the name of the cognitive services account within the specified resource group. Cognitive
39// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
40// only.
41// parameters - the parameters to provide for the created account.
42func (client AccountsClient) Create(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (result Account, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Create")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: accountName,
55			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
56				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
57				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}},
58		{TargetValue: parameters,
59			Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: true, Chain: nil},
60				{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil},
61				{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
62		return result, validation.NewError("cognitiveservices.AccountsClient", "Create", err.Error())
63	}
64
65	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, parameters)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", nil, "Failure preparing request")
68		return
69	}
70
71	resp, err := client.CreateSender(req)
72	if err != nil {
73		result.Response = autorest.Response{Response: resp}
74		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure sending request")
75		return
76	}
77
78	result, err = client.CreateResponder(resp)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure responding to request")
81		return
82	}
83
84	return
85}
86
87// CreatePreparer prepares the Create request.
88func (client AccountsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (*http.Request, error) {
89	pathParameters := map[string]interface{}{
90		"accountName":       autorest.Encode("path", accountName),
91		"resourceGroupName": autorest.Encode("path", resourceGroupName),
92		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2016-02-01-preview"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsContentType("application/json; charset=utf-8"),
102		autorest.AsPut(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters),
105		autorest.WithJSON(parameters),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// CreateSender sends the Create request. The method will close the
111// http.Response Body if it receives an error.
112func (client AccountsClient) CreateSender(req *http.Request) (*http.Response, error) {
113	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
114}
115
116// CreateResponder handles the response to the Create request. The method always
117// closes the http.Response Body.
118func (client AccountsClient) CreateResponder(resp *http.Response) (result Account, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes a Cognitive Services account from the resource group.
129// Parameters:
130// resourceGroupName - the name of the resource group within the user's subscription.
131// accountName - the name of the cognitive services account within the specified resource group. Cognitive
132// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
133// only.
134func (client AccountsClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Delete")
137		defer func() {
138			sc := -1
139			if result.Response != nil {
140				sc = result.Response.StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	if err := validation.Validate([]validation.Validation{
146		{TargetValue: accountName,
147			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
148				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
149				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
150		return result, validation.NewError("cognitiveservices.AccountsClient", "Delete", err.Error())
151	}
152
153	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.DeleteSender(req)
160	if err != nil {
161		result.Response = resp
162		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure sending request")
163		return
164	}
165
166	result, err = client.DeleteResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure responding to request")
169		return
170	}
171
172	return
173}
174
175// DeletePreparer prepares the Delete request.
176func (client AccountsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"accountName":       autorest.Encode("path", accountName),
179		"resourceGroupName": autorest.Encode("path", resourceGroupName),
180		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
181	}
182
183	const APIVersion = "2016-02-01-preview"
184	queryParameters := map[string]interface{}{
185		"api-version": APIVersion,
186	}
187
188	preparer := autorest.CreatePreparer(
189		autorest.AsDelete(),
190		autorest.WithBaseURL(client.BaseURI),
191		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters),
192		autorest.WithQueryParameters(queryParameters))
193	return preparer.Prepare((&http.Request{}).WithContext(ctx))
194}
195
196// DeleteSender sends the Delete request. The method will close the
197// http.Response Body if it receives an error.
198func (client AccountsClient) DeleteSender(req *http.Request) (*http.Response, error) {
199	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
200}
201
202// DeleteResponder handles the response to the Delete request. The method always
203// closes the http.Response Body.
204func (client AccountsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
205	err = autorest.Respond(
206		resp,
207		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
208		autorest.ByClosing())
209	result.Response = resp
210	return
211}
212
213// GetProperties returns a Cognitive Services account specified by the parameters.
214// Parameters:
215// resourceGroupName - the name of the resource group within the user's subscription.
216// accountName - the name of the cognitive services account within the specified resource group. Cognitive
217// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
218// only.
219func (client AccountsClient) GetProperties(ctx context.Context, resourceGroupName string, accountName string) (result Account, err error) {
220	if tracing.IsEnabled() {
221		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.GetProperties")
222		defer func() {
223			sc := -1
224			if result.Response.Response != nil {
225				sc = result.Response.Response.StatusCode
226			}
227			tracing.EndSpan(ctx, sc, err)
228		}()
229	}
230	if err := validation.Validate([]validation.Validation{
231		{TargetValue: accountName,
232			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
233				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
234				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
235		return result, validation.NewError("cognitiveservices.AccountsClient", "GetProperties", err.Error())
236	}
237
238	req, err := client.GetPropertiesPreparer(ctx, resourceGroupName, accountName)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", nil, "Failure preparing request")
241		return
242	}
243
244	resp, err := client.GetPropertiesSender(req)
245	if err != nil {
246		result.Response = autorest.Response{Response: resp}
247		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure sending request")
248		return
249	}
250
251	result, err = client.GetPropertiesResponder(resp)
252	if err != nil {
253		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure responding to request")
254		return
255	}
256
257	return
258}
259
260// GetPropertiesPreparer prepares the GetProperties request.
261func (client AccountsClient) GetPropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
262	pathParameters := map[string]interface{}{
263		"accountName":       autorest.Encode("path", accountName),
264		"resourceGroupName": autorest.Encode("path", resourceGroupName),
265		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
266	}
267
268	const APIVersion = "2016-02-01-preview"
269	queryParameters := map[string]interface{}{
270		"api-version": APIVersion,
271	}
272
273	preparer := autorest.CreatePreparer(
274		autorest.AsGet(),
275		autorest.WithBaseURL(client.BaseURI),
276		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters),
277		autorest.WithQueryParameters(queryParameters))
278	return preparer.Prepare((&http.Request{}).WithContext(ctx))
279}
280
281// GetPropertiesSender sends the GetProperties request. The method will close the
282// http.Response Body if it receives an error.
283func (client AccountsClient) GetPropertiesSender(req *http.Request) (*http.Response, error) {
284	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
285}
286
287// GetPropertiesResponder handles the response to the GetProperties request. The method always
288// closes the http.Response Body.
289func (client AccountsClient) GetPropertiesResponder(resp *http.Response) (result Account, err error) {
290	err = autorest.Respond(
291		resp,
292		azure.WithErrorUnlessStatusCode(http.StatusOK),
293		autorest.ByUnmarshallingJSON(&result),
294		autorest.ByClosing())
295	result.Response = autorest.Response{Response: resp}
296	return
297}
298
299// List returns all the resources of a particular type belonging to a subscription.
300func (client AccountsClient) List(ctx context.Context) (result AccountListResult, err error) {
301	if tracing.IsEnabled() {
302		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.List")
303		defer func() {
304			sc := -1
305			if result.Response.Response != nil {
306				sc = result.Response.Response.StatusCode
307			}
308			tracing.EndSpan(ctx, sc, err)
309		}()
310	}
311	req, err := client.ListPreparer(ctx)
312	if err != nil {
313		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", nil, "Failure preparing request")
314		return
315	}
316
317	resp, err := client.ListSender(req)
318	if err != nil {
319		result.Response = autorest.Response{Response: resp}
320		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure sending request")
321		return
322	}
323
324	result, err = client.ListResponder(resp)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure responding to request")
327		return
328	}
329
330	return
331}
332
333// ListPreparer prepares the List request.
334func (client AccountsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
335	pathParameters := map[string]interface{}{
336		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
337	}
338
339	const APIVersion = "2016-02-01-preview"
340	queryParameters := map[string]interface{}{
341		"api-version": APIVersion,
342	}
343
344	preparer := autorest.CreatePreparer(
345		autorest.AsGet(),
346		autorest.WithBaseURL(client.BaseURI),
347		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/accounts", pathParameters),
348		autorest.WithQueryParameters(queryParameters))
349	return preparer.Prepare((&http.Request{}).WithContext(ctx))
350}
351
352// ListSender sends the List request. The method will close the
353// http.Response Body if it receives an error.
354func (client AccountsClient) ListSender(req *http.Request) (*http.Response, error) {
355	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
356}
357
358// ListResponder handles the response to the List request. The method always
359// closes the http.Response Body.
360func (client AccountsClient) ListResponder(resp *http.Response) (result AccountListResult, err error) {
361	err = autorest.Respond(
362		resp,
363		azure.WithErrorUnlessStatusCode(http.StatusOK),
364		autorest.ByUnmarshallingJSON(&result),
365		autorest.ByClosing())
366	result.Response = autorest.Response{Response: resp}
367	return
368}
369
370// ListByResourceGroup returns all the resources of a particular type belonging to a resource group
371// Parameters:
372// resourceGroupName - the name of the resource group within the user's subscription.
373func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResult, err error) {
374	if tracing.IsEnabled() {
375		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListByResourceGroup")
376		defer func() {
377			sc := -1
378			if result.Response.Response != nil {
379				sc = result.Response.Response.StatusCode
380			}
381			tracing.EndSpan(ctx, sc, err)
382		}()
383	}
384	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
385	if err != nil {
386		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", nil, "Failure preparing request")
387		return
388	}
389
390	resp, err := client.ListByResourceGroupSender(req)
391	if err != nil {
392		result.Response = autorest.Response{Response: resp}
393		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure sending request")
394		return
395	}
396
397	result, err = client.ListByResourceGroupResponder(resp)
398	if err != nil {
399		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure responding to request")
400		return
401	}
402
403	return
404}
405
406// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
407func (client AccountsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
408	pathParameters := map[string]interface{}{
409		"resourceGroupName": autorest.Encode("path", resourceGroupName),
410		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
411	}
412
413	const APIVersion = "2016-02-01-preview"
414	queryParameters := map[string]interface{}{
415		"api-version": APIVersion,
416	}
417
418	preparer := autorest.CreatePreparer(
419		autorest.AsGet(),
420		autorest.WithBaseURL(client.BaseURI),
421		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts", pathParameters),
422		autorest.WithQueryParameters(queryParameters))
423	return preparer.Prepare((&http.Request{}).WithContext(ctx))
424}
425
426// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
427// http.Response Body if it receives an error.
428func (client AccountsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
429	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
430}
431
432// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
433// closes the http.Response Body.
434func (client AccountsClient) ListByResourceGroupResponder(resp *http.Response) (result AccountListResult, err error) {
435	err = autorest.Respond(
436		resp,
437		azure.WithErrorUnlessStatusCode(http.StatusOK),
438		autorest.ByUnmarshallingJSON(&result),
439		autorest.ByClosing())
440	result.Response = autorest.Response{Response: resp}
441	return
442}
443
444// ListKeys lists the account keys for the specified Cognitive Services account.
445// Parameters:
446// resourceGroupName - the name of the resource group within the user's subscription.
447// accountName - the name of the cognitive services account within the specified resource group. Cognitive
448// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
449// only.
450func (client AccountsClient) ListKeys(ctx context.Context, resourceGroupName string, accountName string) (result AccountKeys, err error) {
451	if tracing.IsEnabled() {
452		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListKeys")
453		defer func() {
454			sc := -1
455			if result.Response.Response != nil {
456				sc = result.Response.Response.StatusCode
457			}
458			tracing.EndSpan(ctx, sc, err)
459		}()
460	}
461	if err := validation.Validate([]validation.Validation{
462		{TargetValue: accountName,
463			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
464				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
465				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
466		return result, validation.NewError("cognitiveservices.AccountsClient", "ListKeys", err.Error())
467	}
468
469	req, err := client.ListKeysPreparer(ctx, resourceGroupName, accountName)
470	if err != nil {
471		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", nil, "Failure preparing request")
472		return
473	}
474
475	resp, err := client.ListKeysSender(req)
476	if err != nil {
477		result.Response = autorest.Response{Response: resp}
478		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure sending request")
479		return
480	}
481
482	result, err = client.ListKeysResponder(resp)
483	if err != nil {
484		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure responding to request")
485		return
486	}
487
488	return
489}
490
491// ListKeysPreparer prepares the ListKeys request.
492func (client AccountsClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
493	pathParameters := map[string]interface{}{
494		"accountName":       autorest.Encode("path", accountName),
495		"resourceGroupName": autorest.Encode("path", resourceGroupName),
496		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
497	}
498
499	const APIVersion = "2016-02-01-preview"
500	queryParameters := map[string]interface{}{
501		"api-version": APIVersion,
502	}
503
504	preparer := autorest.CreatePreparer(
505		autorest.AsPost(),
506		autorest.WithBaseURL(client.BaseURI),
507		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/listKeys", pathParameters),
508		autorest.WithQueryParameters(queryParameters))
509	return preparer.Prepare((&http.Request{}).WithContext(ctx))
510}
511
512// ListKeysSender sends the ListKeys request. The method will close the
513// http.Response Body if it receives an error.
514func (client AccountsClient) ListKeysSender(req *http.Request) (*http.Response, error) {
515	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
516}
517
518// ListKeysResponder handles the response to the ListKeys request. The method always
519// closes the http.Response Body.
520func (client AccountsClient) ListKeysResponder(resp *http.Response) (result AccountKeys, err error) {
521	err = autorest.Respond(
522		resp,
523		azure.WithErrorUnlessStatusCode(http.StatusOK),
524		autorest.ByUnmarshallingJSON(&result),
525		autorest.ByClosing())
526	result.Response = autorest.Response{Response: resp}
527	return
528}
529
530// ListSkus list available SKUs for the requested Cognitive Services account
531// Parameters:
532// resourceGroupName - the name of the resource group within the user's subscription.
533// accountName - the name of the cognitive services account within the specified resource group. Cognitive
534// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
535// only.
536func (client AccountsClient) ListSkus(ctx context.Context, resourceGroupName string, accountName string) (result AccountEnumerateSkusResult, err error) {
537	if tracing.IsEnabled() {
538		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListSkus")
539		defer func() {
540			sc := -1
541			if result.Response.Response != nil {
542				sc = result.Response.Response.StatusCode
543			}
544			tracing.EndSpan(ctx, sc, err)
545		}()
546	}
547	if err := validation.Validate([]validation.Validation{
548		{TargetValue: accountName,
549			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
550				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
551				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
552		return result, validation.NewError("cognitiveservices.AccountsClient", "ListSkus", err.Error())
553	}
554
555	req, err := client.ListSkusPreparer(ctx, resourceGroupName, accountName)
556	if err != nil {
557		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", nil, "Failure preparing request")
558		return
559	}
560
561	resp, err := client.ListSkusSender(req)
562	if err != nil {
563		result.Response = autorest.Response{Response: resp}
564		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure sending request")
565		return
566	}
567
568	result, err = client.ListSkusResponder(resp)
569	if err != nil {
570		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure responding to request")
571		return
572	}
573
574	return
575}
576
577// ListSkusPreparer prepares the ListSkus request.
578func (client AccountsClient) ListSkusPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
579	pathParameters := map[string]interface{}{
580		"accountName":       autorest.Encode("path", accountName),
581		"resourceGroupName": autorest.Encode("path", resourceGroupName),
582		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
583	}
584
585	const APIVersion = "2016-02-01-preview"
586	queryParameters := map[string]interface{}{
587		"api-version": APIVersion,
588	}
589
590	preparer := autorest.CreatePreparer(
591		autorest.AsGet(),
592		autorest.WithBaseURL(client.BaseURI),
593		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/skus", pathParameters),
594		autorest.WithQueryParameters(queryParameters))
595	return preparer.Prepare((&http.Request{}).WithContext(ctx))
596}
597
598// ListSkusSender sends the ListSkus request. The method will close the
599// http.Response Body if it receives an error.
600func (client AccountsClient) ListSkusSender(req *http.Request) (*http.Response, error) {
601	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
602}
603
604// ListSkusResponder handles the response to the ListSkus request. The method always
605// closes the http.Response Body.
606func (client AccountsClient) ListSkusResponder(resp *http.Response) (result AccountEnumerateSkusResult, err error) {
607	err = autorest.Respond(
608		resp,
609		azure.WithErrorUnlessStatusCode(http.StatusOK),
610		autorest.ByUnmarshallingJSON(&result),
611		autorest.ByClosing())
612	result.Response = autorest.Response{Response: resp}
613	return
614}
615
616// RegenerateKey regenerates the specified account key for the specified Cognitive Services account.
617// Parameters:
618// resourceGroupName - the name of the resource group within the user's subscription.
619// accountName - the name of the cognitive services account within the specified resource group. Cognitive
620// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
621// only.
622// body - regenerate key parameters.
623func (client AccountsClient) RegenerateKey(ctx context.Context, resourceGroupName string, accountName string, body RegenerateKeyParameters) (result AccountKeys, err error) {
624	if tracing.IsEnabled() {
625		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.RegenerateKey")
626		defer func() {
627			sc := -1
628			if result.Response.Response != nil {
629				sc = result.Response.Response.StatusCode
630			}
631			tracing.EndSpan(ctx, sc, err)
632		}()
633	}
634	if err := validation.Validate([]validation.Validation{
635		{TargetValue: accountName,
636			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
637				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
638				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
639		return result, validation.NewError("cognitiveservices.AccountsClient", "RegenerateKey", err.Error())
640	}
641
642	req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, accountName, body)
643	if err != nil {
644		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", nil, "Failure preparing request")
645		return
646	}
647
648	resp, err := client.RegenerateKeySender(req)
649	if err != nil {
650		result.Response = autorest.Response{Response: resp}
651		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure sending request")
652		return
653	}
654
655	result, err = client.RegenerateKeyResponder(resp)
656	if err != nil {
657		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure responding to request")
658		return
659	}
660
661	return
662}
663
664// RegenerateKeyPreparer prepares the RegenerateKey request.
665func (client AccountsClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, accountName string, body RegenerateKeyParameters) (*http.Request, error) {
666	pathParameters := map[string]interface{}{
667		"accountName":       autorest.Encode("path", accountName),
668		"resourceGroupName": autorest.Encode("path", resourceGroupName),
669		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
670	}
671
672	const APIVersion = "2016-02-01-preview"
673	queryParameters := map[string]interface{}{
674		"api-version": APIVersion,
675	}
676
677	preparer := autorest.CreatePreparer(
678		autorest.AsContentType("application/json; charset=utf-8"),
679		autorest.AsPost(),
680		autorest.WithBaseURL(client.BaseURI),
681		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/regenerateKey", pathParameters),
682		autorest.WithJSON(body),
683		autorest.WithQueryParameters(queryParameters))
684	return preparer.Prepare((&http.Request{}).WithContext(ctx))
685}
686
687// RegenerateKeySender sends the RegenerateKey request. The method will close the
688// http.Response Body if it receives an error.
689func (client AccountsClient) RegenerateKeySender(req *http.Request) (*http.Response, error) {
690	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
691}
692
693// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always
694// closes the http.Response Body.
695func (client AccountsClient) RegenerateKeyResponder(resp *http.Response) (result AccountKeys, err error) {
696	err = autorest.Respond(
697		resp,
698		azure.WithErrorUnlessStatusCode(http.StatusOK),
699		autorest.ByUnmarshallingJSON(&result),
700		autorest.ByClosing())
701	result.Response = autorest.Response{Response: resp}
702	return
703}
704
705// Update updates a Cognitive Services account
706// Parameters:
707// resourceGroupName - the name of the resource group within the user's subscription.
708// accountName - the name of the cognitive services account within the specified resource group. Cognitive
709// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters
710// only.
711// body - the parameters to provide for the created account.
712func (client AccountsClient) Update(ctx context.Context, resourceGroupName string, accountName string, body AccountUpdateParameters) (result Account, err error) {
713	if tracing.IsEnabled() {
714		ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Update")
715		defer func() {
716			sc := -1
717			if result.Response.Response != nil {
718				sc = result.Response.Response.StatusCode
719			}
720			tracing.EndSpan(ctx, sc, err)
721		}()
722	}
723	if err := validation.Validate([]validation.Validation{
724		{TargetValue: accountName,
725			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
726				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
727				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil {
728		return result, validation.NewError("cognitiveservices.AccountsClient", "Update", err.Error())
729	}
730
731	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, body)
732	if err != nil {
733		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", nil, "Failure preparing request")
734		return
735	}
736
737	resp, err := client.UpdateSender(req)
738	if err != nil {
739		result.Response = autorest.Response{Response: resp}
740		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure sending request")
741		return
742	}
743
744	result, err = client.UpdateResponder(resp)
745	if err != nil {
746		err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure responding to request")
747		return
748	}
749
750	return
751}
752
753// UpdatePreparer prepares the Update request.
754func (client AccountsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, body AccountUpdateParameters) (*http.Request, error) {
755	pathParameters := map[string]interface{}{
756		"accountName":       autorest.Encode("path", accountName),
757		"resourceGroupName": autorest.Encode("path", resourceGroupName),
758		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
759	}
760
761	const APIVersion = "2016-02-01-preview"
762	queryParameters := map[string]interface{}{
763		"api-version": APIVersion,
764	}
765
766	preparer := autorest.CreatePreparer(
767		autorest.AsContentType("application/json; charset=utf-8"),
768		autorest.AsPatch(),
769		autorest.WithBaseURL(client.BaseURI),
770		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters),
771		autorest.WithJSON(body),
772		autorest.WithQueryParameters(queryParameters))
773	return preparer.Prepare((&http.Request{}).WithContext(ctx))
774}
775
776// UpdateSender sends the Update request. The method will close the
777// http.Response Body if it receives an error.
778func (client AccountsClient) UpdateSender(req *http.Request) (*http.Response, error) {
779	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
780}
781
782// UpdateResponder handles the response to the Update request. The method always
783// closes the http.Response Body.
784func (client AccountsClient) UpdateResponder(resp *http.Response) (result Account, err error) {
785	err = autorest.Respond(
786		resp,
787		azure.WithErrorUnlessStatusCode(http.StatusOK),
788		autorest.ByUnmarshallingJSON(&result),
789		autorest.ByClosing())
790	result.Response = autorest.Response{Response: resp}
791	return
792}
793