...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2020-07-01-preview/mysqlflexibleservers/serverkeys.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2020-07-01-preview/mysqlflexibleservers

     1  package mysqlflexibleservers
     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  
     9  import (
    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  // ServerKeysClient is the the Microsoft Azure management API provides create, read, update, and delete functionality
    19  // for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and configurations
    20  // with new business model.
    21  type ServerKeysClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewServerKeysClient creates an instance of the ServerKeysClient client.
    26  func NewServerKeysClient(subscriptionID string) ServerKeysClient {
    27  	return NewServerKeysClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewServerKeysClientWithBaseURI creates an instance of the ServerKeysClient client using a custom endpoint.  Use this
    31  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    32  func NewServerKeysClientWithBaseURI(baseURI string, subscriptionID string) ServerKeysClient {
    33  	return ServerKeysClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // CreateOrUpdate creates or updates a MySQL Server key.
    37  // Parameters:
    38  // resourceGroupName - the name of the resource group. The name is case insensitive.
    39  // serverName - the name of the server.
    40  // keyName - the name of the server key.
    41  // parameters - the requested MySQL Server key resource state.
    42  func (client ServerKeysClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, keyName string, parameters ServerKey) (result ServerKeysCreateOrUpdateFuture, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/ServerKeysClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    48  				sc = result.FutureAPI.Response().StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: client.SubscriptionID,
    55  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    56  		{TargetValue: resourceGroupName,
    57  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    58  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    59  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    60  		{TargetValue: parameters,
    61  			Constraints: []validation.Constraint{{Target: "parameters.ServerKeyProperties", Name: validation.Null, Rule: false,
    62  				Chain: []validation.Constraint{{Target: "parameters.ServerKeyProperties.ServerKeyType", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    63  		return result, validation.NewError("mysqlflexibleservers.ServerKeysClient", "CreateOrUpdate", err.Error())
    64  	}
    65  
    66  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, keyName, parameters)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "CreateOrUpdate", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	result, err = client.CreateOrUpdateSender(req)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    82  func (client ServerKeysClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, keyName string, parameters ServerKey) (*http.Request, error) {
    83  	pathParameters := map[string]interface{}{
    84  		"keyName":           autorest.Encode("path", keyName),
    85  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    86  		"serverName":        autorest.Encode("path", serverName),
    87  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2020-07-01-preview"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	parameters.Kind = nil
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsContentType("application/json; charset=utf-8"),
    98  		autorest.AsPut(),
    99  		autorest.WithBaseURL(client.BaseURI),
   100  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/keys/{keyName}", pathParameters),
   101  		autorest.WithJSON(parameters),
   102  		autorest.WithQueryParameters(queryParameters))
   103  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   104  }
   105  
   106  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   107  // http.Response Body if it receives an error.
   108  func (client ServerKeysClient) CreateOrUpdateSender(req *http.Request) (future ServerKeysCreateOrUpdateFuture, err error) {
   109  	var resp *http.Response
   110  	future.FutureAPI = &azure.Future{}
   111  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   112  	if err != nil {
   113  		return
   114  	}
   115  	var azf azure.Future
   116  	azf, err = azure.NewFutureFromResponse(resp)
   117  	future.FutureAPI = &azf
   118  	future.Result = future.result
   119  	return
   120  }
   121  
   122  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   123  // closes the http.Response Body.
   124  func (client ServerKeysClient) CreateOrUpdateResponder(resp *http.Response) (result ServerKey, err error) {
   125  	err = autorest.Respond(
   126  		resp,
   127  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
   128  		autorest.ByUnmarshallingJSON(&result),
   129  		autorest.ByClosing())
   130  	result.Response = autorest.Response{Response: resp}
   131  	return
   132  }
   133  
   134  // Delete deletes the MySQL Server key with the given name.
   135  // Parameters:
   136  // resourceGroupName - the name of the resource group. The name is case insensitive.
   137  // serverName - the name of the server.
   138  // keyName - the name of the server key.
   139  func (client ServerKeysClient) Delete(ctx context.Context, resourceGroupName string, serverName string, keyName string) (result ServerKeysDeleteFuture, err error) {
   140  	if tracing.IsEnabled() {
   141  		ctx = tracing.StartSpan(ctx, fqdn+"/ServerKeysClient.Delete")
   142  		defer func() {
   143  			sc := -1
   144  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   145  				sc = result.FutureAPI.Response().StatusCode
   146  			}
   147  			tracing.EndSpan(ctx, sc, err)
   148  		}()
   149  	}
   150  	if err := validation.Validate([]validation.Validation{
   151  		{TargetValue: client.SubscriptionID,
   152  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   153  		{TargetValue: resourceGroupName,
   154  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   155  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   156  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   157  		return result, validation.NewError("mysqlflexibleservers.ServerKeysClient", "Delete", err.Error())
   158  	}
   159  
   160  	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, keyName)
   161  	if err != nil {
   162  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "Delete", nil, "Failure preparing request")
   163  		return
   164  	}
   165  
   166  	result, err = client.DeleteSender(req)
   167  	if err != nil {
   168  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "Delete", result.Response(), "Failure sending request")
   169  		return
   170  	}
   171  
   172  	return
   173  }
   174  
   175  // DeletePreparer prepares the Delete request.
   176  func (client ServerKeysClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, keyName string) (*http.Request, error) {
   177  	pathParameters := map[string]interface{}{
   178  		"keyName":           autorest.Encode("path", keyName),
   179  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   180  		"serverName":        autorest.Encode("path", serverName),
   181  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   182  	}
   183  
   184  	const APIVersion = "2020-07-01-preview"
   185  	queryParameters := map[string]interface{}{
   186  		"api-version": APIVersion,
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsDelete(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/keys/{keyName}", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // DeleteSender sends the Delete request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client ServerKeysClient) DeleteSender(req *http.Request) (future ServerKeysDeleteFuture, err error) {
   200  	var resp *http.Response
   201  	future.FutureAPI = &azure.Future{}
   202  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   203  	if err != nil {
   204  		return
   205  	}
   206  	var azf azure.Future
   207  	azf, err = azure.NewFutureFromResponse(resp)
   208  	future.FutureAPI = &azf
   209  	future.Result = future.result
   210  	return
   211  }
   212  
   213  // DeleteResponder handles the response to the Delete request. The method always
   214  // closes the http.Response Body.
   215  func (client ServerKeysClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   216  	err = autorest.Respond(
   217  		resp,
   218  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   219  		autorest.ByClosing())
   220  	result.Response = resp
   221  	return
   222  }
   223  
   224  // Get gets a server key.
   225  // Parameters:
   226  // resourceGroupName - the name of the resource group. The name is case insensitive.
   227  // serverName - the name of the server.
   228  // keyName - the name of the server key.
   229  func (client ServerKeysClient) Get(ctx context.Context, resourceGroupName string, serverName string, keyName string) (result ServerKey, err error) {
   230  	if tracing.IsEnabled() {
   231  		ctx = tracing.StartSpan(ctx, fqdn+"/ServerKeysClient.Get")
   232  		defer func() {
   233  			sc := -1
   234  			if result.Response.Response != nil {
   235  				sc = result.Response.Response.StatusCode
   236  			}
   237  			tracing.EndSpan(ctx, sc, err)
   238  		}()
   239  	}
   240  	if err := validation.Validate([]validation.Validation{
   241  		{TargetValue: client.SubscriptionID,
   242  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   243  		{TargetValue: resourceGroupName,
   244  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   245  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   246  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   247  		return result, validation.NewError("mysqlflexibleservers.ServerKeysClient", "Get", err.Error())
   248  	}
   249  
   250  	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, keyName)
   251  	if err != nil {
   252  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "Get", nil, "Failure preparing request")
   253  		return
   254  	}
   255  
   256  	resp, err := client.GetSender(req)
   257  	if err != nil {
   258  		result.Response = autorest.Response{Response: resp}
   259  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "Get", resp, "Failure sending request")
   260  		return
   261  	}
   262  
   263  	result, err = client.GetResponder(resp)
   264  	if err != nil {
   265  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "Get", resp, "Failure responding to request")
   266  		return
   267  	}
   268  
   269  	return
   270  }
   271  
   272  // GetPreparer prepares the Get request.
   273  func (client ServerKeysClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, keyName string) (*http.Request, error) {
   274  	pathParameters := map[string]interface{}{
   275  		"keyName":           autorest.Encode("path", keyName),
   276  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   277  		"serverName":        autorest.Encode("path", serverName),
   278  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   279  	}
   280  
   281  	const APIVersion = "2020-07-01-preview"
   282  	queryParameters := map[string]interface{}{
   283  		"api-version": APIVersion,
   284  	}
   285  
   286  	preparer := autorest.CreatePreparer(
   287  		autorest.AsGet(),
   288  		autorest.WithBaseURL(client.BaseURI),
   289  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/keys/{keyName}", pathParameters),
   290  		autorest.WithQueryParameters(queryParameters))
   291  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   292  }
   293  
   294  // GetSender sends the Get request. The method will close the
   295  // http.Response Body if it receives an error.
   296  func (client ServerKeysClient) GetSender(req *http.Request) (*http.Response, error) {
   297  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   298  }
   299  
   300  // GetResponder handles the response to the Get request. The method always
   301  // closes the http.Response Body.
   302  func (client ServerKeysClient) GetResponder(resp *http.Response) (result ServerKey, err error) {
   303  	err = autorest.Respond(
   304  		resp,
   305  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   306  		autorest.ByUnmarshallingJSON(&result),
   307  		autorest.ByClosing())
   308  	result.Response = autorest.Response{Response: resp}
   309  	return
   310  }
   311  
   312  // ListByServer gets a list of  Server keys.
   313  // Parameters:
   314  // resourceGroupName - the name of the resource group. The name is case insensitive.
   315  // serverName - the name of the server.
   316  func (client ServerKeysClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerKeyListResultPage, err error) {
   317  	if tracing.IsEnabled() {
   318  		ctx = tracing.StartSpan(ctx, fqdn+"/ServerKeysClient.ListByServer")
   319  		defer func() {
   320  			sc := -1
   321  			if result.sklr.Response.Response != nil {
   322  				sc = result.sklr.Response.Response.StatusCode
   323  			}
   324  			tracing.EndSpan(ctx, sc, err)
   325  		}()
   326  	}
   327  	if err := validation.Validate([]validation.Validation{
   328  		{TargetValue: client.SubscriptionID,
   329  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   330  		{TargetValue: resourceGroupName,
   331  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   332  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   333  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   334  		return result, validation.NewError("mysqlflexibleservers.ServerKeysClient", "ListByServer", err.Error())
   335  	}
   336  
   337  	result.fn = client.listByServerNextResults
   338  	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
   339  	if err != nil {
   340  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "ListByServer", nil, "Failure preparing request")
   341  		return
   342  	}
   343  
   344  	resp, err := client.ListByServerSender(req)
   345  	if err != nil {
   346  		result.sklr.Response = autorest.Response{Response: resp}
   347  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "ListByServer", resp, "Failure sending request")
   348  		return
   349  	}
   350  
   351  	result.sklr, err = client.ListByServerResponder(resp)
   352  	if err != nil {
   353  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "ListByServer", resp, "Failure responding to request")
   354  		return
   355  	}
   356  	if result.sklr.hasNextLink() && result.sklr.IsEmpty() {
   357  		err = result.NextWithContext(ctx)
   358  		return
   359  	}
   360  
   361  	return
   362  }
   363  
   364  // ListByServerPreparer prepares the ListByServer request.
   365  func (client ServerKeysClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   366  	pathParameters := map[string]interface{}{
   367  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   368  		"serverName":        autorest.Encode("path", serverName),
   369  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   370  	}
   371  
   372  	const APIVersion = "2020-07-01-preview"
   373  	queryParameters := map[string]interface{}{
   374  		"api-version": APIVersion,
   375  	}
   376  
   377  	preparer := autorest.CreatePreparer(
   378  		autorest.AsGet(),
   379  		autorest.WithBaseURL(client.BaseURI),
   380  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/keys", pathParameters),
   381  		autorest.WithQueryParameters(queryParameters))
   382  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   383  }
   384  
   385  // ListByServerSender sends the ListByServer request. The method will close the
   386  // http.Response Body if it receives an error.
   387  func (client ServerKeysClient) ListByServerSender(req *http.Request) (*http.Response, error) {
   388  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   389  }
   390  
   391  // ListByServerResponder handles the response to the ListByServer request. The method always
   392  // closes the http.Response Body.
   393  func (client ServerKeysClient) ListByServerResponder(resp *http.Response) (result ServerKeyListResult, err error) {
   394  	err = autorest.Respond(
   395  		resp,
   396  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   397  		autorest.ByUnmarshallingJSON(&result),
   398  		autorest.ByClosing())
   399  	result.Response = autorest.Response{Response: resp}
   400  	return
   401  }
   402  
   403  // listByServerNextResults retrieves the next set of results, if any.
   404  func (client ServerKeysClient) listByServerNextResults(ctx context.Context, lastResults ServerKeyListResult) (result ServerKeyListResult, err error) {
   405  	req, err := lastResults.serverKeyListResultPreparer(ctx)
   406  	if err != nil {
   407  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "listByServerNextResults", nil, "Failure preparing next results request")
   408  	}
   409  	if req == nil {
   410  		return
   411  	}
   412  	resp, err := client.ListByServerSender(req)
   413  	if err != nil {
   414  		result.Response = autorest.Response{Response: resp}
   415  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "listByServerNextResults", resp, "Failure sending next results request")
   416  	}
   417  	result, err = client.ListByServerResponder(resp)
   418  	if err != nil {
   419  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ServerKeysClient", "listByServerNextResults", resp, "Failure responding to next results request")
   420  	}
   421  	return
   422  }
   423  
   424  // ListByServerComplete enumerates all values, automatically crossing page boundaries as required.
   425  func (client ServerKeysClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result ServerKeyListResultIterator, err error) {
   426  	if tracing.IsEnabled() {
   427  		ctx = tracing.StartSpan(ctx, fqdn+"/ServerKeysClient.ListByServer")
   428  		defer func() {
   429  			sc := -1
   430  			if result.Response().Response.Response != nil {
   431  				sc = result.page.Response().Response.Response.StatusCode
   432  			}
   433  			tracing.EndSpan(ctx, sc, err)
   434  		}()
   435  	}
   436  	result.page, err = client.ListByServer(ctx, resourceGroupName, serverName)
   437  	return
   438  }
   439  

View as plain text