1package sql 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// ImportExportClient is the the Azure SQL Database management API provides a RESTful set of web services that interact 19// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and 20// delete databases. 21type ImportExportClient struct { 22 BaseClient 23} 24 25// NewImportExportClient creates an instance of the ImportExportClient client. 26func NewImportExportClient(subscriptionID string) ImportExportClient { 27 return NewImportExportClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewImportExportClientWithBaseURI creates an instance of the ImportExportClient client using a custom endpoint. Use 31// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewImportExportClientWithBaseURI(baseURI string, subscriptionID string) ImportExportClient { 33 return ImportExportClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// Import imports a bacpac into a new database. 37// Parameters: 38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 39// from the Azure Resource Manager API or the portal. 40// serverName - the name of the server. 41// databaseName - the name of the database. 42// parameters - the database import request parameters. 43func (client ImportExportClient) Import(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters ImportExistingDatabaseDefinition) (result ImportExportImportFuture, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/ImportExportClient.Import") 46 defer func() { 47 sc := -1 48 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 49 sc = result.FutureAPI.Response().StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: parameters, 56 Constraints: []validation.Constraint{{Target: "parameters.StorageKey", Name: validation.Null, Rule: true, Chain: nil}, 57 {Target: "parameters.StorageURI", Name: validation.Null, Rule: true, Chain: nil}, 58 {Target: "parameters.AdministratorLogin", Name: validation.Null, Rule: true, Chain: nil}, 59 {Target: "parameters.AdministratorLoginPassword", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 60 return result, validation.NewError("sql.ImportExportClient", "Import", err.Error()) 61 } 62 63 req, err := client.ImportPreparer(ctx, resourceGroupName, serverName, databaseName, parameters) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "sql.ImportExportClient", "Import", nil, "Failure preparing request") 66 return 67 } 68 69 result, err = client.ImportSender(req) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "sql.ImportExportClient", "Import", nil, "Failure sending request") 72 return 73 } 74 75 return 76} 77 78// ImportPreparer prepares the Import request. 79func (client ImportExportClient) ImportPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters ImportExistingDatabaseDefinition) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "databaseName": autorest.Encode("path", databaseName), 82 "resourceGroupName": autorest.Encode("path", resourceGroupName), 83 "serverName": autorest.Encode("path", serverName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2020-02-02-preview" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsContentType("application/json; charset=utf-8"), 94 autorest.AsPost(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import", pathParameters), 97 autorest.WithJSON(parameters), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// ImportSender sends the Import request. The method will close the 103// http.Response Body if it receives an error. 104func (client ImportExportClient) ImportSender(req *http.Request) (future ImportExportImportFuture, err error) { 105 var resp *http.Response 106 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 107 if err != nil { 108 return 109 } 110 var azf azure.Future 111 azf, err = azure.NewFutureFromResponse(resp) 112 future.FutureAPI = &azf 113 future.Result = future.result 114 return 115} 116 117// ImportResponder handles the response to the Import request. The method always 118// closes the http.Response Body. 119func (client ImportExportClient) ImportResponder(resp *http.Response) (result ImportExportOperationResult, err error) { 120 err = autorest.Respond( 121 resp, 122 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128