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