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// EncryptionScopesClient is the the Azure Storage Management API.
19type EncryptionScopesClient struct {
20	BaseClient
21}
22
23// NewEncryptionScopesClient creates an instance of the EncryptionScopesClient client.
24func NewEncryptionScopesClient(subscriptionID string) EncryptionScopesClient {
25	return NewEncryptionScopesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewEncryptionScopesClientWithBaseURI creates an instance of the EncryptionScopesClient client using a custom
29// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
30// stack).
31func NewEncryptionScopesClientWithBaseURI(baseURI string, subscriptionID string) EncryptionScopesClient {
32	return EncryptionScopesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// Get returns the properties for the specified encryption scope.
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.
41// encryptionScopeName - the name of the encryption scope within the specified storage account. Encryption
42// scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-)
43// only. Every dash (-) character must be immediately preceded and followed by a letter or number.
44func (client EncryptionScopesClient) Get(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string) (result EncryptionScope, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionScopesClient.Get")
47		defer func() {
48			sc := -1
49			if result.Response.Response != nil {
50				sc = result.Response.Response.StatusCode
51			}
52			tracing.EndSpan(ctx, sc, err)
53		}()
54	}
55	if err := validation.Validate([]validation.Validation{
56		{TargetValue: resourceGroupName,
57			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
59				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
60		{TargetValue: accountName,
61			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
62				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
63		{TargetValue: client.SubscriptionID,
64			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
65		{TargetValue: encryptionScopeName,
66			Constraints: []validation.Constraint{{Target: "encryptionScopeName", Name: validation.MaxLength, Rule: 63, Chain: nil},
67				{Target: "encryptionScopeName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
68		return result, validation.NewError("storage.EncryptionScopesClient", "Get", err.Error())
69	}
70
71	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, encryptionScopeName)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Get", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.GetSender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Get", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.GetResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Get", resp, "Failure responding to request")
87		return
88	}
89
90	return
91}
92
93// GetPreparer prepares the Get request.
94func (client EncryptionScopesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"accountName":         autorest.Encode("path", accountName),
97		"encryptionScopeName": autorest.Encode("path", encryptionScopeName),
98		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
99		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
100	}
101
102	const APIVersion = "2019-06-01"
103	queryParameters := map[string]interface{}{
104		"api-version": APIVersion,
105	}
106
107	preparer := autorest.CreatePreparer(
108		autorest.AsGet(),
109		autorest.WithBaseURL(client.BaseURI),
110		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/encryptionScopes/{encryptionScopeName}", pathParameters),
111		autorest.WithQueryParameters(queryParameters))
112	return preparer.Prepare((&http.Request{}).WithContext(ctx))
113}
114
115// GetSender sends the Get request. The method will close the
116// http.Response Body if it receives an error.
117func (client EncryptionScopesClient) GetSender(req *http.Request) (*http.Response, error) {
118	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
119}
120
121// GetResponder handles the response to the Get request. The method always
122// closes the http.Response Body.
123func (client EncryptionScopesClient) GetResponder(resp *http.Response) (result EncryptionScope, err error) {
124	err = autorest.Respond(
125		resp,
126		azure.WithErrorUnlessStatusCode(http.StatusOK),
127		autorest.ByUnmarshallingJSON(&result),
128		autorest.ByClosing())
129	result.Response = autorest.Response{Response: resp}
130	return
131}
132
133// List lists all the encryption scopes available under the specified storage account.
134// Parameters:
135// resourceGroupName - the name of the resource group within the user's subscription. The name is case
136// insensitive.
137// accountName - the name of the storage account within the specified resource group. Storage account names
138// must be between 3 and 24 characters in length and use numbers and lower-case letters only.
139func (client EncryptionScopesClient) List(ctx context.Context, resourceGroupName string, accountName string) (result EncryptionScopeListResultPage, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionScopesClient.List")
142		defer func() {
143			sc := -1
144			if result.eslr.Response.Response != nil {
145				sc = result.eslr.Response.Response.StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	if err := validation.Validate([]validation.Validation{
151		{TargetValue: resourceGroupName,
152			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
154				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
155		{TargetValue: accountName,
156			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
157				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
158		{TargetValue: client.SubscriptionID,
159			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
160		return result, validation.NewError("storage.EncryptionScopesClient", "List", err.Error())
161	}
162
163	result.fn = client.listNextResults
164	req, err := client.ListPreparer(ctx, resourceGroupName, accountName)
165	if err != nil {
166		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "List", nil, "Failure preparing request")
167		return
168	}
169
170	resp, err := client.ListSender(req)
171	if err != nil {
172		result.eslr.Response = autorest.Response{Response: resp}
173		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "List", resp, "Failure sending request")
174		return
175	}
176
177	result.eslr, err = client.ListResponder(resp)
178	if err != nil {
179		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "List", resp, "Failure responding to request")
180		return
181	}
182	if result.eslr.hasNextLink() && result.eslr.IsEmpty() {
183		err = result.NextWithContext(ctx)
184		return
185	}
186
187	return
188}
189
190// ListPreparer prepares the List request.
191func (client EncryptionScopesClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
192	pathParameters := map[string]interface{}{
193		"accountName":       autorest.Encode("path", accountName),
194		"resourceGroupName": autorest.Encode("path", resourceGroupName),
195		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
196	}
197
198	const APIVersion = "2019-06-01"
199	queryParameters := map[string]interface{}{
200		"api-version": APIVersion,
201	}
202
203	preparer := autorest.CreatePreparer(
204		autorest.AsGet(),
205		autorest.WithBaseURL(client.BaseURI),
206		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/encryptionScopes", pathParameters),
207		autorest.WithQueryParameters(queryParameters))
208	return preparer.Prepare((&http.Request{}).WithContext(ctx))
209}
210
211// ListSender sends the List request. The method will close the
212// http.Response Body if it receives an error.
213func (client EncryptionScopesClient) ListSender(req *http.Request) (*http.Response, error) {
214	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
215}
216
217// ListResponder handles the response to the List request. The method always
218// closes the http.Response Body.
219func (client EncryptionScopesClient) ListResponder(resp *http.Response) (result EncryptionScopeListResult, err error) {
220	err = autorest.Respond(
221		resp,
222		azure.WithErrorUnlessStatusCode(http.StatusOK),
223		autorest.ByUnmarshallingJSON(&result),
224		autorest.ByClosing())
225	result.Response = autorest.Response{Response: resp}
226	return
227}
228
229// listNextResults retrieves the next set of results, if any.
230func (client EncryptionScopesClient) listNextResults(ctx context.Context, lastResults EncryptionScopeListResult) (result EncryptionScopeListResult, err error) {
231	req, err := lastResults.encryptionScopeListResultPreparer(ctx)
232	if err != nil {
233		return result, autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "listNextResults", nil, "Failure preparing next results request")
234	}
235	if req == nil {
236		return
237	}
238	resp, err := client.ListSender(req)
239	if err != nil {
240		result.Response = autorest.Response{Response: resp}
241		return result, autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "listNextResults", resp, "Failure sending next results request")
242	}
243	result, err = client.ListResponder(resp)
244	if err != nil {
245		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "listNextResults", resp, "Failure responding to next results request")
246	}
247	return
248}
249
250// ListComplete enumerates all values, automatically crossing page boundaries as required.
251func (client EncryptionScopesClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string) (result EncryptionScopeListResultIterator, err error) {
252	if tracing.IsEnabled() {
253		ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionScopesClient.List")
254		defer func() {
255			sc := -1
256			if result.Response().Response.Response != nil {
257				sc = result.page.Response().Response.Response.StatusCode
258			}
259			tracing.EndSpan(ctx, sc, err)
260		}()
261	}
262	result.page, err = client.List(ctx, resourceGroupName, accountName)
263	return
264}
265
266// Patch update encryption scope properties as specified in the request body. Update fails if the specified encryption
267// scope does not already exist.
268// Parameters:
269// resourceGroupName - the name of the resource group within the user's subscription. The name is case
270// insensitive.
271// accountName - the name of the storage account within the specified resource group. Storage account names
272// must be between 3 and 24 characters in length and use numbers and lower-case letters only.
273// encryptionScopeName - the name of the encryption scope within the specified storage account. Encryption
274// scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-)
275// only. Every dash (-) character must be immediately preceded and followed by a letter or number.
276// encryptionScope - encryption scope properties to be used for the update.
277func (client EncryptionScopesClient) Patch(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string, encryptionScope EncryptionScope) (result EncryptionScope, err error) {
278	if tracing.IsEnabled() {
279		ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionScopesClient.Patch")
280		defer func() {
281			sc := -1
282			if result.Response.Response != nil {
283				sc = result.Response.Response.StatusCode
284			}
285			tracing.EndSpan(ctx, sc, err)
286		}()
287	}
288	if err := validation.Validate([]validation.Validation{
289		{TargetValue: resourceGroupName,
290			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
291				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
292				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
293		{TargetValue: accountName,
294			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
295				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
296		{TargetValue: client.SubscriptionID,
297			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
298		{TargetValue: encryptionScopeName,
299			Constraints: []validation.Constraint{{Target: "encryptionScopeName", Name: validation.MaxLength, Rule: 63, Chain: nil},
300				{Target: "encryptionScopeName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
301		return result, validation.NewError("storage.EncryptionScopesClient", "Patch", err.Error())
302	}
303
304	req, err := client.PatchPreparer(ctx, resourceGroupName, accountName, encryptionScopeName, encryptionScope)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Patch", nil, "Failure preparing request")
307		return
308	}
309
310	resp, err := client.PatchSender(req)
311	if err != nil {
312		result.Response = autorest.Response{Response: resp}
313		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Patch", resp, "Failure sending request")
314		return
315	}
316
317	result, err = client.PatchResponder(resp)
318	if err != nil {
319		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Patch", resp, "Failure responding to request")
320		return
321	}
322
323	return
324}
325
326// PatchPreparer prepares the Patch request.
327func (client EncryptionScopesClient) PatchPreparer(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string, encryptionScope EncryptionScope) (*http.Request, error) {
328	pathParameters := map[string]interface{}{
329		"accountName":         autorest.Encode("path", accountName),
330		"encryptionScopeName": autorest.Encode("path", encryptionScopeName),
331		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
332		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
333	}
334
335	const APIVersion = "2019-06-01"
336	queryParameters := map[string]interface{}{
337		"api-version": APIVersion,
338	}
339
340	preparer := autorest.CreatePreparer(
341		autorest.AsContentType("application/json; charset=utf-8"),
342		autorest.AsPatch(),
343		autorest.WithBaseURL(client.BaseURI),
344		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/encryptionScopes/{encryptionScopeName}", pathParameters),
345		autorest.WithJSON(encryptionScope),
346		autorest.WithQueryParameters(queryParameters))
347	return preparer.Prepare((&http.Request{}).WithContext(ctx))
348}
349
350// PatchSender sends the Patch request. The method will close the
351// http.Response Body if it receives an error.
352func (client EncryptionScopesClient) PatchSender(req *http.Request) (*http.Response, error) {
353	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
354}
355
356// PatchResponder handles the response to the Patch request. The method always
357// closes the http.Response Body.
358func (client EncryptionScopesClient) PatchResponder(resp *http.Response) (result EncryptionScope, err error) {
359	err = autorest.Respond(
360		resp,
361		azure.WithErrorUnlessStatusCode(http.StatusOK),
362		autorest.ByUnmarshallingJSON(&result),
363		autorest.ByClosing())
364	result.Response = autorest.Response{Response: resp}
365	return
366}
367
368// Put synchronously creates or updates an encryption scope under the specified storage account. If an encryption scope
369// is already created and a subsequent request is issued with different properties, the encryption scope properties
370// will be updated per the specified request.
371// Parameters:
372// resourceGroupName - the name of the resource group within the user's subscription. The name is case
373// insensitive.
374// accountName - the name of the storage account within the specified resource group. Storage account names
375// must be between 3 and 24 characters in length and use numbers and lower-case letters only.
376// encryptionScopeName - the name of the encryption scope within the specified storage account. Encryption
377// scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-)
378// only. Every dash (-) character must be immediately preceded and followed by a letter or number.
379// encryptionScope - encryption scope properties to be used for the create or update.
380func (client EncryptionScopesClient) Put(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string, encryptionScope EncryptionScope) (result EncryptionScope, err error) {
381	if tracing.IsEnabled() {
382		ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionScopesClient.Put")
383		defer func() {
384			sc := -1
385			if result.Response.Response != nil {
386				sc = result.Response.Response.StatusCode
387			}
388			tracing.EndSpan(ctx, sc, err)
389		}()
390	}
391	if err := validation.Validate([]validation.Validation{
392		{TargetValue: resourceGroupName,
393			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
394				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
395				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
396		{TargetValue: accountName,
397			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
398				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
399		{TargetValue: client.SubscriptionID,
400			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
401		{TargetValue: encryptionScopeName,
402			Constraints: []validation.Constraint{{Target: "encryptionScopeName", Name: validation.MaxLength, Rule: 63, Chain: nil},
403				{Target: "encryptionScopeName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
404		return result, validation.NewError("storage.EncryptionScopesClient", "Put", err.Error())
405	}
406
407	req, err := client.PutPreparer(ctx, resourceGroupName, accountName, encryptionScopeName, encryptionScope)
408	if err != nil {
409		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Put", nil, "Failure preparing request")
410		return
411	}
412
413	resp, err := client.PutSender(req)
414	if err != nil {
415		result.Response = autorest.Response{Response: resp}
416		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Put", resp, "Failure sending request")
417		return
418	}
419
420	result, err = client.PutResponder(resp)
421	if err != nil {
422		err = autorest.NewErrorWithError(err, "storage.EncryptionScopesClient", "Put", resp, "Failure responding to request")
423		return
424	}
425
426	return
427}
428
429// PutPreparer prepares the Put request.
430func (client EncryptionScopesClient) PutPreparer(ctx context.Context, resourceGroupName string, accountName string, encryptionScopeName string, encryptionScope EncryptionScope) (*http.Request, error) {
431	pathParameters := map[string]interface{}{
432		"accountName":         autorest.Encode("path", accountName),
433		"encryptionScopeName": autorest.Encode("path", encryptionScopeName),
434		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
435		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
436	}
437
438	const APIVersion = "2019-06-01"
439	queryParameters := map[string]interface{}{
440		"api-version": APIVersion,
441	}
442
443	preparer := autorest.CreatePreparer(
444		autorest.AsContentType("application/json; charset=utf-8"),
445		autorest.AsPut(),
446		autorest.WithBaseURL(client.BaseURI),
447		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/encryptionScopes/{encryptionScopeName}", pathParameters),
448		autorest.WithJSON(encryptionScope),
449		autorest.WithQueryParameters(queryParameters))
450	return preparer.Prepare((&http.Request{}).WithContext(ctx))
451}
452
453// PutSender sends the Put request. The method will close the
454// http.Response Body if it receives an error.
455func (client EncryptionScopesClient) PutSender(req *http.Request) (*http.Response, error) {
456	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
457}
458
459// PutResponder handles the response to the Put request. The method always
460// closes the http.Response Body.
461func (client EncryptionScopesClient) PutResponder(resp *http.Response) (result EncryptionScope, err error) {
462	err = autorest.Respond(
463		resp,
464		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
465		autorest.ByUnmarshallingJSON(&result),
466		autorest.ByClosing())
467	result.Response = autorest.Response{Response: resp}
468	return
469}
470