1package apimanagement 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/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// ProductGroupClient is the apiManagement Client 30type ProductGroupClient struct { 31 BaseClient 32} 33 34// NewProductGroupClient creates an instance of the ProductGroupClient client. 35func NewProductGroupClient(subscriptionID string) ProductGroupClient { 36 return NewProductGroupClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewProductGroupClientWithBaseURI creates an instance of the ProductGroupClient client. 40func NewProductGroupClientWithBaseURI(baseURI string, subscriptionID string) ProductGroupClient { 41 return ProductGroupClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CheckEntityExists checks that Group entity specified by identifier is associated with the Product entity. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// serviceName - the name of the API Management service. 48// productID - product identifier. Must be unique in the current API Management service instance. 49// groupID - group identifier. Must be unique in the current API Management service instance. 50func (client ProductGroupClient) CheckEntityExists(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (result autorest.Response, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/ProductGroupClient.CheckEntityExists") 53 defer func() { 54 sc := -1 55 if result.Response != nil { 56 sc = result.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: serviceName, 63 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 64 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 66 {TargetValue: productID, 67 Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 68 {Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 69 {TargetValue: groupID, 70 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 71 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 72 return result, validation.NewError("apimanagement.ProductGroupClient", "CheckEntityExists", err.Error()) 73 } 74 75 req, err := client.CheckEntityExistsPreparer(ctx, resourceGroupName, serviceName, productID, groupID) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CheckEntityExists", nil, "Failure preparing request") 78 return 79 } 80 81 resp, err := client.CheckEntityExistsSender(req) 82 if err != nil { 83 result.Response = resp 84 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CheckEntityExists", resp, "Failure sending request") 85 return 86 } 87 88 result, err = client.CheckEntityExistsResponder(resp) 89 if err != nil { 90 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CheckEntityExists", resp, "Failure responding to request") 91 } 92 93 return 94} 95 96// CheckEntityExistsPreparer prepares the CheckEntityExists request. 97func (client ProductGroupClient) CheckEntityExistsPreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (*http.Request, error) { 98 pathParameters := map[string]interface{}{ 99 "groupId": autorest.Encode("path", groupID), 100 "productId": autorest.Encode("path", productID), 101 "resourceGroupName": autorest.Encode("path", resourceGroupName), 102 "serviceName": autorest.Encode("path", serviceName), 103 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 104 } 105 106 const APIVersion = "2019-01-01" 107 queryParameters := map[string]interface{}{ 108 "api-version": APIVersion, 109 } 110 111 preparer := autorest.CreatePreparer( 112 autorest.AsHead(), 113 autorest.WithBaseURL(client.BaseURI), 114 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/groups/{groupId}", pathParameters), 115 autorest.WithQueryParameters(queryParameters)) 116 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 117} 118 119// CheckEntityExistsSender sends the CheckEntityExists request. The method will close the 120// http.Response Body if it receives an error. 121func (client ProductGroupClient) CheckEntityExistsSender(req *http.Request) (*http.Response, error) { 122 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 123 return autorest.SendWithSender(client, req, sd...) 124} 125 126// CheckEntityExistsResponder handles the response to the CheckEntityExists request. The method always 127// closes the http.Response Body. 128func (client ProductGroupClient) CheckEntityExistsResponder(resp *http.Response) (result autorest.Response, err error) { 129 err = autorest.Respond( 130 resp, 131 client.ByInspecting(), 132 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 133 autorest.ByClosing()) 134 result.Response = resp 135 return 136} 137 138// CreateOrUpdate adds the association between the specified developer group with the specified product. 139// Parameters: 140// resourceGroupName - the name of the resource group. 141// serviceName - the name of the API Management service. 142// productID - product identifier. Must be unique in the current API Management service instance. 143// groupID - group identifier. Must be unique in the current API Management service instance. 144func (client ProductGroupClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (result GroupContract, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/ProductGroupClient.CreateOrUpdate") 147 defer func() { 148 sc := -1 149 if result.Response.Response != nil { 150 sc = result.Response.Response.StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 if err := validation.Validate([]validation.Validation{ 156 {TargetValue: serviceName, 157 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 158 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 159 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 160 {TargetValue: productID, 161 Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 162 {Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 163 {TargetValue: groupID, 164 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 165 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 166 return result, validation.NewError("apimanagement.ProductGroupClient", "CreateOrUpdate", err.Error()) 167 } 168 169 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, productID, groupID) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CreateOrUpdate", nil, "Failure preparing request") 172 return 173 } 174 175 resp, err := client.CreateOrUpdateSender(req) 176 if err != nil { 177 result.Response = autorest.Response{Response: resp} 178 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CreateOrUpdate", resp, "Failure sending request") 179 return 180 } 181 182 result, err = client.CreateOrUpdateResponder(resp) 183 if err != nil { 184 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "CreateOrUpdate", resp, "Failure responding to request") 185 } 186 187 return 188} 189 190// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 191func (client ProductGroupClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (*http.Request, error) { 192 pathParameters := map[string]interface{}{ 193 "groupId": autorest.Encode("path", groupID), 194 "productId": autorest.Encode("path", productID), 195 "resourceGroupName": autorest.Encode("path", resourceGroupName), 196 "serviceName": autorest.Encode("path", serviceName), 197 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 198 } 199 200 const APIVersion = "2019-01-01" 201 queryParameters := map[string]interface{}{ 202 "api-version": APIVersion, 203 } 204 205 preparer := autorest.CreatePreparer( 206 autorest.AsPut(), 207 autorest.WithBaseURL(client.BaseURI), 208 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/groups/{groupId}", pathParameters), 209 autorest.WithQueryParameters(queryParameters)) 210 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 211} 212 213// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 214// http.Response Body if it receives an error. 215func (client ProductGroupClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 216 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 217 return autorest.SendWithSender(client, req, sd...) 218} 219 220// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 221// closes the http.Response Body. 222func (client ProductGroupClient) CreateOrUpdateResponder(resp *http.Response) (result GroupContract, err error) { 223 err = autorest.Respond( 224 resp, 225 client.ByInspecting(), 226 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 227 autorest.ByUnmarshallingJSON(&result), 228 autorest.ByClosing()) 229 result.Response = autorest.Response{Response: resp} 230 return 231} 232 233// Delete deletes the association between the specified group and product. 234// Parameters: 235// resourceGroupName - the name of the resource group. 236// serviceName - the name of the API Management service. 237// productID - product identifier. Must be unique in the current API Management service instance. 238// groupID - group identifier. Must be unique in the current API Management service instance. 239func (client ProductGroupClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (result autorest.Response, err error) { 240 if tracing.IsEnabled() { 241 ctx = tracing.StartSpan(ctx, fqdn+"/ProductGroupClient.Delete") 242 defer func() { 243 sc := -1 244 if result.Response != nil { 245 sc = result.Response.StatusCode 246 } 247 tracing.EndSpan(ctx, sc, err) 248 }() 249 } 250 if err := validation.Validate([]validation.Validation{ 251 {TargetValue: serviceName, 252 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 253 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 254 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 255 {TargetValue: productID, 256 Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 257 {Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 258 {TargetValue: groupID, 259 Constraints: []validation.Constraint{{Target: "groupID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 260 {Target: "groupID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 261 return result, validation.NewError("apimanagement.ProductGroupClient", "Delete", err.Error()) 262 } 263 264 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, productID, groupID) 265 if err != nil { 266 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "Delete", nil, "Failure preparing request") 267 return 268 } 269 270 resp, err := client.DeleteSender(req) 271 if err != nil { 272 result.Response = resp 273 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "Delete", resp, "Failure sending request") 274 return 275 } 276 277 result, err = client.DeleteResponder(resp) 278 if err != nil { 279 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "Delete", resp, "Failure responding to request") 280 } 281 282 return 283} 284 285// DeletePreparer prepares the Delete request. 286func (client ProductGroupClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, groupID string) (*http.Request, error) { 287 pathParameters := map[string]interface{}{ 288 "groupId": autorest.Encode("path", groupID), 289 "productId": autorest.Encode("path", productID), 290 "resourceGroupName": autorest.Encode("path", resourceGroupName), 291 "serviceName": autorest.Encode("path", serviceName), 292 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 293 } 294 295 const APIVersion = "2019-01-01" 296 queryParameters := map[string]interface{}{ 297 "api-version": APIVersion, 298 } 299 300 preparer := autorest.CreatePreparer( 301 autorest.AsDelete(), 302 autorest.WithBaseURL(client.BaseURI), 303 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/groups/{groupId}", pathParameters), 304 autorest.WithQueryParameters(queryParameters)) 305 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 306} 307 308// DeleteSender sends the Delete request. The method will close the 309// http.Response Body if it receives an error. 310func (client ProductGroupClient) DeleteSender(req *http.Request) (*http.Response, error) { 311 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 312 return autorest.SendWithSender(client, req, sd...) 313} 314 315// DeleteResponder handles the response to the Delete request. The method always 316// closes the http.Response Body. 317func (client ProductGroupClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 318 err = autorest.Respond( 319 resp, 320 client.ByInspecting(), 321 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 322 autorest.ByClosing()) 323 result.Response = resp 324 return 325} 326 327// ListByProduct lists the collection of developer groups associated with the specified product. 328// Parameters: 329// resourceGroupName - the name of the resource group. 330// serviceName - the name of the API Management service. 331// productID - product identifier. Must be unique in the current API Management service instance. 332// filter - | Field | Usage | Supported operators | Supported functions 333// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt 334// | | </br>| displayName | filter | eq, ne | | </br>| description | filter | eq, ne | | </br> 335// top - number of records to return. 336// skip - number of records to skip. 337func (client ProductGroupClient) ListByProduct(ctx context.Context, resourceGroupName string, serviceName string, productID string, filter string, top *int32, skip *int32) (result GroupCollectionPage, err error) { 338 if tracing.IsEnabled() { 339 ctx = tracing.StartSpan(ctx, fqdn+"/ProductGroupClient.ListByProduct") 340 defer func() { 341 sc := -1 342 if result.gc.Response.Response != nil { 343 sc = result.gc.Response.Response.StatusCode 344 } 345 tracing.EndSpan(ctx, sc, err) 346 }() 347 } 348 if err := validation.Validate([]validation.Validation{ 349 {TargetValue: serviceName, 350 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 351 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 352 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 353 {TargetValue: productID, 354 Constraints: []validation.Constraint{{Target: "productID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 355 {Target: "productID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 356 {TargetValue: top, 357 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 358 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}}, 359 {TargetValue: skip, 360 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 361 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil { 362 return result, validation.NewError("apimanagement.ProductGroupClient", "ListByProduct", err.Error()) 363 } 364 365 result.fn = client.listByProductNextResults 366 req, err := client.ListByProductPreparer(ctx, resourceGroupName, serviceName, productID, filter, top, skip) 367 if err != nil { 368 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "ListByProduct", nil, "Failure preparing request") 369 return 370 } 371 372 resp, err := client.ListByProductSender(req) 373 if err != nil { 374 result.gc.Response = autorest.Response{Response: resp} 375 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "ListByProduct", resp, "Failure sending request") 376 return 377 } 378 379 result.gc, err = client.ListByProductResponder(resp) 380 if err != nil { 381 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "ListByProduct", resp, "Failure responding to request") 382 } 383 384 return 385} 386 387// ListByProductPreparer prepares the ListByProduct request. 388func (client ProductGroupClient) ListByProductPreparer(ctx context.Context, resourceGroupName string, serviceName string, productID string, filter string, top *int32, skip *int32) (*http.Request, error) { 389 pathParameters := map[string]interface{}{ 390 "productId": autorest.Encode("path", productID), 391 "resourceGroupName": autorest.Encode("path", resourceGroupName), 392 "serviceName": autorest.Encode("path", serviceName), 393 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 394 } 395 396 const APIVersion = "2019-01-01" 397 queryParameters := map[string]interface{}{ 398 "api-version": APIVersion, 399 } 400 if len(filter) > 0 { 401 queryParameters["$filter"] = autorest.Encode("query", filter) 402 } 403 if top != nil { 404 queryParameters["$top"] = autorest.Encode("query", *top) 405 } 406 if skip != nil { 407 queryParameters["$skip"] = autorest.Encode("query", *skip) 408 } 409 410 preparer := autorest.CreatePreparer( 411 autorest.AsGet(), 412 autorest.WithBaseURL(client.BaseURI), 413 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/groups", pathParameters), 414 autorest.WithQueryParameters(queryParameters)) 415 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 416} 417 418// ListByProductSender sends the ListByProduct request. The method will close the 419// http.Response Body if it receives an error. 420func (client ProductGroupClient) ListByProductSender(req *http.Request) (*http.Response, error) { 421 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 422 return autorest.SendWithSender(client, req, sd...) 423} 424 425// ListByProductResponder handles the response to the ListByProduct request. The method always 426// closes the http.Response Body. 427func (client ProductGroupClient) ListByProductResponder(resp *http.Response) (result GroupCollection, err error) { 428 err = autorest.Respond( 429 resp, 430 client.ByInspecting(), 431 azure.WithErrorUnlessStatusCode(http.StatusOK), 432 autorest.ByUnmarshallingJSON(&result), 433 autorest.ByClosing()) 434 result.Response = autorest.Response{Response: resp} 435 return 436} 437 438// listByProductNextResults retrieves the next set of results, if any. 439func (client ProductGroupClient) listByProductNextResults(ctx context.Context, lastResults GroupCollection) (result GroupCollection, err error) { 440 req, err := lastResults.groupCollectionPreparer(ctx) 441 if err != nil { 442 return result, autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "listByProductNextResults", nil, "Failure preparing next results request") 443 } 444 if req == nil { 445 return 446 } 447 resp, err := client.ListByProductSender(req) 448 if err != nil { 449 result.Response = autorest.Response{Response: resp} 450 return result, autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "listByProductNextResults", resp, "Failure sending next results request") 451 } 452 result, err = client.ListByProductResponder(resp) 453 if err != nil { 454 err = autorest.NewErrorWithError(err, "apimanagement.ProductGroupClient", "listByProductNextResults", resp, "Failure responding to next results request") 455 } 456 return 457} 458 459// ListByProductComplete enumerates all values, automatically crossing page boundaries as required. 460func (client ProductGroupClient) ListByProductComplete(ctx context.Context, resourceGroupName string, serviceName string, productID string, filter string, top *int32, skip *int32) (result GroupCollectionIterator, err error) { 461 if tracing.IsEnabled() { 462 ctx = tracing.StartSpan(ctx, fqdn+"/ProductGroupClient.ListByProduct") 463 defer func() { 464 sc := -1 465 if result.Response().Response.Response != nil { 466 sc = result.page.Response().Response.Response.StatusCode 467 } 468 tracing.EndSpan(ctx, sc, err) 469 }() 470 } 471 result.page, err = client.ListByProduct(ctx, resourceGroupName, serviceName, productID, filter, top, skip) 472 return 473} 474