...

Source file src/github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement/cache.go

Documentation: github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement

     1  package apimanagement
     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  // CacheClient is the apiManagement Client
    19  type CacheClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewCacheClient creates an instance of the CacheClient client.
    24  func NewCacheClient(subscriptionID string) CacheClient {
    25  	return NewCacheClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewCacheClientWithBaseURI creates an instance of the CacheClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewCacheClientWithBaseURI(baseURI string, subscriptionID string) CacheClient {
    31  	return CacheClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates an External Cache to be used in Api Management instance.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // serviceName - the name of the API Management service.
    38  // cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
    39  // identifier).
    40  // parameters - create or Update parameters.
    41  // ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
    42  func (client CacheClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheContract, ifMatch string) (result CacheContract, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: serviceName,
    55  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    56  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
    57  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
    58  		{TargetValue: cacheID,
    59  			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
    60  				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
    61  				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
    62  		{TargetValue: parameters,
    63  			Constraints: []validation.Constraint{{Target: "parameters.CacheContractProperties", Name: validation.Null, Rule: false,
    64  				Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.Description", Name: validation.Null, Rule: false,
    65  					Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.Description", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
    66  					{Target: "parameters.CacheContractProperties.ConnectionString", Name: validation.Null, Rule: true,
    67  						Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.ConnectionString", Name: validation.MaxLength, Rule: 300, Chain: nil}}},
    68  					{Target: "parameters.CacheContractProperties.UseFromLocation", Name: validation.Null, Rule: true,
    69  						Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.UseFromLocation", Name: validation.MaxLength, Rule: 256, Chain: nil}}},
    70  					{Target: "parameters.CacheContractProperties.ResourceID", Name: validation.Null, Rule: false,
    71  						Chain: []validation.Constraint{{Target: "parameters.CacheContractProperties.ResourceID", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
    72  				}}}}}); err != nil {
    73  		return result, validation.NewError("apimanagement.CacheClient", "CreateOrUpdate", err.Error())
    74  	}
    75  
    76  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, cacheID, parameters, ifMatch)
    77  	if err != nil {
    78  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", nil, "Failure preparing request")
    79  		return
    80  	}
    81  
    82  	resp, err := client.CreateOrUpdateSender(req)
    83  	if err != nil {
    84  		result.Response = autorest.Response{Response: resp}
    85  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", resp, "Failure sending request")
    86  		return
    87  	}
    88  
    89  	result, err = client.CreateOrUpdateResponder(resp)
    90  	if err != nil {
    91  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "CreateOrUpdate", resp, "Failure responding to request")
    92  		return
    93  	}
    94  
    95  	return
    96  }
    97  
    98  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    99  func (client CacheClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheContract, ifMatch string) (*http.Request, error) {
   100  	pathParameters := map[string]interface{}{
   101  		"cacheId":           autorest.Encode("path", cacheID),
   102  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   103  		"serviceName":       autorest.Encode("path", serviceName),
   104  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   105  	}
   106  
   107  	const APIVersion = "2020-12-01"
   108  	queryParameters := map[string]interface{}{
   109  		"api-version": APIVersion,
   110  	}
   111  
   112  	preparer := autorest.CreatePreparer(
   113  		autorest.AsContentType("application/json; charset=utf-8"),
   114  		autorest.AsPut(),
   115  		autorest.WithBaseURL(client.BaseURI),
   116  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
   117  		autorest.WithJSON(parameters),
   118  		autorest.WithQueryParameters(queryParameters))
   119  	if len(ifMatch) > 0 {
   120  		preparer = autorest.DecoratePreparer(preparer,
   121  			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   122  	}
   123  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   124  }
   125  
   126  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   127  // http.Response Body if it receives an error.
   128  func (client CacheClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   129  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   130  }
   131  
   132  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   133  // closes the http.Response Body.
   134  func (client CacheClient) CreateOrUpdateResponder(resp *http.Response) (result CacheContract, err error) {
   135  	err = autorest.Respond(
   136  		resp,
   137  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   138  		autorest.ByUnmarshallingJSON(&result),
   139  		autorest.ByClosing())
   140  	result.Response = autorest.Response{Response: resp}
   141  	return
   142  }
   143  
   144  // Delete deletes specific Cache.
   145  // Parameters:
   146  // resourceGroupName - the name of the resource group.
   147  // serviceName - the name of the API Management service.
   148  // cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
   149  // identifier).
   150  // ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
   151  // request or it should be * for unconditional update.
   152  func (client CacheClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, ifMatch string) (result autorest.Response, err error) {
   153  	if tracing.IsEnabled() {
   154  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Delete")
   155  		defer func() {
   156  			sc := -1
   157  			if result.Response != nil {
   158  				sc = result.Response.StatusCode
   159  			}
   160  			tracing.EndSpan(ctx, sc, err)
   161  		}()
   162  	}
   163  	if err := validation.Validate([]validation.Validation{
   164  		{TargetValue: serviceName,
   165  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   166  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
   167  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
   168  		{TargetValue: cacheID,
   169  			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
   170  				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
   171  				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
   172  		return result, validation.NewError("apimanagement.CacheClient", "Delete", err.Error())
   173  	}
   174  
   175  	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, cacheID, ifMatch)
   176  	if err != nil {
   177  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", nil, "Failure preparing request")
   178  		return
   179  	}
   180  
   181  	resp, err := client.DeleteSender(req)
   182  	if err != nil {
   183  		result.Response = resp
   184  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", resp, "Failure sending request")
   185  		return
   186  	}
   187  
   188  	result, err = client.DeleteResponder(resp)
   189  	if err != nil {
   190  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Delete", resp, "Failure responding to request")
   191  		return
   192  	}
   193  
   194  	return
   195  }
   196  
   197  // DeletePreparer prepares the Delete request.
   198  func (client CacheClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, ifMatch string) (*http.Request, error) {
   199  	pathParameters := map[string]interface{}{
   200  		"cacheId":           autorest.Encode("path", cacheID),
   201  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   202  		"serviceName":       autorest.Encode("path", serviceName),
   203  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   204  	}
   205  
   206  	const APIVersion = "2020-12-01"
   207  	queryParameters := map[string]interface{}{
   208  		"api-version": APIVersion,
   209  	}
   210  
   211  	preparer := autorest.CreatePreparer(
   212  		autorest.AsDelete(),
   213  		autorest.WithBaseURL(client.BaseURI),
   214  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
   215  		autorest.WithQueryParameters(queryParameters),
   216  		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   217  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   218  }
   219  
   220  // DeleteSender sends the Delete request. The method will close the
   221  // http.Response Body if it receives an error.
   222  func (client CacheClient) DeleteSender(req *http.Request) (*http.Response, error) {
   223  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   224  }
   225  
   226  // DeleteResponder handles the response to the Delete request. The method always
   227  // closes the http.Response Body.
   228  func (client CacheClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   229  	err = autorest.Respond(
   230  		resp,
   231  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   232  		autorest.ByClosing())
   233  	result.Response = resp
   234  	return
   235  }
   236  
   237  // Get gets the details of the Cache specified by its identifier.
   238  // Parameters:
   239  // resourceGroupName - the name of the resource group.
   240  // serviceName - the name of the API Management service.
   241  // cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
   242  // identifier).
   243  func (client CacheClient) Get(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (result CacheContract, err error) {
   244  	if tracing.IsEnabled() {
   245  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Get")
   246  		defer func() {
   247  			sc := -1
   248  			if result.Response.Response != nil {
   249  				sc = result.Response.Response.StatusCode
   250  			}
   251  			tracing.EndSpan(ctx, sc, err)
   252  		}()
   253  	}
   254  	if err := validation.Validate([]validation.Validation{
   255  		{TargetValue: serviceName,
   256  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   257  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
   258  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
   259  		{TargetValue: cacheID,
   260  			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
   261  				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
   262  				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
   263  		return result, validation.NewError("apimanagement.CacheClient", "Get", err.Error())
   264  	}
   265  
   266  	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, cacheID)
   267  	if err != nil {
   268  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", nil, "Failure preparing request")
   269  		return
   270  	}
   271  
   272  	resp, err := client.GetSender(req)
   273  	if err != nil {
   274  		result.Response = autorest.Response{Response: resp}
   275  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", resp, "Failure sending request")
   276  		return
   277  	}
   278  
   279  	result, err = client.GetResponder(resp)
   280  	if err != nil {
   281  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Get", resp, "Failure responding to request")
   282  		return
   283  	}
   284  
   285  	return
   286  }
   287  
   288  // GetPreparer prepares the Get request.
   289  func (client CacheClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (*http.Request, error) {
   290  	pathParameters := map[string]interface{}{
   291  		"cacheId":           autorest.Encode("path", cacheID),
   292  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   293  		"serviceName":       autorest.Encode("path", serviceName),
   294  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   295  	}
   296  
   297  	const APIVersion = "2020-12-01"
   298  	queryParameters := map[string]interface{}{
   299  		"api-version": APIVersion,
   300  	}
   301  
   302  	preparer := autorest.CreatePreparer(
   303  		autorest.AsGet(),
   304  		autorest.WithBaseURL(client.BaseURI),
   305  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
   306  		autorest.WithQueryParameters(queryParameters))
   307  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   308  }
   309  
   310  // GetSender sends the Get request. The method will close the
   311  // http.Response Body if it receives an error.
   312  func (client CacheClient) GetSender(req *http.Request) (*http.Response, error) {
   313  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   314  }
   315  
   316  // GetResponder handles the response to the Get request. The method always
   317  // closes the http.Response Body.
   318  func (client CacheClient) GetResponder(resp *http.Response) (result CacheContract, err error) {
   319  	err = autorest.Respond(
   320  		resp,
   321  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   322  		autorest.ByUnmarshallingJSON(&result),
   323  		autorest.ByClosing())
   324  	result.Response = autorest.Response{Response: resp}
   325  	return
   326  }
   327  
   328  // GetEntityTag gets the entity state (Etag) version of the Cache specified by its identifier.
   329  // Parameters:
   330  // resourceGroupName - the name of the resource group.
   331  // serviceName - the name of the API Management service.
   332  // cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
   333  // identifier).
   334  func (client CacheClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (result autorest.Response, err error) {
   335  	if tracing.IsEnabled() {
   336  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.GetEntityTag")
   337  		defer func() {
   338  			sc := -1
   339  			if result.Response != nil {
   340  				sc = result.Response.StatusCode
   341  			}
   342  			tracing.EndSpan(ctx, sc, err)
   343  		}()
   344  	}
   345  	if err := validation.Validate([]validation.Validation{
   346  		{TargetValue: serviceName,
   347  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   348  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
   349  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
   350  		{TargetValue: cacheID,
   351  			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
   352  				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
   353  				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
   354  		return result, validation.NewError("apimanagement.CacheClient", "GetEntityTag", err.Error())
   355  	}
   356  
   357  	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, cacheID)
   358  	if err != nil {
   359  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", nil, "Failure preparing request")
   360  		return
   361  	}
   362  
   363  	resp, err := client.GetEntityTagSender(req)
   364  	if err != nil {
   365  		result.Response = resp
   366  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", resp, "Failure sending request")
   367  		return
   368  	}
   369  
   370  	result, err = client.GetEntityTagResponder(resp)
   371  	if err != nil {
   372  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "GetEntityTag", resp, "Failure responding to request")
   373  		return
   374  	}
   375  
   376  	return
   377  }
   378  
   379  // GetEntityTagPreparer prepares the GetEntityTag request.
   380  func (client CacheClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string) (*http.Request, error) {
   381  	pathParameters := map[string]interface{}{
   382  		"cacheId":           autorest.Encode("path", cacheID),
   383  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   384  		"serviceName":       autorest.Encode("path", serviceName),
   385  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   386  	}
   387  
   388  	const APIVersion = "2020-12-01"
   389  	queryParameters := map[string]interface{}{
   390  		"api-version": APIVersion,
   391  	}
   392  
   393  	preparer := autorest.CreatePreparer(
   394  		autorest.AsHead(),
   395  		autorest.WithBaseURL(client.BaseURI),
   396  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
   397  		autorest.WithQueryParameters(queryParameters))
   398  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   399  }
   400  
   401  // GetEntityTagSender sends the GetEntityTag request. The method will close the
   402  // http.Response Body if it receives an error.
   403  func (client CacheClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
   404  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   405  }
   406  
   407  // GetEntityTagResponder handles the response to the GetEntityTag request. The method always
   408  // closes the http.Response Body.
   409  func (client CacheClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
   410  	err = autorest.Respond(
   411  		resp,
   412  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   413  		autorest.ByClosing())
   414  	result.Response = resp
   415  	return
   416  }
   417  
   418  // ListByService lists a collection of all external Caches in the specified service instance.
   419  // Parameters:
   420  // resourceGroupName - the name of the resource group.
   421  // serviceName - the name of the API Management service.
   422  // top - number of records to return.
   423  // skip - number of records to skip.
   424  func (client CacheClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result CacheCollectionPage, err error) {
   425  	if tracing.IsEnabled() {
   426  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.ListByService")
   427  		defer func() {
   428  			sc := -1
   429  			if result.cc.Response.Response != nil {
   430  				sc = result.cc.Response.Response.StatusCode
   431  			}
   432  			tracing.EndSpan(ctx, sc, err)
   433  		}()
   434  	}
   435  	if err := validation.Validate([]validation.Validation{
   436  		{TargetValue: serviceName,
   437  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   438  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
   439  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
   440  		{TargetValue: top,
   441  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   442  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
   443  		{TargetValue: skip,
   444  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   445  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
   446  		return result, validation.NewError("apimanagement.CacheClient", "ListByService", err.Error())
   447  	}
   448  
   449  	result.fn = client.listByServiceNextResults
   450  	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, top, skip)
   451  	if err != nil {
   452  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", nil, "Failure preparing request")
   453  		return
   454  	}
   455  
   456  	resp, err := client.ListByServiceSender(req)
   457  	if err != nil {
   458  		result.cc.Response = autorest.Response{Response: resp}
   459  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", resp, "Failure sending request")
   460  		return
   461  	}
   462  
   463  	result.cc, err = client.ListByServiceResponder(resp)
   464  	if err != nil {
   465  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "ListByService", resp, "Failure responding to request")
   466  		return
   467  	}
   468  	if result.cc.hasNextLink() && result.cc.IsEmpty() {
   469  		err = result.NextWithContext(ctx)
   470  		return
   471  	}
   472  
   473  	return
   474  }
   475  
   476  // ListByServicePreparer prepares the ListByService request.
   477  func (client CacheClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (*http.Request, error) {
   478  	pathParameters := map[string]interface{}{
   479  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   480  		"serviceName":       autorest.Encode("path", serviceName),
   481  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   482  	}
   483  
   484  	const APIVersion = "2020-12-01"
   485  	queryParameters := map[string]interface{}{
   486  		"api-version": APIVersion,
   487  	}
   488  	if top != nil {
   489  		queryParameters["$top"] = autorest.Encode("query", *top)
   490  	}
   491  	if skip != nil {
   492  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   493  	}
   494  
   495  	preparer := autorest.CreatePreparer(
   496  		autorest.AsGet(),
   497  		autorest.WithBaseURL(client.BaseURI),
   498  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches", pathParameters),
   499  		autorest.WithQueryParameters(queryParameters))
   500  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   501  }
   502  
   503  // ListByServiceSender sends the ListByService request. The method will close the
   504  // http.Response Body if it receives an error.
   505  func (client CacheClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
   506  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   507  }
   508  
   509  // ListByServiceResponder handles the response to the ListByService request. The method always
   510  // closes the http.Response Body.
   511  func (client CacheClient) ListByServiceResponder(resp *http.Response) (result CacheCollection, err error) {
   512  	err = autorest.Respond(
   513  		resp,
   514  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   515  		autorest.ByUnmarshallingJSON(&result),
   516  		autorest.ByClosing())
   517  	result.Response = autorest.Response{Response: resp}
   518  	return
   519  }
   520  
   521  // listByServiceNextResults retrieves the next set of results, if any.
   522  func (client CacheClient) listByServiceNextResults(ctx context.Context, lastResults CacheCollection) (result CacheCollection, err error) {
   523  	req, err := lastResults.cacheCollectionPreparer(ctx)
   524  	if err != nil {
   525  		return result, autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", nil, "Failure preparing next results request")
   526  	}
   527  	if req == nil {
   528  		return
   529  	}
   530  	resp, err := client.ListByServiceSender(req)
   531  	if err != nil {
   532  		result.Response = autorest.Response{Response: resp}
   533  		return result, autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", resp, "Failure sending next results request")
   534  	}
   535  	result, err = client.ListByServiceResponder(resp)
   536  	if err != nil {
   537  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "listByServiceNextResults", resp, "Failure responding to next results request")
   538  	}
   539  	return
   540  }
   541  
   542  // ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
   543  func (client CacheClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, top *int32, skip *int32) (result CacheCollectionIterator, err error) {
   544  	if tracing.IsEnabled() {
   545  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.ListByService")
   546  		defer func() {
   547  			sc := -1
   548  			if result.Response().Response.Response != nil {
   549  				sc = result.page.Response().Response.Response.StatusCode
   550  			}
   551  			tracing.EndSpan(ctx, sc, err)
   552  		}()
   553  	}
   554  	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, top, skip)
   555  	return
   556  }
   557  
   558  // Update updates the details of the cache specified by its identifier.
   559  // Parameters:
   560  // resourceGroupName - the name of the resource group.
   561  // serviceName - the name of the API Management service.
   562  // cacheID - identifier of the Cache entity. Cache identifier (should be either 'default' or valid Azure region
   563  // identifier).
   564  // parameters - update parameters.
   565  // ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
   566  // request or it should be * for unconditional update.
   567  func (client CacheClient) Update(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheUpdateParameters, ifMatch string) (result CacheContract, err error) {
   568  	if tracing.IsEnabled() {
   569  		ctx = tracing.StartSpan(ctx, fqdn+"/CacheClient.Update")
   570  		defer func() {
   571  			sc := -1
   572  			if result.Response.Response != nil {
   573  				sc = result.Response.Response.StatusCode
   574  			}
   575  			tracing.EndSpan(ctx, sc, err)
   576  		}()
   577  	}
   578  	if err := validation.Validate([]validation.Validation{
   579  		{TargetValue: serviceName,
   580  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   581  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
   582  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
   583  		{TargetValue: cacheID,
   584  			Constraints: []validation.Constraint{{Target: "cacheID", Name: validation.MaxLength, Rule: 80, Chain: nil},
   585  				{Target: "cacheID", Name: validation.MinLength, Rule: 1, Chain: nil},
   586  				{Target: "cacheID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
   587  		return result, validation.NewError("apimanagement.CacheClient", "Update", err.Error())
   588  	}
   589  
   590  	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, cacheID, parameters, ifMatch)
   591  	if err != nil {
   592  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", nil, "Failure preparing request")
   593  		return
   594  	}
   595  
   596  	resp, err := client.UpdateSender(req)
   597  	if err != nil {
   598  		result.Response = autorest.Response{Response: resp}
   599  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", resp, "Failure sending request")
   600  		return
   601  	}
   602  
   603  	result, err = client.UpdateResponder(resp)
   604  	if err != nil {
   605  		err = autorest.NewErrorWithError(err, "apimanagement.CacheClient", "Update", resp, "Failure responding to request")
   606  		return
   607  	}
   608  
   609  	return
   610  }
   611  
   612  // UpdatePreparer prepares the Update request.
   613  func (client CacheClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, cacheID string, parameters CacheUpdateParameters, ifMatch string) (*http.Request, error) {
   614  	pathParameters := map[string]interface{}{
   615  		"cacheId":           autorest.Encode("path", cacheID),
   616  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   617  		"serviceName":       autorest.Encode("path", serviceName),
   618  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   619  	}
   620  
   621  	const APIVersion = "2020-12-01"
   622  	queryParameters := map[string]interface{}{
   623  		"api-version": APIVersion,
   624  	}
   625  
   626  	preparer := autorest.CreatePreparer(
   627  		autorest.AsContentType("application/json; charset=utf-8"),
   628  		autorest.AsPatch(),
   629  		autorest.WithBaseURL(client.BaseURI),
   630  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/caches/{cacheId}", pathParameters),
   631  		autorest.WithJSON(parameters),
   632  		autorest.WithQueryParameters(queryParameters),
   633  		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   634  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   635  }
   636  
   637  // UpdateSender sends the Update request. The method will close the
   638  // http.Response Body if it receives an error.
   639  func (client CacheClient) UpdateSender(req *http.Request) (*http.Response, error) {
   640  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   641  }
   642  
   643  // UpdateResponder handles the response to the Update request. The method always
   644  // closes the http.Response Body.
   645  func (client CacheClient) UpdateResponder(resp *http.Response) (result CacheContract, err error) {
   646  	err = autorest.Respond(
   647  		resp,
   648  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   649  		autorest.ByUnmarshallingJSON(&result),
   650  		autorest.ByClosing())
   651  	result.Response = autorest.Response{Response: resp}
   652  	return
   653  }
   654  

View as plain text