...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2020-07-01-preview/mysqlflexibleservers/configurations.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  // ConfigurationsClient is the the Microsoft Azure management API provides create, read, update, and delete
    19  // functionality for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and
    20  // configurations with new business model.
    21  type ConfigurationsClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewConfigurationsClient creates an instance of the ConfigurationsClient client.
    26  func NewConfigurationsClient(subscriptionID string) ConfigurationsClient {
    27  	return NewConfigurationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewConfigurationsClientWithBaseURI creates an instance of the ConfigurationsClient client using a custom endpoint.
    31  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    32  func NewConfigurationsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationsClient {
    33  	return ConfigurationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // Get gets information about a configuration of server.
    37  // Parameters:
    38  // resourceGroupName - the name of the resource group. The name is case insensitive.
    39  // serverName - the name of the server.
    40  // configurationName - the name of the server configuration.
    41  func (client ConfigurationsClient) Get(ctx context.Context, resourceGroupName string, serverName string, configurationName string) (result Configuration, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationsClient.Get")
    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}}}}); err != nil {
    59  		return result, validation.NewError("mysqlflexibleservers.ConfigurationsClient", "Get", err.Error())
    60  	}
    61  
    62  	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, configurationName)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "Get", nil, "Failure preparing request")
    65  		return
    66  	}
    67  
    68  	resp, err := client.GetSender(req)
    69  	if err != nil {
    70  		result.Response = autorest.Response{Response: resp}
    71  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "Get", resp, "Failure sending request")
    72  		return
    73  	}
    74  
    75  	result, err = client.GetResponder(resp)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "Get", resp, "Failure responding to request")
    78  		return
    79  	}
    80  
    81  	return
    82  }
    83  
    84  // GetPreparer prepares the Get request.
    85  func (client ConfigurationsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, configurationName string) (*http.Request, error) {
    86  	pathParameters := map[string]interface{}{
    87  		"configurationName": autorest.Encode("path", configurationName),
    88  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    89  		"serverName":        autorest.Encode("path", serverName),
    90  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    91  	}
    92  
    93  	const APIVersion = "2020-07-01-preview"
    94  	queryParameters := map[string]interface{}{
    95  		"api-version": APIVersion,
    96  	}
    97  
    98  	preparer := autorest.CreatePreparer(
    99  		autorest.AsGet(),
   100  		autorest.WithBaseURL(client.BaseURI),
   101  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/configurations/{configurationName}", pathParameters),
   102  		autorest.WithQueryParameters(queryParameters))
   103  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   104  }
   105  
   106  // GetSender sends the Get request. The method will close the
   107  // http.Response Body if it receives an error.
   108  func (client ConfigurationsClient) GetSender(req *http.Request) (*http.Response, error) {
   109  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   110  }
   111  
   112  // GetResponder handles the response to the Get request. The method always
   113  // closes the http.Response Body.
   114  func (client ConfigurationsClient) GetResponder(resp *http.Response) (result Configuration, err error) {
   115  	err = autorest.Respond(
   116  		resp,
   117  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   118  		autorest.ByUnmarshallingJSON(&result),
   119  		autorest.ByClosing())
   120  	result.Response = autorest.Response{Response: resp}
   121  	return
   122  }
   123  
   124  // ListByServer list all the configurations in a given server.
   125  // Parameters:
   126  // resourceGroupName - the name of the resource group. The name is case insensitive.
   127  // serverName - the name of the server.
   128  func (client ConfigurationsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ConfigurationListResultPage, err error) {
   129  	if tracing.IsEnabled() {
   130  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationsClient.ListByServer")
   131  		defer func() {
   132  			sc := -1
   133  			if result.clr.Response.Response != nil {
   134  				sc = result.clr.Response.Response.StatusCode
   135  			}
   136  			tracing.EndSpan(ctx, sc, err)
   137  		}()
   138  	}
   139  	if err := validation.Validate([]validation.Validation{
   140  		{TargetValue: client.SubscriptionID,
   141  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   142  		{TargetValue: resourceGroupName,
   143  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   144  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   145  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   146  		return result, validation.NewError("mysqlflexibleservers.ConfigurationsClient", "ListByServer", err.Error())
   147  	}
   148  
   149  	result.fn = client.listByServerNextResults
   150  	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "ListByServer", nil, "Failure preparing request")
   153  		return
   154  	}
   155  
   156  	resp, err := client.ListByServerSender(req)
   157  	if err != nil {
   158  		result.clr.Response = autorest.Response{Response: resp}
   159  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "ListByServer", resp, "Failure sending request")
   160  		return
   161  	}
   162  
   163  	result.clr, err = client.ListByServerResponder(resp)
   164  	if err != nil {
   165  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "ListByServer", resp, "Failure responding to request")
   166  		return
   167  	}
   168  	if result.clr.hasNextLink() && result.clr.IsEmpty() {
   169  		err = result.NextWithContext(ctx)
   170  		return
   171  	}
   172  
   173  	return
   174  }
   175  
   176  // ListByServerPreparer prepares the ListByServer request.
   177  func (client ConfigurationsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   178  	pathParameters := map[string]interface{}{
   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.AsGet(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/configurations", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // ListByServerSender sends the ListByServer request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client ConfigurationsClient) ListByServerSender(req *http.Request) (*http.Response, error) {
   200  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   201  }
   202  
   203  // ListByServerResponder handles the response to the ListByServer request. The method always
   204  // closes the http.Response Body.
   205  func (client ConfigurationsClient) ListByServerResponder(resp *http.Response) (result ConfigurationListResult, err error) {
   206  	err = autorest.Respond(
   207  		resp,
   208  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   209  		autorest.ByUnmarshallingJSON(&result),
   210  		autorest.ByClosing())
   211  	result.Response = autorest.Response{Response: resp}
   212  	return
   213  }
   214  
   215  // listByServerNextResults retrieves the next set of results, if any.
   216  func (client ConfigurationsClient) listByServerNextResults(ctx context.Context, lastResults ConfigurationListResult) (result ConfigurationListResult, err error) {
   217  	req, err := lastResults.configurationListResultPreparer(ctx)
   218  	if err != nil {
   219  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "listByServerNextResults", nil, "Failure preparing next results request")
   220  	}
   221  	if req == nil {
   222  		return
   223  	}
   224  	resp, err := client.ListByServerSender(req)
   225  	if err != nil {
   226  		result.Response = autorest.Response{Response: resp}
   227  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "listByServerNextResults", resp, "Failure sending next results request")
   228  	}
   229  	result, err = client.ListByServerResponder(resp)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "listByServerNextResults", resp, "Failure responding to next results request")
   232  	}
   233  	return
   234  }
   235  
   236  // ListByServerComplete enumerates all values, automatically crossing page boundaries as required.
   237  func (client ConfigurationsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result ConfigurationListResultIterator, err error) {
   238  	if tracing.IsEnabled() {
   239  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationsClient.ListByServer")
   240  		defer func() {
   241  			sc := -1
   242  			if result.Response().Response.Response != nil {
   243  				sc = result.page.Response().Response.Response.StatusCode
   244  			}
   245  			tracing.EndSpan(ctx, sc, err)
   246  		}()
   247  	}
   248  	result.page, err = client.ListByServer(ctx, resourceGroupName, serverName)
   249  	return
   250  }
   251  
   252  // Update updates a configuration of a server.
   253  // Parameters:
   254  // resourceGroupName - the name of the resource group. The name is case insensitive.
   255  // serverName - the name of the server.
   256  // configurationName - the name of the server configuration.
   257  // parameters - the required parameters for updating a server configuration.
   258  func (client ConfigurationsClient) Update(ctx context.Context, resourceGroupName string, serverName string, configurationName string, parameters Configuration) (result ConfigurationsUpdateFuture, err error) {
   259  	if tracing.IsEnabled() {
   260  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationsClient.Update")
   261  		defer func() {
   262  			sc := -1
   263  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   264  				sc = result.FutureAPI.Response().StatusCode
   265  			}
   266  			tracing.EndSpan(ctx, sc, err)
   267  		}()
   268  	}
   269  	if err := validation.Validate([]validation.Validation{
   270  		{TargetValue: client.SubscriptionID,
   271  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   272  		{TargetValue: resourceGroupName,
   273  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   274  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   275  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   276  		return result, validation.NewError("mysqlflexibleservers.ConfigurationsClient", "Update", err.Error())
   277  	}
   278  
   279  	req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, configurationName, parameters)
   280  	if err != nil {
   281  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "Update", nil, "Failure preparing request")
   282  		return
   283  	}
   284  
   285  	result, err = client.UpdateSender(req)
   286  	if err != nil {
   287  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ConfigurationsClient", "Update", result.Response(), "Failure sending request")
   288  		return
   289  	}
   290  
   291  	return
   292  }
   293  
   294  // UpdatePreparer prepares the Update request.
   295  func (client ConfigurationsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, configurationName string, parameters Configuration) (*http.Request, error) {
   296  	pathParameters := map[string]interface{}{
   297  		"configurationName": autorest.Encode("path", configurationName),
   298  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   299  		"serverName":        autorest.Encode("path", serverName),
   300  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   301  	}
   302  
   303  	const APIVersion = "2020-07-01-preview"
   304  	queryParameters := map[string]interface{}{
   305  		"api-version": APIVersion,
   306  	}
   307  
   308  	preparer := autorest.CreatePreparer(
   309  		autorest.AsContentType("application/json; charset=utf-8"),
   310  		autorest.AsPatch(),
   311  		autorest.WithBaseURL(client.BaseURI),
   312  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/configurations/{configurationName}", pathParameters),
   313  		autorest.WithJSON(parameters),
   314  		autorest.WithQueryParameters(queryParameters))
   315  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   316  }
   317  
   318  // UpdateSender sends the Update request. The method will close the
   319  // http.Response Body if it receives an error.
   320  func (client ConfigurationsClient) UpdateSender(req *http.Request) (future ConfigurationsUpdateFuture, err error) {
   321  	var resp *http.Response
   322  	future.FutureAPI = &azure.Future{}
   323  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   324  	if err != nil {
   325  		return
   326  	}
   327  	var azf azure.Future
   328  	azf, err = azure.NewFutureFromResponse(resp)
   329  	future.FutureAPI = &azf
   330  	future.Result = future.result
   331  	return
   332  }
   333  
   334  // UpdateResponder handles the response to the Update request. The method always
   335  // closes the http.Response Body.
   336  func (client ConfigurationsClient) UpdateResponder(resp *http.Response) (result Configuration, err error) {
   337  	err = autorest.Respond(
   338  		resp,
   339  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   340  		autorest.ByUnmarshallingJSON(&result),
   341  		autorest.ByClosing())
   342  	result.Response = autorest.Response{Response: resp}
   343  	return
   344  }
   345  

View as plain text