1package storage 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// FileServicesClient is the the Azure Storage Management API. 19type FileServicesClient struct { 20 BaseClient 21} 22 23// NewFileServicesClient creates an instance of the FileServicesClient client. 24func NewFileServicesClient(subscriptionID string) FileServicesClient { 25 return NewFileServicesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewFileServicesClientWithBaseURI creates an instance of the FileServicesClient client using a custom endpoint. Use 29// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewFileServicesClientWithBaseURI(baseURI string, subscriptionID string) FileServicesClient { 31 return FileServicesClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// GetServiceProperties gets the properties of file services in storage accounts, including CORS (Cross-Origin Resource 35// Sharing) rules. 36// Parameters: 37// resourceGroupName - the name of the resource group within the user's subscription. The name is case 38// insensitive. 39// accountName - the name of the storage account within the specified resource group. Storage account names 40// must be between 3 and 24 characters in length and use numbers and lower-case letters only. 41func (client FileServicesClient) GetServiceProperties(ctx context.Context, resourceGroupName string, accountName string) (result FileServiceProperties, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/FileServicesClient.GetServiceProperties") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: resourceGroupName, 54 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 55 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 56 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 57 {TargetValue: accountName, 58 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 59 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 60 {TargetValue: client.SubscriptionID, 61 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 62 return result, validation.NewError("storage.FileServicesClient", "GetServiceProperties", err.Error()) 63 } 64 65 req, err := client.GetServicePropertiesPreparer(ctx, resourceGroupName, accountName) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "GetServiceProperties", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.GetServicePropertiesSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "GetServiceProperties", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.GetServicePropertiesResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "GetServiceProperties", resp, "Failure responding to request") 81 return 82 } 83 84 return 85} 86 87// GetServicePropertiesPreparer prepares the GetServiceProperties request. 88func (client FileServicesClient) GetServicePropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "accountName": autorest.Encode("path", accountName), 91 "FileServicesName": autorest.Encode("path", "default"), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2021-02-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsGet(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices/{FileServicesName}", pathParameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// GetServicePropertiesSender sends the GetServiceProperties request. The method will close the 110// http.Response Body if it receives an error. 111func (client FileServicesClient) GetServicePropertiesSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113} 114 115// GetServicePropertiesResponder handles the response to the GetServiceProperties request. The method always 116// closes the http.Response Body. 117func (client FileServicesClient) GetServicePropertiesResponder(resp *http.Response) (result FileServiceProperties, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// List list all file services in storage accounts 128// Parameters: 129// resourceGroupName - the name of the resource group within the user's subscription. The name is case 130// insensitive. 131// accountName - the name of the storage account within the specified resource group. Storage account names 132// must be between 3 and 24 characters in length and use numbers and lower-case letters only. 133func (client FileServicesClient) List(ctx context.Context, resourceGroupName string, accountName string) (result FileServiceItems, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/FileServicesClient.List") 136 defer func() { 137 sc := -1 138 if result.Response.Response != nil { 139 sc = result.Response.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 if err := validation.Validate([]validation.Validation{ 145 {TargetValue: resourceGroupName, 146 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 147 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 148 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 149 {TargetValue: accountName, 150 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 151 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 152 {TargetValue: client.SubscriptionID, 153 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 154 return result, validation.NewError("storage.FileServicesClient", "List", err.Error()) 155 } 156 157 req, err := client.ListPreparer(ctx, resourceGroupName, accountName) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "List", nil, "Failure preparing request") 160 return 161 } 162 163 resp, err := client.ListSender(req) 164 if err != nil { 165 result.Response = autorest.Response{Response: resp} 166 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "List", resp, "Failure sending request") 167 return 168 } 169 170 result, err = client.ListResponder(resp) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "List", resp, "Failure responding to request") 173 return 174 } 175 176 return 177} 178 179// ListPreparer prepares the List request. 180func (client FileServicesClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 181 pathParameters := map[string]interface{}{ 182 "accountName": autorest.Encode("path", accountName), 183 "resourceGroupName": autorest.Encode("path", resourceGroupName), 184 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 185 } 186 187 const APIVersion = "2021-02-01" 188 queryParameters := map[string]interface{}{ 189 "api-version": APIVersion, 190 } 191 192 preparer := autorest.CreatePreparer( 193 autorest.AsGet(), 194 autorest.WithBaseURL(client.BaseURI), 195 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices", pathParameters), 196 autorest.WithQueryParameters(queryParameters)) 197 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 198} 199 200// ListSender sends the List request. The method will close the 201// http.Response Body if it receives an error. 202func (client FileServicesClient) ListSender(req *http.Request) (*http.Response, error) { 203 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 204} 205 206// ListResponder handles the response to the List request. The method always 207// closes the http.Response Body. 208func (client FileServicesClient) ListResponder(resp *http.Response) (result FileServiceItems, err error) { 209 err = autorest.Respond( 210 resp, 211 azure.WithErrorUnlessStatusCode(http.StatusOK), 212 autorest.ByUnmarshallingJSON(&result), 213 autorest.ByClosing()) 214 result.Response = autorest.Response{Response: resp} 215 return 216} 217 218// SetServiceProperties sets the properties of file services in storage accounts, including CORS (Cross-Origin Resource 219// Sharing) rules. 220// Parameters: 221// resourceGroupName - the name of the resource group within the user's subscription. The name is case 222// insensitive. 223// accountName - the name of the storage account within the specified resource group. Storage account names 224// must be between 3 and 24 characters in length and use numbers and lower-case letters only. 225// parameters - the properties of file services in storage accounts, including CORS (Cross-Origin Resource 226// Sharing) rules. 227func (client FileServicesClient) SetServiceProperties(ctx context.Context, resourceGroupName string, accountName string, parameters FileServiceProperties) (result FileServiceProperties, err error) { 228 if tracing.IsEnabled() { 229 ctx = tracing.StartSpan(ctx, fqdn+"/FileServicesClient.SetServiceProperties") 230 defer func() { 231 sc := -1 232 if result.Response.Response != nil { 233 sc = result.Response.Response.StatusCode 234 } 235 tracing.EndSpan(ctx, sc, err) 236 }() 237 } 238 if err := validation.Validate([]validation.Validation{ 239 {TargetValue: resourceGroupName, 240 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 241 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 242 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 243 {TargetValue: accountName, 244 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 245 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 246 {TargetValue: client.SubscriptionID, 247 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 248 {TargetValue: parameters, 249 Constraints: []validation.Constraint{{Target: "parameters.FileServicePropertiesProperties", Name: validation.Null, Rule: false, 250 Chain: []validation.Constraint{{Target: "parameters.FileServicePropertiesProperties.ShareDeleteRetentionPolicy", Name: validation.Null, Rule: false, 251 Chain: []validation.Constraint{{Target: "parameters.FileServicePropertiesProperties.ShareDeleteRetentionPolicy.Days", Name: validation.Null, Rule: false, 252 Chain: []validation.Constraint{{Target: "parameters.FileServicePropertiesProperties.ShareDeleteRetentionPolicy.Days", Name: validation.InclusiveMaximum, Rule: int64(365), Chain: nil}, 253 {Target: "parameters.FileServicePropertiesProperties.ShareDeleteRetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, 254 }}, 255 }}, 256 }}}}}); err != nil { 257 return result, validation.NewError("storage.FileServicesClient", "SetServiceProperties", err.Error()) 258 } 259 260 req, err := client.SetServicePropertiesPreparer(ctx, resourceGroupName, accountName, parameters) 261 if err != nil { 262 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "SetServiceProperties", nil, "Failure preparing request") 263 return 264 } 265 266 resp, err := client.SetServicePropertiesSender(req) 267 if err != nil { 268 result.Response = autorest.Response{Response: resp} 269 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "SetServiceProperties", resp, "Failure sending request") 270 return 271 } 272 273 result, err = client.SetServicePropertiesResponder(resp) 274 if err != nil { 275 err = autorest.NewErrorWithError(err, "storage.FileServicesClient", "SetServiceProperties", resp, "Failure responding to request") 276 return 277 } 278 279 return 280} 281 282// SetServicePropertiesPreparer prepares the SetServiceProperties request. 283func (client FileServicesClient) SetServicePropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string, parameters FileServiceProperties) (*http.Request, error) { 284 pathParameters := map[string]interface{}{ 285 "accountName": autorest.Encode("path", accountName), 286 "FileServicesName": autorest.Encode("path", "default"), 287 "resourceGroupName": autorest.Encode("path", resourceGroupName), 288 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 289 } 290 291 const APIVersion = "2021-02-01" 292 queryParameters := map[string]interface{}{ 293 "api-version": APIVersion, 294 } 295 296 parameters.Sku = nil 297 preparer := autorest.CreatePreparer( 298 autorest.AsContentType("application/json; charset=utf-8"), 299 autorest.AsPut(), 300 autorest.WithBaseURL(client.BaseURI), 301 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices/{FileServicesName}", pathParameters), 302 autorest.WithJSON(parameters), 303 autorest.WithQueryParameters(queryParameters)) 304 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 305} 306 307// SetServicePropertiesSender sends the SetServiceProperties request. The method will close the 308// http.Response Body if it receives an error. 309func (client FileServicesClient) SetServicePropertiesSender(req *http.Request) (*http.Response, error) { 310 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 311} 312 313// SetServicePropertiesResponder handles the response to the SetServiceProperties request. The method always 314// closes the http.Response Body. 315func (client FileServicesClient) SetServicePropertiesResponder(resp *http.Response) (result FileServiceProperties, err error) { 316 err = autorest.Respond( 317 resp, 318 azure.WithErrorUnlessStatusCode(http.StatusOK), 319 autorest.ByUnmarshallingJSON(&result), 320 autorest.ByClosing()) 321 result.Response = autorest.Response{Response: resp} 322 return 323} 324