1package eventgrid 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// PrivateEndpointConnectionsClient is the azure EventGrid Management Client 29type PrivateEndpointConnectionsClient struct { 30 BaseClient 31} 32 33// NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client. 34func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient { 35 return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewPrivateEndpointConnectionsClientWithBaseURI creates an instance of the PrivateEndpointConnectionsClient client 39// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 40// clouds, Azure stack). 41func NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient { 42 return PrivateEndpointConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Delete delete a specific private endpoint connection under a topic or domain. 46// Parameters: 47// resourceGroupName - the name of the resource group within the user's subscription. 48// parentType - the type of the parent resource. This can be either \'topics\' or \'domains\'. 49// parentName - the name of the parent resource (namely, either, the topic name or domain name). 50// privateEndpointConnectionName - the name of the private endpoint connection connection. 51func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete") 54 defer func() { 55 sc := -1 56 if result.Response() != nil { 57 sc = result.Response().StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.DeletePreparer(ctx, resourceGroupName, parentType, parentName, privateEndpointConnectionName) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request") 65 return 66 } 67 68 result, err = client.DeleteSender(req) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Delete", result.Response(), "Failure sending request") 71 return 72 } 73 74 return 75} 76 77// DeletePreparer prepares the Delete request. 78func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "parentName": autorest.Encode("path", parentName), 81 "parentType": autorest.Encode("path", parentType), 82 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2020-04-01-preview" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsDelete(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/{parentType}/{parentName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// DeleteSender sends the Delete request. The method will close the 101// http.Response Body if it receives an error. 102func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) { 103 var resp *http.Response 104 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105 if err != nil { 106 return 107 } 108 future.Future, err = azure.NewFutureFromResponse(resp) 109 return 110} 111 112// DeleteResponder handles the response to the Delete request. The method always 113// closes the http.Response Body. 114func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 115 err = autorest.Respond( 116 resp, 117 client.ByInspecting(), 118 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 119 autorest.ByClosing()) 120 result.Response = resp 121 return 122} 123 124// Get get a specific private endpoint connection under a topic or domain. 125// Parameters: 126// resourceGroupName - the name of the resource group within the user's subscription. 127// parentType - the type of the parent resource. This can be either \'topics\' or \'domains\'. 128// parentName - the name of the parent resource (namely, either, the topic name or domain name). 129// privateEndpointConnectionName - the name of the private endpoint connection connection. 130func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) { 131 if tracing.IsEnabled() { 132 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get") 133 defer func() { 134 sc := -1 135 if result.Response.Response != nil { 136 sc = result.Response.Response.StatusCode 137 } 138 tracing.EndSpan(ctx, sc, err) 139 }() 140 } 141 req, err := client.GetPreparer(ctx, resourceGroupName, parentType, parentName, privateEndpointConnectionName) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request") 144 return 145 } 146 147 resp, err := client.GetSender(req) 148 if err != nil { 149 result.Response = autorest.Response{Response: resp} 150 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request") 151 return 152 } 153 154 result, err = client.GetResponder(resp) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request") 157 } 158 159 return 160} 161 162// GetPreparer prepares the Get request. 163func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string) (*http.Request, error) { 164 pathParameters := map[string]interface{}{ 165 "parentName": autorest.Encode("path", parentName), 166 "parentType": autorest.Encode("path", parentType), 167 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 168 "resourceGroupName": autorest.Encode("path", resourceGroupName), 169 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 170 } 171 172 const APIVersion = "2020-04-01-preview" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsGet(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/{parentType}/{parentName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// GetSender sends the Get request. The method will close the 186// http.Response Body if it receives an error. 187func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) { 188 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 189} 190 191// GetResponder handles the response to the Get request. The method always 192// closes the http.Response Body. 193func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK), 198 autorest.ByUnmarshallingJSON(&result), 199 autorest.ByClosing()) 200 result.Response = autorest.Response{Response: resp} 201 return 202} 203 204// ListByResource get all private endpoint connections under a topic or domain. 205// Parameters: 206// resourceGroupName - the name of the resource group within the user's subscription. 207// parentType - the type of the parent resource. This can be either \'topics\' or \'domains\'. 208// parentName - the name of the parent resource (namely, either, the topic name or domain name). 209// filter - the query used to filter the search results using OData syntax. Filtering is permitted on the 210// 'name' property only and with limited number of OData operations. These operations are: the 'contains' 211// function as well as the following logical operations: not, and, or, eq (for equal), and ne (for not equal). 212// No arithmetic operations are supported. The following is a valid filter example: $filter=contains(namE, 213// 'PATTERN') and name ne 'PATTERN-1'. The following is not a valid filter example: $filter=location eq 214// 'westus'. 215// top - the number of results to return per page for the list operation. Valid range for top parameter is 1 to 216// 100. If not specified, the default number of results to be returned is 20 items per page. 217func (client PrivateEndpointConnectionsClient) ListByResource(ctx context.Context, resourceGroupName string, parentType string, parentName string, filter string, top *int32) (result PrivateEndpointConnectionListResultPage, err error) { 218 if tracing.IsEnabled() { 219 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByResource") 220 defer func() { 221 sc := -1 222 if result.peclr.Response.Response != nil { 223 sc = result.peclr.Response.Response.StatusCode 224 } 225 tracing.EndSpan(ctx, sc, err) 226 }() 227 } 228 result.fn = client.listByResourceNextResults 229 req, err := client.ListByResourcePreparer(ctx, resourceGroupName, parentType, parentName, filter, top) 230 if err != nil { 231 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "ListByResource", nil, "Failure preparing request") 232 return 233 } 234 235 resp, err := client.ListByResourceSender(req) 236 if err != nil { 237 result.peclr.Response = autorest.Response{Response: resp} 238 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "ListByResource", resp, "Failure sending request") 239 return 240 } 241 242 result.peclr, err = client.ListByResourceResponder(resp) 243 if err != nil { 244 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "ListByResource", resp, "Failure responding to request") 245 } 246 247 return 248} 249 250// ListByResourcePreparer prepares the ListByResource request. 251func (client PrivateEndpointConnectionsClient) ListByResourcePreparer(ctx context.Context, resourceGroupName string, parentType string, parentName string, filter string, top *int32) (*http.Request, error) { 252 pathParameters := map[string]interface{}{ 253 "parentName": autorest.Encode("path", parentName), 254 "parentType": autorest.Encode("path", parentType), 255 "resourceGroupName": autorest.Encode("path", resourceGroupName), 256 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 257 } 258 259 const APIVersion = "2020-04-01-preview" 260 queryParameters := map[string]interface{}{ 261 "api-version": APIVersion, 262 } 263 if len(filter) > 0 { 264 queryParameters["$filter"] = autorest.Encode("query", filter) 265 } 266 if top != nil { 267 queryParameters["$top"] = autorest.Encode("query", *top) 268 } 269 270 preparer := autorest.CreatePreparer( 271 autorest.AsGet(), 272 autorest.WithBaseURL(client.BaseURI), 273 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/{parentType}/{parentName}/privateEndpointConnections", pathParameters), 274 autorest.WithQueryParameters(queryParameters)) 275 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 276} 277 278// ListByResourceSender sends the ListByResource request. The method will close the 279// http.Response Body if it receives an error. 280func (client PrivateEndpointConnectionsClient) ListByResourceSender(req *http.Request) (*http.Response, error) { 281 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 282} 283 284// ListByResourceResponder handles the response to the ListByResource request. The method always 285// closes the http.Response Body. 286func (client PrivateEndpointConnectionsClient) ListByResourceResponder(resp *http.Response) (result PrivateEndpointConnectionListResult, err error) { 287 err = autorest.Respond( 288 resp, 289 client.ByInspecting(), 290 azure.WithErrorUnlessStatusCode(http.StatusOK), 291 autorest.ByUnmarshallingJSON(&result), 292 autorest.ByClosing()) 293 result.Response = autorest.Response{Response: resp} 294 return 295} 296 297// listByResourceNextResults retrieves the next set of results, if any. 298func (client PrivateEndpointConnectionsClient) listByResourceNextResults(ctx context.Context, lastResults PrivateEndpointConnectionListResult) (result PrivateEndpointConnectionListResult, err error) { 299 req, err := lastResults.privateEndpointConnectionListResultPreparer(ctx) 300 if err != nil { 301 return result, autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "listByResourceNextResults", nil, "Failure preparing next results request") 302 } 303 if req == nil { 304 return 305 } 306 resp, err := client.ListByResourceSender(req) 307 if err != nil { 308 result.Response = autorest.Response{Response: resp} 309 return result, autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "listByResourceNextResults", resp, "Failure sending next results request") 310 } 311 result, err = client.ListByResourceResponder(resp) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "listByResourceNextResults", resp, "Failure responding to next results request") 314 } 315 return 316} 317 318// ListByResourceComplete enumerates all values, automatically crossing page boundaries as required. 319func (client PrivateEndpointConnectionsClient) ListByResourceComplete(ctx context.Context, resourceGroupName string, parentType string, parentName string, filter string, top *int32) (result PrivateEndpointConnectionListResultIterator, err error) { 320 if tracing.IsEnabled() { 321 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByResource") 322 defer func() { 323 sc := -1 324 if result.Response().Response.Response != nil { 325 sc = result.page.Response().Response.Response.StatusCode 326 } 327 tracing.EndSpan(ctx, sc, err) 328 }() 329 } 330 result.page, err = client.ListByResource(ctx, resourceGroupName, parentType, parentName, filter, top) 331 return 332} 333 334// Update update a specific private endpoint connection under a topic or domain. 335// Parameters: 336// resourceGroupName - the name of the resource group within the user's subscription. 337// parentType - the type of the parent resource. This can be either \'topics\' or \'domains\'. 338// parentName - the name of the parent resource (namely, either, the topic name or domain name). 339// privateEndpointConnectionName - the name of the private endpoint connection connection. 340// privateEndpointConnection - the private endpoint connection object to update. 341func (client PrivateEndpointConnectionsClient) Update(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateFuture, err error) { 342 if tracing.IsEnabled() { 343 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Update") 344 defer func() { 345 sc := -1 346 if result.Response() != nil { 347 sc = result.Response().StatusCode 348 } 349 tracing.EndSpan(ctx, sc, err) 350 }() 351 } 352 req, err := client.UpdatePreparer(ctx, resourceGroupName, parentType, parentName, privateEndpointConnectionName, privateEndpointConnection) 353 if err != nil { 354 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Update", nil, "Failure preparing request") 355 return 356 } 357 358 result, err = client.UpdateSender(req) 359 if err != nil { 360 err = autorest.NewErrorWithError(err, "eventgrid.PrivateEndpointConnectionsClient", "Update", result.Response(), "Failure sending request") 361 return 362 } 363 364 return 365} 366 367// UpdatePreparer prepares the Update request. 368func (client PrivateEndpointConnectionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, parentType string, parentName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (*http.Request, error) { 369 pathParameters := map[string]interface{}{ 370 "parentName": autorest.Encode("path", parentName), 371 "parentType": autorest.Encode("path", parentType), 372 "privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName), 373 "resourceGroupName": autorest.Encode("path", resourceGroupName), 374 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 375 } 376 377 const APIVersion = "2020-04-01-preview" 378 queryParameters := map[string]interface{}{ 379 "api-version": APIVersion, 380 } 381 382 preparer := autorest.CreatePreparer( 383 autorest.AsContentType("application/json; charset=utf-8"), 384 autorest.AsPut(), 385 autorest.WithBaseURL(client.BaseURI), 386 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/{parentType}/{parentName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters), 387 autorest.WithJSON(privateEndpointConnection), 388 autorest.WithQueryParameters(queryParameters)) 389 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 390} 391 392// UpdateSender sends the Update request. The method will close the 393// http.Response Body if it receives an error. 394func (client PrivateEndpointConnectionsClient) UpdateSender(req *http.Request) (future PrivateEndpointConnectionsUpdateFuture, err error) { 395 var resp *http.Response 396 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 397 if err != nil { 398 return 399 } 400 future.Future, err = azure.NewFutureFromResponse(resp) 401 return 402} 403 404// UpdateResponder handles the response to the Update request. The method always 405// closes the http.Response Body. 406func (client PrivateEndpointConnectionsClient) UpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) { 407 err = autorest.Respond( 408 resp, 409 client.ByInspecting(), 410 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 411 autorest.ByUnmarshallingJSON(&result), 412 autorest.ByClosing()) 413 result.Response = autorest.Response{Response: resp} 414 return 415} 416