1package sql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient is the the Azure SQL Database management API 29// provides a RESTful set of web services that interact with Azure SQL Database services to manage your databases. The 30// API enables you to create, retrieve, update, and delete databases. 31type ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient struct { 32 BaseClient 33} 34 35// NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient creates an instance of the 36// ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient client. 37func NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient(subscriptionID string) ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient { 38 return NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI creates an instance of the 42// ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient client using a custom endpoint. Use this 43// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 44func NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient { 45 return ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 46} 47 48// CreateOrUpdate sets a database's long term retention policy. 49// Parameters: 50// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 51// from the Azure Resource Manager API or the portal. 52// managedInstanceName - the name of the managed instance. 53// parameters - the long term retention policy info. 54func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string, parameters ManagedBackupShortTermRetentionPolicy) (result ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesCreateOrUpdateFuture, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.CreateOrUpdate") 57 defer func() { 58 sc := -1 59 if result.Response() != nil { 60 sc = result.Response().StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID, parameters) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 68 return 69 } 70 71 result, err = client.CreateOrUpdateSender(req) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "CreateOrUpdate", result.Response(), "Failure sending request") 74 return 75 } 76 77 return 78} 79 80// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 81func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string, parameters ManagedBackupShortTermRetentionPolicy) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "managedInstanceName": autorest.Encode("path", managedInstanceName), 84 "policyName": autorest.Encode("path", "default"), 85 "resourceGroupName": autorest.Encode("path", resourceGroupName), 86 "restorableDroppedDatabaseId": autorest.Encode("path", restorableDroppedDatabaseID), 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 } 89 90 const APIVersion = "2017-03-01-preview" 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.AsPut(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", pathParameters), 100 autorest.WithJSON(parameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 106// http.Response Body if it receives an error. 107func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdateSender(req *http.Request) (future ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesCreateOrUpdateFuture, err error) { 108 var resp *http.Response 109 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110 if err != nil { 111 return 112 } 113 future.Future, err = azure.NewFutureFromResponse(resp) 114 return 115} 116 117// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 118// closes the http.Response Body. 119func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ManagedBackupShortTermRetentionPolicy, err error) { 120 err = autorest.Respond( 121 resp, 122 client.ByInspecting(), 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Get gets a dropped database's short term retention policy. 131// Parameters: 132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 133// from the Azure Resource Manager API or the portal. 134// managedInstanceName - the name of the managed instance. 135func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) Get(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (result ManagedBackupShortTermRetentionPolicy, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.Get") 138 defer func() { 139 sc := -1 140 if result.Response.Response != nil { 141 sc = result.Response.Response.StatusCode 142 } 143 tracing.EndSpan(ctx, sc, err) 144 }() 145 } 146 req, err := client.GetPreparer(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "Get", nil, "Failure preparing request") 149 return 150 } 151 152 resp, err := client.GetSender(req) 153 if err != nil { 154 result.Response = autorest.Response{Response: resp} 155 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "Get", resp, "Failure sending request") 156 return 157 } 158 159 result, err = client.GetResponder(resp) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "Get", resp, "Failure responding to request") 162 } 163 164 return 165} 166 167// GetPreparer prepares the Get request. 168func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (*http.Request, error) { 169 pathParameters := map[string]interface{}{ 170 "managedInstanceName": autorest.Encode("path", managedInstanceName), 171 "policyName": autorest.Encode("path", "default"), 172 "resourceGroupName": autorest.Encode("path", resourceGroupName), 173 "restorableDroppedDatabaseId": autorest.Encode("path", restorableDroppedDatabaseID), 174 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 175 } 176 177 const APIVersion = "2017-03-01-preview" 178 queryParameters := map[string]interface{}{ 179 "api-version": APIVersion, 180 } 181 182 preparer := autorest.CreatePreparer( 183 autorest.AsGet(), 184 autorest.WithBaseURL(client.BaseURI), 185 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", pathParameters), 186 autorest.WithQueryParameters(queryParameters)) 187 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 188} 189 190// GetSender sends the Get request. The method will close the 191// http.Response Body if it receives an error. 192func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 193 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 194} 195 196// GetResponder handles the response to the Get request. The method always 197// closes the http.Response Body. 198func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) GetResponder(resp *http.Response) (result ManagedBackupShortTermRetentionPolicy, err error) { 199 err = autorest.Respond( 200 resp, 201 client.ByInspecting(), 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208 209// ListByRestorableDroppedDatabase gets a dropped database's short term retention policy list. 210// Parameters: 211// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 212// from the Azure Resource Manager API or the portal. 213// managedInstanceName - the name of the managed instance. 214func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabase(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (result ManagedBackupShortTermRetentionPolicyListResultPage, err error) { 215 if tracing.IsEnabled() { 216 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.ListByRestorableDroppedDatabase") 217 defer func() { 218 sc := -1 219 if result.mbstrplr.Response.Response != nil { 220 sc = result.mbstrplr.Response.Response.StatusCode 221 } 222 tracing.EndSpan(ctx, sc, err) 223 }() 224 } 225 result.fn = client.listByRestorableDroppedDatabaseNextResults 226 req, err := client.ListByRestorableDroppedDatabasePreparer(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID) 227 if err != nil { 228 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "ListByRestorableDroppedDatabase", nil, "Failure preparing request") 229 return 230 } 231 232 resp, err := client.ListByRestorableDroppedDatabaseSender(req) 233 if err != nil { 234 result.mbstrplr.Response = autorest.Response{Response: resp} 235 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "ListByRestorableDroppedDatabase", resp, "Failure sending request") 236 return 237 } 238 239 result.mbstrplr, err = client.ListByRestorableDroppedDatabaseResponder(resp) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "ListByRestorableDroppedDatabase", resp, "Failure responding to request") 242 } 243 244 return 245} 246 247// ListByRestorableDroppedDatabasePreparer prepares the ListByRestorableDroppedDatabase request. 248func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabasePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (*http.Request, error) { 249 pathParameters := map[string]interface{}{ 250 "managedInstanceName": autorest.Encode("path", managedInstanceName), 251 "resourceGroupName": autorest.Encode("path", resourceGroupName), 252 "restorableDroppedDatabaseId": autorest.Encode("path", restorableDroppedDatabaseID), 253 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 254 } 255 256 const APIVersion = "2017-03-01-preview" 257 queryParameters := map[string]interface{}{ 258 "api-version": APIVersion, 259 } 260 261 preparer := autorest.CreatePreparer( 262 autorest.AsGet(), 263 autorest.WithBaseURL(client.BaseURI), 264 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies", pathParameters), 265 autorest.WithQueryParameters(queryParameters)) 266 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 267} 268 269// ListByRestorableDroppedDatabaseSender sends the ListByRestorableDroppedDatabase request. The method will close the 270// http.Response Body if it receives an error. 271func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabaseSender(req *http.Request) (*http.Response, error) { 272 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 273} 274 275// ListByRestorableDroppedDatabaseResponder handles the response to the ListByRestorableDroppedDatabase request. The method always 276// closes the http.Response Body. 277func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabaseResponder(resp *http.Response) (result ManagedBackupShortTermRetentionPolicyListResult, err error) { 278 err = autorest.Respond( 279 resp, 280 client.ByInspecting(), 281 azure.WithErrorUnlessStatusCode(http.StatusOK), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// listByRestorableDroppedDatabaseNextResults retrieves the next set of results, if any. 289func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) listByRestorableDroppedDatabaseNextResults(ctx context.Context, lastResults ManagedBackupShortTermRetentionPolicyListResult) (result ManagedBackupShortTermRetentionPolicyListResult, err error) { 290 req, err := lastResults.managedBackupShortTermRetentionPolicyListResultPreparer(ctx) 291 if err != nil { 292 return result, autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "listByRestorableDroppedDatabaseNextResults", nil, "Failure preparing next results request") 293 } 294 if req == nil { 295 return 296 } 297 resp, err := client.ListByRestorableDroppedDatabaseSender(req) 298 if err != nil { 299 result.Response = autorest.Response{Response: resp} 300 return result, autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "listByRestorableDroppedDatabaseNextResults", resp, "Failure sending next results request") 301 } 302 result, err = client.ListByRestorableDroppedDatabaseResponder(resp) 303 if err != nil { 304 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "listByRestorableDroppedDatabaseNextResults", resp, "Failure responding to next results request") 305 } 306 return 307} 308 309// ListByRestorableDroppedDatabaseComplete enumerates all values, automatically crossing page boundaries as required. 310func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabaseComplete(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (result ManagedBackupShortTermRetentionPolicyListResultIterator, err error) { 311 if tracing.IsEnabled() { 312 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.ListByRestorableDroppedDatabase") 313 defer func() { 314 sc := -1 315 if result.Response().Response.Response != nil { 316 sc = result.page.Response().Response.Response.StatusCode 317 } 318 tracing.EndSpan(ctx, sc, err) 319 }() 320 } 321 result.page, err = client.ListByRestorableDroppedDatabase(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID) 322 return 323} 324 325// Update sets a database's long term retention policy. 326// Parameters: 327// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 328// from the Azure Resource Manager API or the portal. 329// managedInstanceName - the name of the managed instance. 330// parameters - the long term retention policy info. 331func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) Update(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string, parameters ManagedBackupShortTermRetentionPolicy) (result ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesUpdateFuture, err error) { 332 if tracing.IsEnabled() { 333 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.Update") 334 defer func() { 335 sc := -1 336 if result.Response() != nil { 337 sc = result.Response().StatusCode 338 } 339 tracing.EndSpan(ctx, sc, err) 340 }() 341 } 342 req, err := client.UpdatePreparer(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID, parameters) 343 if err != nil { 344 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "Update", nil, "Failure preparing request") 345 return 346 } 347 348 result, err = client.UpdateSender(req) 349 if err != nil { 350 err = autorest.NewErrorWithError(err, "sql.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient", "Update", result.Response(), "Failure sending request") 351 return 352 } 353 354 return 355} 356 357// UpdatePreparer prepares the Update request. 358func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string, parameters ManagedBackupShortTermRetentionPolicy) (*http.Request, error) { 359 pathParameters := map[string]interface{}{ 360 "managedInstanceName": autorest.Encode("path", managedInstanceName), 361 "policyName": autorest.Encode("path", "default"), 362 "resourceGroupName": autorest.Encode("path", resourceGroupName), 363 "restorableDroppedDatabaseId": autorest.Encode("path", restorableDroppedDatabaseID), 364 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 365 } 366 367 const APIVersion = "2017-03-01-preview" 368 queryParameters := map[string]interface{}{ 369 "api-version": APIVersion, 370 } 371 372 preparer := autorest.CreatePreparer( 373 autorest.AsContentType("application/json; charset=utf-8"), 374 autorest.AsPatch(), 375 autorest.WithBaseURL(client.BaseURI), 376 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", pathParameters), 377 autorest.WithJSON(parameters), 378 autorest.WithQueryParameters(queryParameters)) 379 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 380} 381 382// UpdateSender sends the Update request. The method will close the 383// http.Response Body if it receives an error. 384func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) UpdateSender(req *http.Request) (future ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesUpdateFuture, err error) { 385 var resp *http.Response 386 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 387 if err != nil { 388 return 389 } 390 future.Future, err = azure.NewFutureFromResponse(resp) 391 return 392} 393 394// UpdateResponder handles the response to the Update request. The method always 395// closes the http.Response Body. 396func (client ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) UpdateResponder(resp *http.Response) (result ManagedBackupShortTermRetentionPolicy, err error) { 397 err = autorest.Respond( 398 resp, 399 client.ByInspecting(), 400 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 401 autorest.ByUnmarshallingJSON(&result), 402 autorest.ByClosing()) 403 result.Response = autorest.Response{Response: resp} 404 return 405} 406