...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2021-10-15-preview/eventgrid/channels.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2021-10-15-preview/eventgrid

     1  package eventgrid
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // ChannelsClient is the azure EventGrid Management Client
    18  type ChannelsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewChannelsClient creates an instance of the ChannelsClient client.
    23  func NewChannelsClient(subscriptionID string) ChannelsClient {
    24  	return NewChannelsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewChannelsClientWithBaseURI creates an instance of the ChannelsClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewChannelsClientWithBaseURI(baseURI string, subscriptionID string) ChannelsClient {
    30  	return ChannelsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate synchronously creates or updates a new channel with the specified parameters.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group within the partners subscription.
    36  // partnerNamespaceName - name of the partner namespace.
    37  // channelName - name of the channel.
    38  // channelInfo - channel information.
    39  func (client ChannelsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string, channelInfo Channel) (result Channel, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, partnerNamespaceName, channelName, channelInfo)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	resp, err := client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		result.Response = autorest.Response{Response: resp}
    59  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "CreateOrUpdate", resp, "Failure sending request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateResponder(resp)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client ChannelsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string, channelInfo Channel) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"channelName":          autorest.Encode("path", channelName),
    76  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
    77  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
    79  	}
    80  
    81  	const APIVersion = "2021-10-15-preview"
    82  	queryParameters := map[string]interface{}{
    83  		"api-version": APIVersion,
    84  	}
    85  
    86  	channelInfo.SystemData = nil
    87  	preparer := autorest.CreatePreparer(
    88  		autorest.AsContentType("application/json; charset=utf-8"),
    89  		autorest.AsPut(),
    90  		autorest.WithBaseURL(client.BaseURI),
    91  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels/{channelName}", pathParameters),
    92  		autorest.WithJSON(channelInfo),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client ChannelsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   101  }
   102  
   103  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   104  // closes the http.Response Body.
   105  func (client ChannelsClient) CreateOrUpdateResponder(resp *http.Response) (result Channel, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  
   115  // Delete delete an existing channel.
   116  // Parameters:
   117  // resourceGroupName - the name of the resource group within the partners subscription.
   118  // partnerNamespaceName - name of the partner namespace.
   119  // channelName - name of the channel.
   120  func (client ChannelsClient) Delete(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (result ChannelsDeleteFuture, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.Delete")
   123  		defer func() {
   124  			sc := -1
   125  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   126  				sc = result.FutureAPI.Response().StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	req, err := client.DeletePreparer(ctx, resourceGroupName, partnerNamespaceName, channelName)
   132  	if err != nil {
   133  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Delete", nil, "Failure preparing request")
   134  		return
   135  	}
   136  
   137  	result, err = client.DeleteSender(req)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Delete", result.Response(), "Failure sending request")
   140  		return
   141  	}
   142  
   143  	return
   144  }
   145  
   146  // DeletePreparer prepares the Delete request.
   147  func (client ChannelsClient) DeletePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (*http.Request, error) {
   148  	pathParameters := map[string]interface{}{
   149  		"channelName":          autorest.Encode("path", channelName),
   150  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   151  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   152  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   153  	}
   154  
   155  	const APIVersion = "2021-10-15-preview"
   156  	queryParameters := map[string]interface{}{
   157  		"api-version": APIVersion,
   158  	}
   159  
   160  	preparer := autorest.CreatePreparer(
   161  		autorest.AsDelete(),
   162  		autorest.WithBaseURL(client.BaseURI),
   163  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels/{channelName}", pathParameters),
   164  		autorest.WithQueryParameters(queryParameters))
   165  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   166  }
   167  
   168  // DeleteSender sends the Delete request. The method will close the
   169  // http.Response Body if it receives an error.
   170  func (client ChannelsClient) DeleteSender(req *http.Request) (future ChannelsDeleteFuture, err error) {
   171  	var resp *http.Response
   172  	future.FutureAPI = &azure.Future{}
   173  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   174  	if err != nil {
   175  		return
   176  	}
   177  	var azf azure.Future
   178  	azf, err = azure.NewFutureFromResponse(resp)
   179  	future.FutureAPI = &azf
   180  	future.Result = future.result
   181  	return
   182  }
   183  
   184  // DeleteResponder handles the response to the Delete request. The method always
   185  // closes the http.Response Body.
   186  func (client ChannelsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   187  	err = autorest.Respond(
   188  		resp,
   189  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   190  		autorest.ByClosing())
   191  	result.Response = resp
   192  	return
   193  }
   194  
   195  // Get get properties of a channel.
   196  // Parameters:
   197  // resourceGroupName - the name of the resource group within the partners subscription.
   198  // partnerNamespaceName - name of the partner namespace.
   199  // channelName - name of the channel.
   200  func (client ChannelsClient) Get(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (result Channel, err error) {
   201  	if tracing.IsEnabled() {
   202  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.Get")
   203  		defer func() {
   204  			sc := -1
   205  			if result.Response.Response != nil {
   206  				sc = result.Response.Response.StatusCode
   207  			}
   208  			tracing.EndSpan(ctx, sc, err)
   209  		}()
   210  	}
   211  	req, err := client.GetPreparer(ctx, resourceGroupName, partnerNamespaceName, channelName)
   212  	if err != nil {
   213  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Get", nil, "Failure preparing request")
   214  		return
   215  	}
   216  
   217  	resp, err := client.GetSender(req)
   218  	if err != nil {
   219  		result.Response = autorest.Response{Response: resp}
   220  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Get", resp, "Failure sending request")
   221  		return
   222  	}
   223  
   224  	result, err = client.GetResponder(resp)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Get", resp, "Failure responding to request")
   227  		return
   228  	}
   229  
   230  	return
   231  }
   232  
   233  // GetPreparer prepares the Get request.
   234  func (client ChannelsClient) GetPreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (*http.Request, error) {
   235  	pathParameters := map[string]interface{}{
   236  		"channelName":          autorest.Encode("path", channelName),
   237  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   238  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   239  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   240  	}
   241  
   242  	const APIVersion = "2021-10-15-preview"
   243  	queryParameters := map[string]interface{}{
   244  		"api-version": APIVersion,
   245  	}
   246  
   247  	preparer := autorest.CreatePreparer(
   248  		autorest.AsGet(),
   249  		autorest.WithBaseURL(client.BaseURI),
   250  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels/{channelName}", pathParameters),
   251  		autorest.WithQueryParameters(queryParameters))
   252  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   253  }
   254  
   255  // GetSender sends the Get request. The method will close the
   256  // http.Response Body if it receives an error.
   257  func (client ChannelsClient) GetSender(req *http.Request) (*http.Response, error) {
   258  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   259  }
   260  
   261  // GetResponder handles the response to the Get request. The method always
   262  // closes the http.Response Body.
   263  func (client ChannelsClient) GetResponder(resp *http.Response) (result Channel, err error) {
   264  	err = autorest.Respond(
   265  		resp,
   266  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   267  		autorest.ByUnmarshallingJSON(&result),
   268  		autorest.ByClosing())
   269  	result.Response = autorest.Response{Response: resp}
   270  	return
   271  }
   272  
   273  // GetFullURL get the full endpoint URL of a partner destination channel.
   274  // Parameters:
   275  // resourceGroupName - the name of the resource group within the partners subscription.
   276  // partnerNamespaceName - name of the partner namespace.
   277  // channelName - name of the Channel.
   278  func (client ChannelsClient) GetFullURL(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (result EventSubscriptionFullURL, err error) {
   279  	if tracing.IsEnabled() {
   280  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.GetFullURL")
   281  		defer func() {
   282  			sc := -1
   283  			if result.Response.Response != nil {
   284  				sc = result.Response.Response.StatusCode
   285  			}
   286  			tracing.EndSpan(ctx, sc, err)
   287  		}()
   288  	}
   289  	req, err := client.GetFullURLPreparer(ctx, resourceGroupName, partnerNamespaceName, channelName)
   290  	if err != nil {
   291  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "GetFullURL", nil, "Failure preparing request")
   292  		return
   293  	}
   294  
   295  	resp, err := client.GetFullURLSender(req)
   296  	if err != nil {
   297  		result.Response = autorest.Response{Response: resp}
   298  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "GetFullURL", resp, "Failure sending request")
   299  		return
   300  	}
   301  
   302  	result, err = client.GetFullURLResponder(resp)
   303  	if err != nil {
   304  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "GetFullURL", resp, "Failure responding to request")
   305  		return
   306  	}
   307  
   308  	return
   309  }
   310  
   311  // GetFullURLPreparer prepares the GetFullURL request.
   312  func (client ChannelsClient) GetFullURLPreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string) (*http.Request, error) {
   313  	pathParameters := map[string]interface{}{
   314  		"channelName":          autorest.Encode("path", channelName),
   315  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   316  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   317  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   318  	}
   319  
   320  	const APIVersion = "2021-10-15-preview"
   321  	queryParameters := map[string]interface{}{
   322  		"api-version": APIVersion,
   323  	}
   324  
   325  	preparer := autorest.CreatePreparer(
   326  		autorest.AsPost(),
   327  		autorest.WithBaseURL(client.BaseURI),
   328  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels/{channelName}/getFullUrl", pathParameters),
   329  		autorest.WithQueryParameters(queryParameters))
   330  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   331  }
   332  
   333  // GetFullURLSender sends the GetFullURL request. The method will close the
   334  // http.Response Body if it receives an error.
   335  func (client ChannelsClient) GetFullURLSender(req *http.Request) (*http.Response, error) {
   336  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   337  }
   338  
   339  // GetFullURLResponder handles the response to the GetFullURL request. The method always
   340  // closes the http.Response Body.
   341  func (client ChannelsClient) GetFullURLResponder(resp *http.Response) (result EventSubscriptionFullURL, err error) {
   342  	err = autorest.Respond(
   343  		resp,
   344  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   345  		autorest.ByUnmarshallingJSON(&result),
   346  		autorest.ByClosing())
   347  	result.Response = autorest.Response{Response: resp}
   348  	return
   349  }
   350  
   351  // ListByPartnerNamespace list all the channels in a partner namespace.
   352  // Parameters:
   353  // resourceGroupName - the name of the resource group within the partners subscription.
   354  // partnerNamespaceName - name of the partner namespace.
   355  // filter - the query used to filter the search results using OData syntax. Filtering is permitted on the
   356  // 'name' property only and with limited number of OData operations. These operations are: the 'contains'
   357  // function as well as the following logical operations: not, and, or, eq (for equal), and ne (for not equal).
   358  // No arithmetic operations are supported. The following is a valid filter example: $filter=contains(namE,
   359  // 'PATTERN') and name ne 'PATTERN-1'. The following is not a valid filter example: $filter=location eq
   360  // 'westus'.
   361  // top - the number of results to return per page for the list operation. Valid range for top parameter is 1 to
   362  // 100. If not specified, the default number of results to be returned is 20 items per page.
   363  func (client ChannelsClient) ListByPartnerNamespace(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (result ChannelsListResultPage, err error) {
   364  	if tracing.IsEnabled() {
   365  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.ListByPartnerNamespace")
   366  		defer func() {
   367  			sc := -1
   368  			if result.clr.Response.Response != nil {
   369  				sc = result.clr.Response.Response.StatusCode
   370  			}
   371  			tracing.EndSpan(ctx, sc, err)
   372  		}()
   373  	}
   374  	result.fn = client.listByPartnerNamespaceNextResults
   375  	req, err := client.ListByPartnerNamespacePreparer(ctx, resourceGroupName, partnerNamespaceName, filter, top)
   376  	if err != nil {
   377  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "ListByPartnerNamespace", nil, "Failure preparing request")
   378  		return
   379  	}
   380  
   381  	resp, err := client.ListByPartnerNamespaceSender(req)
   382  	if err != nil {
   383  		result.clr.Response = autorest.Response{Response: resp}
   384  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "ListByPartnerNamespace", resp, "Failure sending request")
   385  		return
   386  	}
   387  
   388  	result.clr, err = client.ListByPartnerNamespaceResponder(resp)
   389  	if err != nil {
   390  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "ListByPartnerNamespace", resp, "Failure responding to request")
   391  		return
   392  	}
   393  	if result.clr.hasNextLink() && result.clr.IsEmpty() {
   394  		err = result.NextWithContext(ctx)
   395  		return
   396  	}
   397  
   398  	return
   399  }
   400  
   401  // ListByPartnerNamespacePreparer prepares the ListByPartnerNamespace request.
   402  func (client ChannelsClient) ListByPartnerNamespacePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (*http.Request, error) {
   403  	pathParameters := map[string]interface{}{
   404  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   405  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   406  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   407  	}
   408  
   409  	const APIVersion = "2021-10-15-preview"
   410  	queryParameters := map[string]interface{}{
   411  		"api-version": APIVersion,
   412  	}
   413  	if len(filter) > 0 {
   414  		queryParameters["$filter"] = autorest.Encode("query", filter)
   415  	}
   416  	if top != nil {
   417  		queryParameters["$top"] = autorest.Encode("query", *top)
   418  	}
   419  
   420  	preparer := autorest.CreatePreparer(
   421  		autorest.AsGet(),
   422  		autorest.WithBaseURL(client.BaseURI),
   423  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels", pathParameters),
   424  		autorest.WithQueryParameters(queryParameters))
   425  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   426  }
   427  
   428  // ListByPartnerNamespaceSender sends the ListByPartnerNamespace request. The method will close the
   429  // http.Response Body if it receives an error.
   430  func (client ChannelsClient) ListByPartnerNamespaceSender(req *http.Request) (*http.Response, error) {
   431  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   432  }
   433  
   434  // ListByPartnerNamespaceResponder handles the response to the ListByPartnerNamespace request. The method always
   435  // closes the http.Response Body.
   436  func (client ChannelsClient) ListByPartnerNamespaceResponder(resp *http.Response) (result ChannelsListResult, err error) {
   437  	err = autorest.Respond(
   438  		resp,
   439  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   440  		autorest.ByUnmarshallingJSON(&result),
   441  		autorest.ByClosing())
   442  	result.Response = autorest.Response{Response: resp}
   443  	return
   444  }
   445  
   446  // listByPartnerNamespaceNextResults retrieves the next set of results, if any.
   447  func (client ChannelsClient) listByPartnerNamespaceNextResults(ctx context.Context, lastResults ChannelsListResult) (result ChannelsListResult, err error) {
   448  	req, err := lastResults.channelsListResultPreparer(ctx)
   449  	if err != nil {
   450  		return result, autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "listByPartnerNamespaceNextResults", nil, "Failure preparing next results request")
   451  	}
   452  	if req == nil {
   453  		return
   454  	}
   455  	resp, err := client.ListByPartnerNamespaceSender(req)
   456  	if err != nil {
   457  		result.Response = autorest.Response{Response: resp}
   458  		return result, autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "listByPartnerNamespaceNextResults", resp, "Failure sending next results request")
   459  	}
   460  	result, err = client.ListByPartnerNamespaceResponder(resp)
   461  	if err != nil {
   462  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "listByPartnerNamespaceNextResults", resp, "Failure responding to next results request")
   463  	}
   464  	return
   465  }
   466  
   467  // ListByPartnerNamespaceComplete enumerates all values, automatically crossing page boundaries as required.
   468  func (client ChannelsClient) ListByPartnerNamespaceComplete(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (result ChannelsListResultIterator, err error) {
   469  	if tracing.IsEnabled() {
   470  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.ListByPartnerNamespace")
   471  		defer func() {
   472  			sc := -1
   473  			if result.Response().Response.Response != nil {
   474  				sc = result.page.Response().Response.Response.StatusCode
   475  			}
   476  			tracing.EndSpan(ctx, sc, err)
   477  		}()
   478  	}
   479  	result.page, err = client.ListByPartnerNamespace(ctx, resourceGroupName, partnerNamespaceName, filter, top)
   480  	return
   481  }
   482  
   483  // Update synchronously updates a channel with the specified parameters.
   484  // Parameters:
   485  // resourceGroupName - the name of the resource group within the partners subscription.
   486  // partnerNamespaceName - name of the partner namespace.
   487  // channelName - name of the channel.
   488  // channelUpdateParameters - channel update information.
   489  func (client ChannelsClient) Update(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string, channelUpdateParameters ChannelUpdateParameters) (result autorest.Response, err error) {
   490  	if tracing.IsEnabled() {
   491  		ctx = tracing.StartSpan(ctx, fqdn+"/ChannelsClient.Update")
   492  		defer func() {
   493  			sc := -1
   494  			if result.Response != nil {
   495  				sc = result.Response.StatusCode
   496  			}
   497  			tracing.EndSpan(ctx, sc, err)
   498  		}()
   499  	}
   500  	req, err := client.UpdatePreparer(ctx, resourceGroupName, partnerNamespaceName, channelName, channelUpdateParameters)
   501  	if err != nil {
   502  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Update", nil, "Failure preparing request")
   503  		return
   504  	}
   505  
   506  	resp, err := client.UpdateSender(req)
   507  	if err != nil {
   508  		result.Response = resp
   509  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Update", resp, "Failure sending request")
   510  		return
   511  	}
   512  
   513  	result, err = client.UpdateResponder(resp)
   514  	if err != nil {
   515  		err = autorest.NewErrorWithError(err, "eventgrid.ChannelsClient", "Update", resp, "Failure responding to request")
   516  		return
   517  	}
   518  
   519  	return
   520  }
   521  
   522  // UpdatePreparer prepares the Update request.
   523  func (client ChannelsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, channelName string, channelUpdateParameters ChannelUpdateParameters) (*http.Request, error) {
   524  	pathParameters := map[string]interface{}{
   525  		"channelName":          autorest.Encode("path", channelName),
   526  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   527  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   528  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   529  	}
   530  
   531  	const APIVersion = "2021-10-15-preview"
   532  	queryParameters := map[string]interface{}{
   533  		"api-version": APIVersion,
   534  	}
   535  
   536  	preparer := autorest.CreatePreparer(
   537  		autorest.AsContentType("application/json; charset=utf-8"),
   538  		autorest.AsPatch(),
   539  		autorest.WithBaseURL(client.BaseURI),
   540  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/channels/{channelName}", pathParameters),
   541  		autorest.WithJSON(channelUpdateParameters),
   542  		autorest.WithQueryParameters(queryParameters))
   543  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   544  }
   545  
   546  // UpdateSender sends the Update request. The method will close the
   547  // http.Response Body if it receives an error.
   548  func (client ChannelsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   549  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   550  }
   551  
   552  // UpdateResponder handles the response to the Update request. The method always
   553  // closes the http.Response Body.
   554  func (client ChannelsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
   555  	err = autorest.Respond(
   556  		resp,
   557  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   558  		autorest.ByClosing())
   559  	result.Response = resp
   560  	return
   561  }
   562  

View as plain text