...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2021-10-15-preview/eventgrid/eventchannels.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  // EventChannelsClient is the azure EventGrid Management Client
    18  type EventChannelsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewEventChannelsClient creates an instance of the EventChannelsClient client.
    23  func NewEventChannelsClient(subscriptionID string) EventChannelsClient {
    24  	return NewEventChannelsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewEventChannelsClientWithBaseURI creates an instance of the EventChannelsClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewEventChannelsClientWithBaseURI(baseURI string, subscriptionID string) EventChannelsClient {
    30  	return EventChannelsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate asynchronously creates a new event channel with the specified parameters.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group within the user's subscription.
    36  // partnerNamespaceName - name of the partner namespace.
    37  // eventChannelName - name of the event channel.
    38  // eventChannelInfo - eventChannel information.
    39  func (client EventChannelsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string, eventChannelInfo EventChannel) (result EventChannel, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/EventChannelsClient.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, eventChannelName, eventChannelInfo)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "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.EventChannelsClient", "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.EventChannelsClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client EventChannelsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string, eventChannelInfo EventChannel) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"eventChannelName":     autorest.Encode("path", eventChannelName),
    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  	eventChannelInfo.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}/eventChannels/{eventChannelName}", pathParameters),
    92  		autorest.WithJSON(eventChannelInfo),
    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 EventChannelsClient) 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 EventChannelsClient) CreateOrUpdateResponder(resp *http.Response) (result EventChannel, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  
   115  // Delete delete existing event channel.
   116  // Parameters:
   117  // resourceGroupName - the name of the resource group within the user's subscription.
   118  // partnerNamespaceName - name of the partner namespace.
   119  // eventChannelName - name of the event channel.
   120  func (client EventChannelsClient) Delete(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string) (result EventChannelsDeleteFuture, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/EventChannelsClient.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, eventChannelName)
   132  	if err != nil {
   133  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "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.EventChannelsClient", "Delete", result.Response(), "Failure sending request")
   140  		return
   141  	}
   142  
   143  	return
   144  }
   145  
   146  // DeletePreparer prepares the Delete request.
   147  func (client EventChannelsClient) DeletePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string) (*http.Request, error) {
   148  	pathParameters := map[string]interface{}{
   149  		"eventChannelName":     autorest.Encode("path", eventChannelName),
   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}/eventChannels/{eventChannelName}", 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 EventChannelsClient) DeleteSender(req *http.Request) (future EventChannelsDeleteFuture, 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 EventChannelsClient) 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 an event channel.
   196  // Parameters:
   197  // resourceGroupName - the name of the resource group within the user's subscription.
   198  // partnerNamespaceName - name of the partner namespace.
   199  // eventChannelName - name of the event channel.
   200  func (client EventChannelsClient) Get(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string) (result EventChannel, err error) {
   201  	if tracing.IsEnabled() {
   202  		ctx = tracing.StartSpan(ctx, fqdn+"/EventChannelsClient.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, eventChannelName)
   212  	if err != nil {
   213  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "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.EventChannelsClient", "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.EventChannelsClient", "Get", resp, "Failure responding to request")
   227  		return
   228  	}
   229  
   230  	return
   231  }
   232  
   233  // GetPreparer prepares the Get request.
   234  func (client EventChannelsClient) GetPreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, eventChannelName string) (*http.Request, error) {
   235  	pathParameters := map[string]interface{}{
   236  		"eventChannelName":     autorest.Encode("path", eventChannelName),
   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}/eventChannels/{eventChannelName}", 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 EventChannelsClient) 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 EventChannelsClient) GetResponder(resp *http.Response) (result EventChannel, 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  // ListByPartnerNamespace list all the event channels in a partner namespace.
   274  // Parameters:
   275  // resourceGroupName - the name of the resource group within the user's subscription.
   276  // partnerNamespaceName - name of the partner namespace.
   277  // filter - the query used to filter the search results using OData syntax. Filtering is permitted on the
   278  // 'name' property only and with limited number of OData operations. These operations are: the 'contains'
   279  // function as well as the following logical operations: not, and, or, eq (for equal), and ne (for not equal).
   280  // No arithmetic operations are supported. The following is a valid filter example: $filter=contains(namE,
   281  // 'PATTERN') and name ne 'PATTERN-1'. The following is not a valid filter example: $filter=location eq
   282  // 'westus'.
   283  // top - the number of results to return per page for the list operation. Valid range for top parameter is 1 to
   284  // 100. If not specified, the default number of results to be returned is 20 items per page.
   285  func (client EventChannelsClient) ListByPartnerNamespace(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (result EventChannelsListResultPage, err error) {
   286  	if tracing.IsEnabled() {
   287  		ctx = tracing.StartSpan(ctx, fqdn+"/EventChannelsClient.ListByPartnerNamespace")
   288  		defer func() {
   289  			sc := -1
   290  			if result.eclr.Response.Response != nil {
   291  				sc = result.eclr.Response.Response.StatusCode
   292  			}
   293  			tracing.EndSpan(ctx, sc, err)
   294  		}()
   295  	}
   296  	result.fn = client.listByPartnerNamespaceNextResults
   297  	req, err := client.ListByPartnerNamespacePreparer(ctx, resourceGroupName, partnerNamespaceName, filter, top)
   298  	if err != nil {
   299  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "ListByPartnerNamespace", nil, "Failure preparing request")
   300  		return
   301  	}
   302  
   303  	resp, err := client.ListByPartnerNamespaceSender(req)
   304  	if err != nil {
   305  		result.eclr.Response = autorest.Response{Response: resp}
   306  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "ListByPartnerNamespace", resp, "Failure sending request")
   307  		return
   308  	}
   309  
   310  	result.eclr, err = client.ListByPartnerNamespaceResponder(resp)
   311  	if err != nil {
   312  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "ListByPartnerNamespace", resp, "Failure responding to request")
   313  		return
   314  	}
   315  	if result.eclr.hasNextLink() && result.eclr.IsEmpty() {
   316  		err = result.NextWithContext(ctx)
   317  		return
   318  	}
   319  
   320  	return
   321  }
   322  
   323  // ListByPartnerNamespacePreparer prepares the ListByPartnerNamespace request.
   324  func (client EventChannelsClient) ListByPartnerNamespacePreparer(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (*http.Request, error) {
   325  	pathParameters := map[string]interface{}{
   326  		"partnerNamespaceName": autorest.Encode("path", partnerNamespaceName),
   327  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   328  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   329  	}
   330  
   331  	const APIVersion = "2021-10-15-preview"
   332  	queryParameters := map[string]interface{}{
   333  		"api-version": APIVersion,
   334  	}
   335  	if len(filter) > 0 {
   336  		queryParameters["$filter"] = autorest.Encode("query", filter)
   337  	}
   338  	if top != nil {
   339  		queryParameters["$top"] = autorest.Encode("query", *top)
   340  	}
   341  
   342  	preparer := autorest.CreatePreparer(
   343  		autorest.AsGet(),
   344  		autorest.WithBaseURL(client.BaseURI),
   345  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/partnerNamespaces/{partnerNamespaceName}/eventChannels", pathParameters),
   346  		autorest.WithQueryParameters(queryParameters))
   347  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   348  }
   349  
   350  // ListByPartnerNamespaceSender sends the ListByPartnerNamespace request. The method will close the
   351  // http.Response Body if it receives an error.
   352  func (client EventChannelsClient) ListByPartnerNamespaceSender(req *http.Request) (*http.Response, error) {
   353  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   354  }
   355  
   356  // ListByPartnerNamespaceResponder handles the response to the ListByPartnerNamespace request. The method always
   357  // closes the http.Response Body.
   358  func (client EventChannelsClient) ListByPartnerNamespaceResponder(resp *http.Response) (result EventChannelsListResult, err error) {
   359  	err = autorest.Respond(
   360  		resp,
   361  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   362  		autorest.ByUnmarshallingJSON(&result),
   363  		autorest.ByClosing())
   364  	result.Response = autorest.Response{Response: resp}
   365  	return
   366  }
   367  
   368  // listByPartnerNamespaceNextResults retrieves the next set of results, if any.
   369  func (client EventChannelsClient) listByPartnerNamespaceNextResults(ctx context.Context, lastResults EventChannelsListResult) (result EventChannelsListResult, err error) {
   370  	req, err := lastResults.eventChannelsListResultPreparer(ctx)
   371  	if err != nil {
   372  		return result, autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "listByPartnerNamespaceNextResults", nil, "Failure preparing next results request")
   373  	}
   374  	if req == nil {
   375  		return
   376  	}
   377  	resp, err := client.ListByPartnerNamespaceSender(req)
   378  	if err != nil {
   379  		result.Response = autorest.Response{Response: resp}
   380  		return result, autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "listByPartnerNamespaceNextResults", resp, "Failure sending next results request")
   381  	}
   382  	result, err = client.ListByPartnerNamespaceResponder(resp)
   383  	if err != nil {
   384  		err = autorest.NewErrorWithError(err, "eventgrid.EventChannelsClient", "listByPartnerNamespaceNextResults", resp, "Failure responding to next results request")
   385  	}
   386  	return
   387  }
   388  
   389  // ListByPartnerNamespaceComplete enumerates all values, automatically crossing page boundaries as required.
   390  func (client EventChannelsClient) ListByPartnerNamespaceComplete(ctx context.Context, resourceGroupName string, partnerNamespaceName string, filter string, top *int32) (result EventChannelsListResultIterator, err error) {
   391  	if tracing.IsEnabled() {
   392  		ctx = tracing.StartSpan(ctx, fqdn+"/EventChannelsClient.ListByPartnerNamespace")
   393  		defer func() {
   394  			sc := -1
   395  			if result.Response().Response.Response != nil {
   396  				sc = result.page.Response().Response.Response.StatusCode
   397  			}
   398  			tracing.EndSpan(ctx, sc, err)
   399  		}()
   400  	}
   401  	result.page, err = client.ListByPartnerNamespace(ctx, resourceGroupName, partnerNamespaceName, filter, top)
   402  	return
   403  }
   404  

View as plain text