1package synapse 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// SQLPoolGeoBackupPoliciesClient is the azure Synapse Analytics Management Client 19type SQLPoolGeoBackupPoliciesClient struct { 20 BaseClient 21} 22 23// NewSQLPoolGeoBackupPoliciesClient creates an instance of the SQLPoolGeoBackupPoliciesClient client. 24func NewSQLPoolGeoBackupPoliciesClient(subscriptionID string) SQLPoolGeoBackupPoliciesClient { 25 return NewSQLPoolGeoBackupPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewSQLPoolGeoBackupPoliciesClientWithBaseURI creates an instance of the SQLPoolGeoBackupPoliciesClient client using 29// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 30// clouds, Azure stack). 31func NewSQLPoolGeoBackupPoliciesClientWithBaseURI(baseURI string, subscriptionID string) SQLPoolGeoBackupPoliciesClient { 32 return SQLPoolGeoBackupPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate updates a SQL Pool geo backup policy. 36// Parameters: 37// resourceGroupName - the name of the resource group. The name is case insensitive. 38// workspaceName - the name of the workspace 39// SQLPoolName - SQL pool name 40// parameters - the required parameters for creating or updating the geo backup policy. 41func (client SQLPoolGeoBackupPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters GeoBackupPolicy) (result GeoBackupPolicy, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolGeoBackupPoliciesClient.CreateOrUpdate") 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: client.SubscriptionID, 54 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 55 {TargetValue: resourceGroupName, 56 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 57 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 59 {TargetValue: parameters, 60 Constraints: []validation.Constraint{{Target: "parameters.GeoBackupPolicyProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 61 return result, validation.NewError("synapse.SQLPoolGeoBackupPoliciesClient", "CreateOrUpdate", err.Error()) 62 } 63 64 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, parameters) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.CreateOrUpdateSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "CreateOrUpdate", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.CreateOrUpdateResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 87func (client SQLPoolGeoBackupPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters GeoBackupPolicy) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "geoBackupPolicyName": autorest.Encode("path", "Default"), 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "sqlPoolName": autorest.Encode("path", SQLPoolName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 "workspaceName": autorest.Encode("path", workspaceName), 94 } 95 96 const APIVersion = "2021-03-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 parameters.Kind = nil 102 parameters.Location = nil 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/geoBackupPolicies/{geoBackupPolicyName}", pathParameters), 108 autorest.WithJSON(parameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 114// http.Response Body if it receives an error. 115func (client SQLPoolGeoBackupPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 116 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 117} 118 119// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 120// closes the http.Response Body. 121func (client SQLPoolGeoBackupPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result GeoBackupPolicy, err error) { 122 err = autorest.Respond( 123 resp, 124 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 125 autorest.ByUnmarshallingJSON(&result), 126 autorest.ByClosing()) 127 result.Response = autorest.Response{Response: resp} 128 return 129} 130 131// Get get the specified SQL pool geo backup policy 132// Parameters: 133// resourceGroupName - the name of the resource group. The name is case insensitive. 134// workspaceName - the name of the workspace 135// SQLPoolName - SQL pool name 136func (client SQLPoolGeoBackupPoliciesClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result GeoBackupPolicy, err error) { 137 if tracing.IsEnabled() { 138 ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolGeoBackupPoliciesClient.Get") 139 defer func() { 140 sc := -1 141 if result.Response.Response != nil { 142 sc = result.Response.Response.StatusCode 143 } 144 tracing.EndSpan(ctx, sc, err) 145 }() 146 } 147 if err := validation.Validate([]validation.Validation{ 148 {TargetValue: client.SubscriptionID, 149 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 150 {TargetValue: resourceGroupName, 151 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 152 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 153 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 154 return result, validation.NewError("synapse.SQLPoolGeoBackupPoliciesClient", "Get", err.Error()) 155 } 156 157 req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "Get", nil, "Failure preparing request") 160 return 161 } 162 163 resp, err := client.GetSender(req) 164 if err != nil { 165 result.Response = autorest.Response{Response: resp} 166 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "Get", resp, "Failure sending request") 167 return 168 } 169 170 result, err = client.GetResponder(resp) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "Get", resp, "Failure responding to request") 173 return 174 } 175 176 return 177} 178 179// GetPreparer prepares the Get request. 180func (client SQLPoolGeoBackupPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (*http.Request, error) { 181 pathParameters := map[string]interface{}{ 182 "geoBackupPolicyName": autorest.Encode("path", "Default"), 183 "resourceGroupName": autorest.Encode("path", resourceGroupName), 184 "sqlPoolName": autorest.Encode("path", SQLPoolName), 185 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 186 "workspaceName": autorest.Encode("path", workspaceName), 187 } 188 189 const APIVersion = "2021-03-01" 190 queryParameters := map[string]interface{}{ 191 "api-version": APIVersion, 192 } 193 194 preparer := autorest.CreatePreparer( 195 autorest.AsGet(), 196 autorest.WithBaseURL(client.BaseURI), 197 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/geoBackupPolicies/{geoBackupPolicyName}", pathParameters), 198 autorest.WithQueryParameters(queryParameters)) 199 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 200} 201 202// GetSender sends the Get request. The method will close the 203// http.Response Body if it receives an error. 204func (client SQLPoolGeoBackupPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 205 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 206} 207 208// GetResponder handles the response to the Get request. The method always 209// closes the http.Response Body. 210func (client SQLPoolGeoBackupPoliciesClient) GetResponder(resp *http.Response) (result GeoBackupPolicy, err error) { 211 err = autorest.Respond( 212 resp, 213 azure.WithErrorUnlessStatusCode(http.StatusOK), 214 autorest.ByUnmarshallingJSON(&result), 215 autorest.ByClosing()) 216 result.Response = autorest.Response{Response: resp} 217 return 218} 219 220// List get list of SQL pool geo backup policies 221// Parameters: 222// resourceGroupName - the name of the resource group. The name is case insensitive. 223// workspaceName - the name of the workspace 224// SQLPoolName - SQL pool name 225func (client SQLPoolGeoBackupPoliciesClient) List(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result GeoBackupPolicyListResult, err error) { 226 if tracing.IsEnabled() { 227 ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolGeoBackupPoliciesClient.List") 228 defer func() { 229 sc := -1 230 if result.Response.Response != nil { 231 sc = result.Response.Response.StatusCode 232 } 233 tracing.EndSpan(ctx, sc, err) 234 }() 235 } 236 if err := validation.Validate([]validation.Validation{ 237 {TargetValue: client.SubscriptionID, 238 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 239 {TargetValue: resourceGroupName, 240 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 241 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 242 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 243 return result, validation.NewError("synapse.SQLPoolGeoBackupPoliciesClient", "List", err.Error()) 244 } 245 246 req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "List", nil, "Failure preparing request") 249 return 250 } 251 252 resp, err := client.ListSender(req) 253 if err != nil { 254 result.Response = autorest.Response{Response: resp} 255 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "List", resp, "Failure sending request") 256 return 257 } 258 259 result, err = client.ListResponder(resp) 260 if err != nil { 261 err = autorest.NewErrorWithError(err, "synapse.SQLPoolGeoBackupPoliciesClient", "List", resp, "Failure responding to request") 262 return 263 } 264 265 return 266} 267 268// ListPreparer prepares the List request. 269func (client SQLPoolGeoBackupPoliciesClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (*http.Request, error) { 270 pathParameters := map[string]interface{}{ 271 "resourceGroupName": autorest.Encode("path", resourceGroupName), 272 "sqlPoolName": autorest.Encode("path", SQLPoolName), 273 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 274 "workspaceName": autorest.Encode("path", workspaceName), 275 } 276 277 const APIVersion = "2021-03-01" 278 queryParameters := map[string]interface{}{ 279 "api-version": APIVersion, 280 } 281 282 preparer := autorest.CreatePreparer( 283 autorest.AsGet(), 284 autorest.WithBaseURL(client.BaseURI), 285 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/geoBackupPolicies", pathParameters), 286 autorest.WithQueryParameters(queryParameters)) 287 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 288} 289 290// ListSender sends the List request. The method will close the 291// http.Response Body if it receives an error. 292func (client SQLPoolGeoBackupPoliciesClient) ListSender(req *http.Request) (*http.Response, error) { 293 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 294} 295 296// ListResponder handles the response to the List request. The method always 297// closes the http.Response Body. 298func (client SQLPoolGeoBackupPoliciesClient) ListResponder(resp *http.Response) (result GeoBackupPolicyListResult, err error) { 299 err = autorest.Respond( 300 resp, 301 azure.WithErrorUnlessStatusCode(http.StatusOK), 302 autorest.ByUnmarshallingJSON(&result), 303 autorest.ByClosing()) 304 result.Response = autorest.Response{Response: resp} 305 return 306} 307