...

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

View as plain text