1package storsimple
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// StorageAccountCredentialsClient is the client for the StorageAccountCredentials methods of the Storsimple service.
19type StorageAccountCredentialsClient struct {
20	BaseClient
21}
22
23// NewStorageAccountCredentialsClient creates an instance of the StorageAccountCredentialsClient client.
24func NewStorageAccountCredentialsClient(subscriptionID string) StorageAccountCredentialsClient {
25	return NewStorageAccountCredentialsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewStorageAccountCredentialsClientWithBaseURI creates an instance of the StorageAccountCredentialsClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewStorageAccountCredentialsClientWithBaseURI(baseURI string, subscriptionID string) StorageAccountCredentialsClient {
32	return StorageAccountCredentialsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate creates or updates the storage account credential.
36// Parameters:
37// storageAccountCredentialName - the storage account credential name.
38// parameters - the storage account credential to be added or updated.
39// resourceGroupName - the resource group name
40// managerName - the manager name
41func (client StorageAccountCredentialsClient) CreateOrUpdate(ctx context.Context, storageAccountCredentialName string, parameters StorageAccountCredential, resourceGroupName string, managerName string) (result StorageAccountCredentialsCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: parameters,
54			Constraints: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties", Name: validation.Null, Rule: true,
55				Chain: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties.EndPoint", Name: validation.Null, Rule: true, Chain: nil},
56					{Target: "parameters.StorageAccountCredentialProperties.AccessKey", Name: validation.Null, Rule: false,
57						Chain: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties.AccessKey.Value", Name: validation.Null, Rule: true, Chain: nil}}},
58				}}}},
59		{TargetValue: managerName,
60			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
61				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
62		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", err.Error())
63	}
64
65	req, err := client.CreateOrUpdatePreparer(ctx, storageAccountCredentialName, parameters, resourceGroupName, managerName)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", nil, "Failure preparing request")
68		return
69	}
70
71	result, err = client.CreateOrUpdateSender(req)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", nil, "Failure sending request")
74		return
75	}
76
77	return
78}
79
80// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
81func (client StorageAccountCredentialsClient) CreateOrUpdatePreparer(ctx context.Context, storageAccountCredentialName string, parameters StorageAccountCredential, resourceGroupName string, managerName string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"managerName":                  managerName,
84		"resourceGroupName":            resourceGroupName,
85		"storageAccountCredentialName": storageAccountCredentialName,
86		"subscriptionId":               client.SubscriptionID,
87	}
88
89	const APIVersion = "2017-06-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsContentType("application/json; charset=utf-8"),
96		autorest.AsPut(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
99		autorest.WithJSON(parameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
105// http.Response Body if it receives an error.
106func (client StorageAccountCredentialsClient) CreateOrUpdateSender(req *http.Request) (future StorageAccountCredentialsCreateOrUpdateFuture, err error) {
107	var resp *http.Response
108	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
109	if err != nil {
110		return
111	}
112	var azf azure.Future
113	azf, err = azure.NewFutureFromResponse(resp)
114	future.FutureAPI = &azf
115	future.Result = future.result
116	return
117}
118
119// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
120// closes the http.Response Body.
121func (client StorageAccountCredentialsClient) CreateOrUpdateResponder(resp *http.Response) (result StorageAccountCredential, err error) {
122	err = autorest.Respond(
123		resp,
124		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
125		autorest.ByUnmarshallingJSON(&result),
126		autorest.ByClosing())
127	result.Response = autorest.Response{Response: resp}
128	return
129}
130
131// Delete deletes the storage account credential.
132// Parameters:
133// storageAccountCredentialName - the name of the storage account credential.
134// resourceGroupName - the resource group name
135// managerName - the manager name
136func (client StorageAccountCredentialsClient) Delete(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (result StorageAccountCredentialsDeleteFuture, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.Delete")
139		defer func() {
140			sc := -1
141			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
142				sc = result.FutureAPI.Response().StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	if err := validation.Validate([]validation.Validation{
148		{TargetValue: managerName,
149			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
150				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
151		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "Delete", err.Error())
152	}
153
154	req, err := client.DeletePreparer(ctx, storageAccountCredentialName, resourceGroupName, managerName)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Delete", nil, "Failure preparing request")
157		return
158	}
159
160	result, err = client.DeleteSender(req)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Delete", nil, "Failure sending request")
163		return
164	}
165
166	return
167}
168
169// DeletePreparer prepares the Delete request.
170func (client StorageAccountCredentialsClient) DeletePreparer(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (*http.Request, error) {
171	pathParameters := map[string]interface{}{
172		"managerName":                  managerName,
173		"resourceGroupName":            resourceGroupName,
174		"storageAccountCredentialName": storageAccountCredentialName,
175		"subscriptionId":               client.SubscriptionID,
176	}
177
178	const APIVersion = "2017-06-01"
179	queryParameters := map[string]interface{}{
180		"api-version": APIVersion,
181	}
182
183	preparer := autorest.CreatePreparer(
184		autorest.AsDelete(),
185		autorest.WithBaseURL(client.BaseURI),
186		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
187		autorest.WithQueryParameters(queryParameters))
188	return preparer.Prepare((&http.Request{}).WithContext(ctx))
189}
190
191// DeleteSender sends the Delete request. The method will close the
192// http.Response Body if it receives an error.
193func (client StorageAccountCredentialsClient) DeleteSender(req *http.Request) (future StorageAccountCredentialsDeleteFuture, err error) {
194	var resp *http.Response
195	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
196	if err != nil {
197		return
198	}
199	var azf azure.Future
200	azf, err = azure.NewFutureFromResponse(resp)
201	future.FutureAPI = &azf
202	future.Result = future.result
203	return
204}
205
206// DeleteResponder handles the response to the Delete request. The method always
207// closes the http.Response Body.
208func (client StorageAccountCredentialsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
209	err = autorest.Respond(
210		resp,
211		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
212		autorest.ByClosing())
213	result.Response = resp
214	return
215}
216
217// Get gets the properties of the specified storage account credential name.
218// Parameters:
219// storageAccountCredentialName - the name of storage account credential to be fetched.
220// resourceGroupName - the resource group name
221// managerName - the manager name
222func (client StorageAccountCredentialsClient) Get(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (result StorageAccountCredential, err error) {
223	if tracing.IsEnabled() {
224		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.Get")
225		defer func() {
226			sc := -1
227			if result.Response.Response != nil {
228				sc = result.Response.Response.StatusCode
229			}
230			tracing.EndSpan(ctx, sc, err)
231		}()
232	}
233	if err := validation.Validate([]validation.Validation{
234		{TargetValue: managerName,
235			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
236				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
237		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "Get", err.Error())
238	}
239
240	req, err := client.GetPreparer(ctx, storageAccountCredentialName, resourceGroupName, managerName)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", nil, "Failure preparing request")
243		return
244	}
245
246	resp, err := client.GetSender(req)
247	if err != nil {
248		result.Response = autorest.Response{Response: resp}
249		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", resp, "Failure sending request")
250		return
251	}
252
253	result, err = client.GetResponder(resp)
254	if err != nil {
255		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", resp, "Failure responding to request")
256		return
257	}
258
259	return
260}
261
262// GetPreparer prepares the Get request.
263func (client StorageAccountCredentialsClient) GetPreparer(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (*http.Request, error) {
264	pathParameters := map[string]interface{}{
265		"managerName":                  managerName,
266		"resourceGroupName":            resourceGroupName,
267		"storageAccountCredentialName": storageAccountCredentialName,
268		"subscriptionId":               client.SubscriptionID,
269	}
270
271	const APIVersion = "2017-06-01"
272	queryParameters := map[string]interface{}{
273		"api-version": APIVersion,
274	}
275
276	preparer := autorest.CreatePreparer(
277		autorest.AsGet(),
278		autorest.WithBaseURL(client.BaseURI),
279		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
280		autorest.WithQueryParameters(queryParameters))
281	return preparer.Prepare((&http.Request{}).WithContext(ctx))
282}
283
284// GetSender sends the Get request. The method will close the
285// http.Response Body if it receives an error.
286func (client StorageAccountCredentialsClient) GetSender(req *http.Request) (*http.Response, error) {
287	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
288}
289
290// GetResponder handles the response to the Get request. The method always
291// closes the http.Response Body.
292func (client StorageAccountCredentialsClient) GetResponder(resp *http.Response) (result StorageAccountCredential, err error) {
293	err = autorest.Respond(
294		resp,
295		azure.WithErrorUnlessStatusCode(http.StatusOK),
296		autorest.ByUnmarshallingJSON(&result),
297		autorest.ByClosing())
298	result.Response = autorest.Response{Response: resp}
299	return
300}
301
302// ListByManager gets all the storage account credentials in a manager.
303// Parameters:
304// resourceGroupName - the resource group name
305// managerName - the manager name
306func (client StorageAccountCredentialsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string) (result StorageAccountCredentialList, err error) {
307	if tracing.IsEnabled() {
308		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.ListByManager")
309		defer func() {
310			sc := -1
311			if result.Response.Response != nil {
312				sc = result.Response.Response.StatusCode
313			}
314			tracing.EndSpan(ctx, sc, err)
315		}()
316	}
317	if err := validation.Validate([]validation.Validation{
318		{TargetValue: managerName,
319			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
320				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
321		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "ListByManager", err.Error())
322	}
323
324	req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", nil, "Failure preparing request")
327		return
328	}
329
330	resp, err := client.ListByManagerSender(req)
331	if err != nil {
332		result.Response = autorest.Response{Response: resp}
333		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", resp, "Failure sending request")
334		return
335	}
336
337	result, err = client.ListByManagerResponder(resp)
338	if err != nil {
339		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", resp, "Failure responding to request")
340		return
341	}
342
343	return
344}
345
346// ListByManagerPreparer prepares the ListByManager request.
347func (client StorageAccountCredentialsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string) (*http.Request, error) {
348	pathParameters := map[string]interface{}{
349		"managerName":       managerName,
350		"resourceGroupName": resourceGroupName,
351		"subscriptionId":    client.SubscriptionID,
352	}
353
354	const APIVersion = "2017-06-01"
355	queryParameters := map[string]interface{}{
356		"api-version": APIVersion,
357	}
358
359	preparer := autorest.CreatePreparer(
360		autorest.AsGet(),
361		autorest.WithBaseURL(client.BaseURI),
362		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials", pathParameters),
363		autorest.WithQueryParameters(queryParameters))
364	return preparer.Prepare((&http.Request{}).WithContext(ctx))
365}
366
367// ListByManagerSender sends the ListByManager request. The method will close the
368// http.Response Body if it receives an error.
369func (client StorageAccountCredentialsClient) ListByManagerSender(req *http.Request) (*http.Response, error) {
370	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
371}
372
373// ListByManagerResponder handles the response to the ListByManager request. The method always
374// closes the http.Response Body.
375func (client StorageAccountCredentialsClient) ListByManagerResponder(resp *http.Response) (result StorageAccountCredentialList, err error) {
376	err = autorest.Respond(
377		resp,
378		azure.WithErrorUnlessStatusCode(http.StatusOK),
379		autorest.ByUnmarshallingJSON(&result),
380		autorest.ByClosing())
381	result.Response = autorest.Response{Response: resp}
382	return
383}
384