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// BlobServicesClient is the the Azure Storage Management API.
19type BlobServicesClient struct {
20	BaseClient
21}
22
23// NewBlobServicesClient creates an instance of the BlobServicesClient client.
24func NewBlobServicesClient(subscriptionID string) BlobServicesClient {
25	return NewBlobServicesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewBlobServicesClientWithBaseURI creates an instance of the BlobServicesClient 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 NewBlobServicesClientWithBaseURI(baseURI string, subscriptionID string) BlobServicesClient {
31	return BlobServicesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// GetServiceProperties gets the properties of a storage account’s Blob service, including properties for Storage
35// Analytics and CORS (Cross-Origin Resource 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 BlobServicesClient) GetServiceProperties(ctx context.Context, resourceGroupName string, accountName string) (result BlobServiceProperties, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/BlobServicesClient.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.BlobServicesClient", "GetServiceProperties", err.Error())
63	}
64
65	req, err := client.GetServicePropertiesPreparer(ctx, resourceGroupName, accountName)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "storage.BlobServicesClient", "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.BlobServicesClient", "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.BlobServicesClient", "GetServiceProperties", resp, "Failure responding to request")
81		return
82	}
83
84	return
85}
86
87// GetServicePropertiesPreparer prepares the GetServiceProperties request.
88func (client BlobServicesClient) GetServicePropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
89	pathParameters := map[string]interface{}{
90		"accountName":       autorest.Encode("path", accountName),
91		"BlobServicesName":  autorest.Encode("path", "default"),
92		"resourceGroupName": autorest.Encode("path", resourceGroupName),
93		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
94	}
95
96	const APIVersion = "2018-07-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}/blobServices/{BlobServicesName}", 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 BlobServicesClient) 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 BlobServicesClient) GetServicePropertiesResponder(resp *http.Response) (result BlobServiceProperties, 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// SetServiceProperties sets the properties of a storage account’s Blob service, including properties for Storage
128// Analytics and CORS (Cross-Origin Resource Sharing) rules.
129// Parameters:
130// resourceGroupName - the name of the resource group within the user's subscription. The name is case
131// insensitive.
132// accountName - the name of the storage account within the specified resource group. Storage account names
133// must be between 3 and 24 characters in length and use numbers and lower-case letters only.
134// parameters - the properties of a storage account’s Blob service, including properties for Storage Analytics
135// and CORS (Cross-Origin Resource Sharing) rules.
136func (client BlobServicesClient) SetServiceProperties(ctx context.Context, resourceGroupName string, accountName string, parameters BlobServiceProperties) (result BlobServiceProperties, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/BlobServicesClient.SetServiceProperties")
139		defer func() {
140			sc := -1
141			if result.Response.Response != nil {
142				sc = result.Response.Response.StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	if err := validation.Validate([]validation.Validation{
148		{TargetValue: resourceGroupName,
149			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
150				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
151				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
152		{TargetValue: accountName,
153			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
154				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
155		{TargetValue: client.SubscriptionID,
156			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
157		{TargetValue: parameters,
158			Constraints: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties", Name: validation.Null, Rule: false,
159				Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.DeleteRetentionPolicy", Name: validation.Null, Rule: false,
160					Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.DeleteRetentionPolicy.Days", Name: validation.Null, Rule: false,
161						Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.DeleteRetentionPolicy.Days", Name: validation.InclusiveMaximum, Rule: int64(365), Chain: nil},
162							{Target: "parameters.BlobServicePropertiesProperties.DeleteRetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
163						}},
164					}},
165				}}}}}); err != nil {
166		return result, validation.NewError("storage.BlobServicesClient", "SetServiceProperties", err.Error())
167	}
168
169	req, err := client.SetServicePropertiesPreparer(ctx, resourceGroupName, accountName, parameters)
170	if err != nil {
171		err = autorest.NewErrorWithError(err, "storage.BlobServicesClient", "SetServiceProperties", nil, "Failure preparing request")
172		return
173	}
174
175	resp, err := client.SetServicePropertiesSender(req)
176	if err != nil {
177		result.Response = autorest.Response{Response: resp}
178		err = autorest.NewErrorWithError(err, "storage.BlobServicesClient", "SetServiceProperties", resp, "Failure sending request")
179		return
180	}
181
182	result, err = client.SetServicePropertiesResponder(resp)
183	if err != nil {
184		err = autorest.NewErrorWithError(err, "storage.BlobServicesClient", "SetServiceProperties", resp, "Failure responding to request")
185		return
186	}
187
188	return
189}
190
191// SetServicePropertiesPreparer prepares the SetServiceProperties request.
192func (client BlobServicesClient) SetServicePropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string, parameters BlobServiceProperties) (*http.Request, error) {
193	pathParameters := map[string]interface{}{
194		"accountName":       autorest.Encode("path", accountName),
195		"BlobServicesName":  autorest.Encode("path", "default"),
196		"resourceGroupName": autorest.Encode("path", resourceGroupName),
197		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
198	}
199
200	const APIVersion = "2018-07-01"
201	queryParameters := map[string]interface{}{
202		"api-version": APIVersion,
203	}
204
205	preparer := autorest.CreatePreparer(
206		autorest.AsContentType("application/json; charset=utf-8"),
207		autorest.AsPut(),
208		autorest.WithBaseURL(client.BaseURI),
209		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/blobServices/{BlobServicesName}", pathParameters),
210		autorest.WithJSON(parameters),
211		autorest.WithQueryParameters(queryParameters))
212	return preparer.Prepare((&http.Request{}).WithContext(ctx))
213}
214
215// SetServicePropertiesSender sends the SetServiceProperties request. The method will close the
216// http.Response Body if it receives an error.
217func (client BlobServicesClient) SetServicePropertiesSender(req *http.Request) (*http.Response, error) {
218	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
219}
220
221// SetServicePropertiesResponder handles the response to the SetServiceProperties request. The method always
222// closes the http.Response Body.
223func (client BlobServicesClient) SetServicePropertiesResponder(resp *http.Response) (result BlobServiceProperties, err error) {
224	err = autorest.Respond(
225		resp,
226		azure.WithErrorUnlessStatusCode(http.StatusOK),
227		autorest.ByUnmarshallingJSON(&result),
228		autorest.ByClosing())
229	result.Response = autorest.Response{Response: resp}
230	return
231}
232