...

Source file src/github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement/apioperation.go

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

View as plain text