1package backup 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/tracing" 14 "net/http" 15) 16 17// ResourceEncryptionConfigsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service 18type ResourceEncryptionConfigsClient struct { 19 BaseClient 20} 21 22// NewResourceEncryptionConfigsClient creates an instance of the ResourceEncryptionConfigsClient client. 23func NewResourceEncryptionConfigsClient(subscriptionID string) ResourceEncryptionConfigsClient { 24 return NewResourceEncryptionConfigsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewResourceEncryptionConfigsClientWithBaseURI creates an instance of the ResourceEncryptionConfigsClient client 28// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 29// clouds, Azure stack). 30func NewResourceEncryptionConfigsClientWithBaseURI(baseURI string, subscriptionID string) ResourceEncryptionConfigsClient { 31 return ResourceEncryptionConfigsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Get fetches Vault Encryption config. 35// Parameters: 36// vaultName - the name of the recovery services vault. 37// resourceGroupName - the name of the resource group where the recovery services vault is present. 38func (client ResourceEncryptionConfigsClient) Get(ctx context.Context, vaultName string, resourceGroupName string) (result ResourceEncryptionConfigResource, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/ResourceEncryptionConfigsClient.Get") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 req, err := client.GetPreparer(ctx, vaultName, resourceGroupName) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Get", nil, "Failure preparing request") 52 return 53 } 54 55 resp, err := client.GetSender(req) 56 if err != nil { 57 result.Response = autorest.Response{Response: resp} 58 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Get", resp, "Failure sending request") 59 return 60 } 61 62 result, err = client.GetResponder(resp) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Get", resp, "Failure responding to request") 65 return 66 } 67 68 return 69} 70 71// GetPreparer prepares the Get request. 72func (client ResourceEncryptionConfigsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string) (*http.Request, error) { 73 pathParameters := map[string]interface{}{ 74 "resourceGroupName": autorest.Encode("path", resourceGroupName), 75 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 76 "vaultName": autorest.Encode("path", vaultName), 77 } 78 79 const APIVersion = "2021-01-01" 80 queryParameters := map[string]interface{}{ 81 "api-version": APIVersion, 82 } 83 84 preparer := autorest.CreatePreparer( 85 autorest.AsGet(), 86 autorest.WithBaseURL(client.BaseURI), 87 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupEncryptionConfigs/backupResourceEncryptionConfig", pathParameters), 88 autorest.WithQueryParameters(queryParameters)) 89 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 90} 91 92// GetSender sends the Get request. The method will close the 93// http.Response Body if it receives an error. 94func (client ResourceEncryptionConfigsClient) GetSender(req *http.Request) (*http.Response, error) { 95 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 96} 97 98// GetResponder handles the response to the Get request. The method always 99// closes the http.Response Body. 100func (client ResourceEncryptionConfigsClient) GetResponder(resp *http.Response) (result ResourceEncryptionConfigResource, err error) { 101 err = autorest.Respond( 102 resp, 103 azure.WithErrorUnlessStatusCode(http.StatusOK), 104 autorest.ByUnmarshallingJSON(&result), 105 autorest.ByClosing()) 106 result.Response = autorest.Response{Response: resp} 107 return 108} 109 110// Update updates Vault encryption config. 111// Parameters: 112// vaultName - the name of the recovery services vault. 113// resourceGroupName - the name of the resource group where the recovery services vault is present. 114// parameters - vault encryption input config request 115func (client ResourceEncryptionConfigsClient) Update(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceEncryptionConfigResource) (result autorest.Response, err error) { 116 if tracing.IsEnabled() { 117 ctx = tracing.StartSpan(ctx, fqdn+"/ResourceEncryptionConfigsClient.Update") 118 defer func() { 119 sc := -1 120 if result.Response != nil { 121 sc = result.Response.StatusCode 122 } 123 tracing.EndSpan(ctx, sc, err) 124 }() 125 } 126 req, err := client.UpdatePreparer(ctx, vaultName, resourceGroupName, parameters) 127 if err != nil { 128 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Update", nil, "Failure preparing request") 129 return 130 } 131 132 resp, err := client.UpdateSender(req) 133 if err != nil { 134 result.Response = resp 135 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Update", resp, "Failure sending request") 136 return 137 } 138 139 result, err = client.UpdateResponder(resp) 140 if err != nil { 141 err = autorest.NewErrorWithError(err, "backup.ResourceEncryptionConfigsClient", "Update", resp, "Failure responding to request") 142 return 143 } 144 145 return 146} 147 148// UpdatePreparer prepares the Update request. 149func (client ResourceEncryptionConfigsClient) UpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceEncryptionConfigResource) (*http.Request, error) { 150 pathParameters := map[string]interface{}{ 151 "resourceGroupName": autorest.Encode("path", resourceGroupName), 152 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 153 "vaultName": autorest.Encode("path", vaultName), 154 } 155 156 const APIVersion = "2021-01-01" 157 queryParameters := map[string]interface{}{ 158 "api-version": APIVersion, 159 } 160 161 preparer := autorest.CreatePreparer( 162 autorest.AsContentType("application/json; charset=utf-8"), 163 autorest.AsPut(), 164 autorest.WithBaseURL(client.BaseURI), 165 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupEncryptionConfigs/backupResourceEncryptionConfig", pathParameters), 166 autorest.WithJSON(parameters), 167 autorest.WithQueryParameters(queryParameters)) 168 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 169} 170 171// UpdateSender sends the Update request. The method will close the 172// http.Response Body if it receives an error. 173func (client ResourceEncryptionConfigsClient) UpdateSender(req *http.Request) (*http.Response, error) { 174 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 175} 176 177// UpdateResponder handles the response to the Update request. The method always 178// closes the http.Response Body. 179func (client ResourceEncryptionConfigsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 180 err = autorest.Respond( 181 resp, 182 azure.WithErrorUnlessStatusCode(http.StatusOK), 183 autorest.ByClosing()) 184 result.Response = resp 185 return 186} 187