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// PrivateLinkResourcesClient is the the Azure Storage Management API.
19type PrivateLinkResourcesClient struct {
20	BaseClient
21}
22
23// NewPrivateLinkResourcesClient creates an instance of the PrivateLinkResourcesClient client.
24func NewPrivateLinkResourcesClient(subscriptionID string) PrivateLinkResourcesClient {
25	return NewPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewPrivateLinkResourcesClientWithBaseURI creates an instance of the PrivateLinkResourcesClient 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 NewPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkResourcesClient {
32	return PrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// ListByStorageAccount gets the private link resources that need to be created for a storage account.
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 PrivateLinkResourcesClient) ListByStorageAccount(ctx context.Context, resourceGroupName string, accountName string) (result PrivateLinkResourceListResult, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.ListByStorageAccount")
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.PrivateLinkResourcesClient", "ListByStorageAccount", err.Error())
63	}
64
65	req, err := client.ListByStorageAccountPreparer(ctx, resourceGroupName, accountName)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "storage.PrivateLinkResourcesClient", "ListByStorageAccount", nil, "Failure preparing request")
68		return
69	}
70
71	resp, err := client.ListByStorageAccountSender(req)
72	if err != nil {
73		result.Response = autorest.Response{Response: resp}
74		err = autorest.NewErrorWithError(err, "storage.PrivateLinkResourcesClient", "ListByStorageAccount", resp, "Failure sending request")
75		return
76	}
77
78	result, err = client.ListByStorageAccountResponder(resp)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "storage.PrivateLinkResourcesClient", "ListByStorageAccount", resp, "Failure responding to request")
81		return
82	}
83
84	return
85}
86
87// ListByStorageAccountPreparer prepares the ListByStorageAccount request.
88func (client PrivateLinkResourcesClient) ListByStorageAccountPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
89	pathParameters := map[string]interface{}{
90		"accountName":       autorest.Encode("path", accountName),
91		"resourceGroupName": autorest.Encode("path", resourceGroupName),
92		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2021-02-01"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsGet(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/privateLinkResources", pathParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// ListByStorageAccountSender sends the ListByStorageAccount request. The method will close the
109// http.Response Body if it receives an error.
110func (client PrivateLinkResourcesClient) ListByStorageAccountSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// ListByStorageAccountResponder handles the response to the ListByStorageAccount request. The method always
115// closes the http.Response Body.
116func (client PrivateLinkResourcesClient) ListByStorageAccountResponder(resp *http.Response) (result PrivateLinkResourceListResult, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125