1// Package dataprotection implements the Azure ARM Dataprotection service API version 2021-01-01. 2// 3// Open API 2.0 Specs for Azure Data Protection service 4package dataprotection 5 6// Copyright (c) Microsoft Corporation. All rights reserved. 7// Licensed under the MIT License. See License.txt in the project root for license information. 8// 9// Code generated by Microsoft (R) AutoRest Code Generator. 10// Changes may cause incorrect behavior and will be lost if the code is regenerated. 11 12import ( 13 "context" 14 "github.com/Azure/go-autorest/autorest" 15 "github.com/Azure/go-autorest/autorest/azure" 16 "github.com/Azure/go-autorest/tracing" 17 "net/http" 18) 19 20const ( 21 // DefaultBaseURI is the default URI used for the service Dataprotection 22 DefaultBaseURI = "https://management.azure.com" 23) 24 25// BaseClient is the base client for Dataprotection. 26type BaseClient struct { 27 autorest.Client 28 BaseURI string 29 SubscriptionID string 30} 31 32// New creates an instance of the BaseClient client. 33func New(subscriptionID string) BaseClient { 34 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 38// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 39func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 40 return BaseClient{ 41 Client: autorest.NewClientWithUserAgent(UserAgent()), 42 BaseURI: baseURI, 43 SubscriptionID: subscriptionID, 44 } 45} 46 47// CheckFeatureSupport sends the check feature support request. 48// Parameters: 49// parameters - feature support request object 50func (client BaseClient) CheckFeatureSupport(ctx context.Context, location string, parameters BasicFeatureValidationRequestBase) (result FeatureValidationResponseBaseModel, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckFeatureSupport") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.CheckFeatureSupportPreparer(ctx, location, parameters) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "CheckFeatureSupport", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.CheckFeatureSupportSender(req) 68 if err != nil { 69 result.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "CheckFeatureSupport", resp, "Failure sending request") 71 return 72 } 73 74 result, err = client.CheckFeatureSupportResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "CheckFeatureSupport", resp, "Failure responding to request") 77 return 78 } 79 80 return 81} 82 83// CheckFeatureSupportPreparer prepares the CheckFeatureSupport request. 84func (client BaseClient) CheckFeatureSupportPreparer(ctx context.Context, location string, parameters BasicFeatureValidationRequestBase) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "location": autorest.Encode("path", location), 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 } 89 90 const APIVersion = "2021-01-01" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsContentType("application/json; charset=utf-8"), 97 autorest.AsPost(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataProtection/locations/{location}/checkFeatureSupport", pathParameters), 100 autorest.WithJSON(parameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CheckFeatureSupportSender sends the CheckFeatureSupport request. The method will close the 106// http.Response Body if it receives an error. 107func (client BaseClient) CheckFeatureSupportSender(req *http.Request) (*http.Response, error) { 108 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 109} 110 111// CheckFeatureSupportResponder handles the response to the CheckFeatureSupport request. The method always 112// closes the http.Response Body. 113func (client BaseClient) CheckFeatureSupportResponder(resp *http.Response) (result FeatureValidationResponseBaseModel, err error) { 114 err = autorest.Respond( 115 resp, 116 azure.WithErrorUnlessStatusCode(http.StatusOK), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122 123// GetOperationResultPatch sends the get operation result patch request. 124// Parameters: 125// vaultName - the name of the backup vault. 126// resourceGroupName - the name of the resource group where the backup vault is present. 127func (client BaseClient) GetOperationResultPatch(ctx context.Context, vaultName string, resourceGroupName string, operationID string) (result BackupVaultResource, err error) { 128 if tracing.IsEnabled() { 129 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetOperationResultPatch") 130 defer func() { 131 sc := -1 132 if result.Response.Response != nil { 133 sc = result.Response.Response.StatusCode 134 } 135 tracing.EndSpan(ctx, sc, err) 136 }() 137 } 138 req, err := client.GetOperationResultPatchPreparer(ctx, vaultName, resourceGroupName, operationID) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationResultPatch", nil, "Failure preparing request") 141 return 142 } 143 144 resp, err := client.GetOperationResultPatchSender(req) 145 if err != nil { 146 result.Response = autorest.Response{Response: resp} 147 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationResultPatch", resp, "Failure sending request") 148 return 149 } 150 151 result, err = client.GetOperationResultPatchResponder(resp) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationResultPatch", resp, "Failure responding to request") 154 return 155 } 156 157 return 158} 159 160// GetOperationResultPatchPreparer prepares the GetOperationResultPatch request. 161func (client BaseClient) GetOperationResultPatchPreparer(ctx context.Context, vaultName string, resourceGroupName string, operationID string) (*http.Request, error) { 162 pathParameters := map[string]interface{}{ 163 "operationId": autorest.Encode("path", operationID), 164 "resourceGroupName": autorest.Encode("path", resourceGroupName), 165 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 166 "vaultName": autorest.Encode("path", vaultName), 167 } 168 169 const APIVersion = "2021-01-01" 170 queryParameters := map[string]interface{}{ 171 "api-version": APIVersion, 172 } 173 174 preparer := autorest.CreatePreparer( 175 autorest.AsGet(), 176 autorest.WithBaseURL(client.BaseURI), 177 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/operationResults/{operationId}", pathParameters), 178 autorest.WithQueryParameters(queryParameters)) 179 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 180} 181 182// GetOperationResultPatchSender sends the GetOperationResultPatch request. The method will close the 183// http.Response Body if it receives an error. 184func (client BaseClient) GetOperationResultPatchSender(req *http.Request) (*http.Response, error) { 185 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 186} 187 188// GetOperationResultPatchResponder handles the response to the GetOperationResultPatch request. The method always 189// closes the http.Response Body. 190func (client BaseClient) GetOperationResultPatchResponder(resp *http.Response) (result BackupVaultResource, err error) { 191 err = autorest.Respond( 192 resp, 193 azure.WithErrorUnlessStatusCode(http.StatusOK), 194 autorest.ByUnmarshallingJSON(&result), 195 autorest.ByClosing()) 196 result.Response = autorest.Response{Response: resp} 197 return 198} 199 200// GetOperationStatus sends the get operation status request. 201func (client BaseClient) GetOperationStatus(ctx context.Context, location string, operationID string) (result OperationResource, err error) { 202 if tracing.IsEnabled() { 203 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetOperationStatus") 204 defer func() { 205 sc := -1 206 if result.Response.Response != nil { 207 sc = result.Response.Response.StatusCode 208 } 209 tracing.EndSpan(ctx, sc, err) 210 }() 211 } 212 req, err := client.GetOperationStatusPreparer(ctx, location, operationID) 213 if err != nil { 214 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationStatus", nil, "Failure preparing request") 215 return 216 } 217 218 resp, err := client.GetOperationStatusSender(req) 219 if err != nil { 220 result.Response = autorest.Response{Response: resp} 221 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationStatus", resp, "Failure sending request") 222 return 223 } 224 225 result, err = client.GetOperationStatusResponder(resp) 226 if err != nil { 227 err = autorest.NewErrorWithError(err, "dataprotection.BaseClient", "GetOperationStatus", resp, "Failure responding to request") 228 return 229 } 230 231 return 232} 233 234// GetOperationStatusPreparer prepares the GetOperationStatus request. 235func (client BaseClient) GetOperationStatusPreparer(ctx context.Context, location string, operationID string) (*http.Request, error) { 236 pathParameters := map[string]interface{}{ 237 "location": autorest.Encode("path", location), 238 "operationId": autorest.Encode("path", operationID), 239 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 240 } 241 242 const APIVersion = "2021-01-01" 243 queryParameters := map[string]interface{}{ 244 "api-version": APIVersion, 245 } 246 247 preparer := autorest.CreatePreparer( 248 autorest.AsGet(), 249 autorest.WithBaseURL(client.BaseURI), 250 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataProtection/locations/{location}/operationStatus/{operationId}", pathParameters), 251 autorest.WithQueryParameters(queryParameters)) 252 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 253} 254 255// GetOperationStatusSender sends the GetOperationStatus request. The method will close the 256// http.Response Body if it receives an error. 257func (client BaseClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) { 258 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 259} 260 261// GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always 262// closes the http.Response Body. 263func (client BaseClient) GetOperationStatusResponder(resp *http.Response) (result OperationResource, err error) { 264 err = autorest.Respond( 265 resp, 266 azure.WithErrorUnlessStatusCode(http.StatusOK), 267 autorest.ByUnmarshallingJSON(&result), 268 autorest.ByClosing()) 269 result.Response = autorest.Response{Response: resp} 270 return 271} 272