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 "net/http" 26) 27 28// LoggerClient is the client for the Logger methods of the Apimanagement service. 29type LoggerClient struct { 30 BaseClient 31} 32 33// NewLoggerClient creates an instance of the LoggerClient client. 34func NewLoggerClient() LoggerClient { 35 return LoggerClient{New()} 36} 37 38// CreateOrUpdate creates or Updates a logger. 39// Parameters: 40// apimBaseURL - the management endpoint of the API Management service, for example 41// https://myapimservice.management.azure-api.net. 42// loggerid - logger identifier. Must be unique in the API Management service instance. 43// parameters - create parameters. 44func (client LoggerClient) CreateOrUpdate(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerContract) (result LoggerContract, err error) { 45 if err := validation.Validate([]validation.Validation{ 46 {TargetValue: loggerid, 47 Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 48 {Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 49 return result, validation.NewError("apimanagement.LoggerClient", "CreateOrUpdate", err.Error()) 50 } 51 52 req, err := client.CreateOrUpdatePreparer(ctx, apimBaseURL, loggerid, parameters) 53 if err != nil { 54 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", nil, "Failure preparing request") 55 return 56 } 57 58 resp, err := client.CreateOrUpdateSender(req) 59 if err != nil { 60 result.Response = autorest.Response{Response: resp} 61 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure sending request") 62 return 63 } 64 65 result, err = client.CreateOrUpdateResponder(resp) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "CreateOrUpdate", resp, "Failure responding to request") 68 } 69 70 return 71} 72 73// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 74func (client LoggerClient) CreateOrUpdatePreparer(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerContract) (*http.Request, error) { 75 urlParameters := map[string]interface{}{ 76 "apimBaseUrl": apimBaseURL, 77 } 78 79 pathParameters := map[string]interface{}{ 80 "loggerid": autorest.Encode("path", loggerid), 81 } 82 83 const APIVersion = "2017-03-01" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsContentType("application/json; charset=utf-8"), 90 autorest.AsPut(), 91 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 92 autorest.WithPathParameters("/loggers/{loggerid}", pathParameters), 93 autorest.WithJSON(parameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 99// http.Response Body if it receives an error. 100func (client LoggerClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 101 return autorest.SendWithSender(client, req, 102 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 103} 104 105// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 106// closes the http.Response Body. 107func (client LoggerClient) CreateOrUpdateResponder(resp *http.Response) (result LoggerContract, err error) { 108 err = autorest.Respond( 109 resp, 110 client.ByInspecting(), 111 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// Delete deletes the specified logger. 119// Parameters: 120// apimBaseURL - the management endpoint of the API Management service, for example 121// https://myapimservice.management.azure-api.net. 122// loggerid - logger identifier. Must be unique in the API Management service instance. 123// ifMatch - the entity state (Etag) version of the logger to delete. A value of "*" can be used for If-Match 124// to unconditionally apply the operation. 125func (client LoggerClient) Delete(ctx context.Context, apimBaseURL string, loggerid string, ifMatch string) (result autorest.Response, err error) { 126 if err := validation.Validate([]validation.Validation{ 127 {TargetValue: loggerid, 128 Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 129 {Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 130 return result, validation.NewError("apimanagement.LoggerClient", "Delete", err.Error()) 131 } 132 133 req, err := client.DeletePreparer(ctx, apimBaseURL, loggerid, ifMatch) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", nil, "Failure preparing request") 136 return 137 } 138 139 resp, err := client.DeleteSender(req) 140 if err != nil { 141 result.Response = resp 142 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure sending request") 143 return 144 } 145 146 result, err = client.DeleteResponder(resp) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Delete", resp, "Failure responding to request") 149 } 150 151 return 152} 153 154// DeletePreparer prepares the Delete request. 155func (client LoggerClient) DeletePreparer(ctx context.Context, apimBaseURL string, loggerid string, ifMatch string) (*http.Request, error) { 156 urlParameters := map[string]interface{}{ 157 "apimBaseUrl": apimBaseURL, 158 } 159 160 pathParameters := map[string]interface{}{ 161 "loggerid": autorest.Encode("path", loggerid), 162 } 163 164 const APIVersion = "2017-03-01" 165 queryParameters := map[string]interface{}{ 166 "api-version": APIVersion, 167 } 168 169 preparer := autorest.CreatePreparer( 170 autorest.AsDelete(), 171 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 172 autorest.WithPathParameters("/loggers/{loggerid}", pathParameters), 173 autorest.WithQueryParameters(queryParameters), 174 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// DeleteSender sends the Delete request. The method will close the 179// http.Response Body if it receives an error. 180func (client LoggerClient) DeleteSender(req *http.Request) (*http.Response, error) { 181 return autorest.SendWithSender(client, req, 182 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 183} 184 185// DeleteResponder handles the response to the Delete request. The method always 186// closes the http.Response Body. 187func (client LoggerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 188 err = autorest.Respond( 189 resp, 190 client.ByInspecting(), 191 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 192 autorest.ByClosing()) 193 result.Response = resp 194 return 195} 196 197// Get gets the details of the logger specified by its identifier. 198// Parameters: 199// apimBaseURL - the management endpoint of the API Management service, for example 200// https://myapimservice.management.azure-api.net. 201// loggerid - logger identifier. Must be unique in the API Management service instance. 202func (client LoggerClient) Get(ctx context.Context, apimBaseURL string, loggerid string) (result LoggerContract, err error) { 203 if err := validation.Validate([]validation.Validation{ 204 {TargetValue: loggerid, 205 Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 206 {Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 207 return result, validation.NewError("apimanagement.LoggerClient", "Get", err.Error()) 208 } 209 210 req, err := client.GetPreparer(ctx, apimBaseURL, loggerid) 211 if err != nil { 212 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", nil, "Failure preparing request") 213 return 214 } 215 216 resp, err := client.GetSender(req) 217 if err != nil { 218 result.Response = autorest.Response{Response: resp} 219 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure sending request") 220 return 221 } 222 223 result, err = client.GetResponder(resp) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Get", resp, "Failure responding to request") 226 } 227 228 return 229} 230 231// GetPreparer prepares the Get request. 232func (client LoggerClient) GetPreparer(ctx context.Context, apimBaseURL string, loggerid string) (*http.Request, error) { 233 urlParameters := map[string]interface{}{ 234 "apimBaseUrl": apimBaseURL, 235 } 236 237 pathParameters := map[string]interface{}{ 238 "loggerid": autorest.Encode("path", loggerid), 239 } 240 241 const APIVersion = "2017-03-01" 242 queryParameters := map[string]interface{}{ 243 "api-version": APIVersion, 244 } 245 246 preparer := autorest.CreatePreparer( 247 autorest.AsGet(), 248 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 249 autorest.WithPathParameters("/loggers/{loggerid}", pathParameters), 250 autorest.WithQueryParameters(queryParameters)) 251 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 252} 253 254// GetSender sends the Get request. The method will close the 255// http.Response Body if it receives an error. 256func (client LoggerClient) GetSender(req *http.Request) (*http.Response, error) { 257 return autorest.SendWithSender(client, req, 258 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 259} 260 261// GetResponder handles the response to the Get request. The method always 262// closes the http.Response Body. 263func (client LoggerClient) GetResponder(resp *http.Response) (result LoggerContract, err error) { 264 err = autorest.Respond( 265 resp, 266 client.ByInspecting(), 267 azure.WithErrorUnlessStatusCode(http.StatusOK), 268 autorest.ByUnmarshallingJSON(&result), 269 autorest.ByClosing()) 270 result.Response = autorest.Response{Response: resp} 271 return 272} 273 274// List lists a collection of loggers in the specified service instance. 275// Parameters: 276// apimBaseURL - the management endpoint of the API Management service, for example 277// https://myapimservice.management.azure-api.net. 278// filter - | Field | Supported operators | Supported functions | 279// |-------|------------------------|---------------------------------------------| 280// | id | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 281// | type | eq | | 282// top - number of records to return. 283// skip - number of records to skip. 284func (client LoggerClient) List(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result LoggerCollectionPage, err error) { 285 if err := validation.Validate([]validation.Validation{ 286 {TargetValue: top, 287 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 288 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}}, 289 {TargetValue: skip, 290 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 291 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil { 292 return result, validation.NewError("apimanagement.LoggerClient", "List", err.Error()) 293 } 294 295 result.fn = client.listNextResults 296 req, err := client.ListPreparer(ctx, apimBaseURL, filter, top, skip) 297 if err != nil { 298 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", nil, "Failure preparing request") 299 return 300 } 301 302 resp, err := client.ListSender(req) 303 if err != nil { 304 result.lc.Response = autorest.Response{Response: resp} 305 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", resp, "Failure sending request") 306 return 307 } 308 309 result.lc, err = client.ListResponder(resp) 310 if err != nil { 311 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "List", resp, "Failure responding to request") 312 } 313 314 return 315} 316 317// ListPreparer prepares the List request. 318func (client LoggerClient) ListPreparer(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (*http.Request, error) { 319 urlParameters := map[string]interface{}{ 320 "apimBaseUrl": apimBaseURL, 321 } 322 323 const APIVersion = "2017-03-01" 324 queryParameters := map[string]interface{}{ 325 "api-version": APIVersion, 326 } 327 if len(filter) > 0 { 328 queryParameters["$filter"] = autorest.Encode("query", filter) 329 } 330 if top != nil { 331 queryParameters["$top"] = autorest.Encode("query", *top) 332 } 333 if skip != nil { 334 queryParameters["$skip"] = autorest.Encode("query", *skip) 335 } 336 337 preparer := autorest.CreatePreparer( 338 autorest.AsGet(), 339 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 340 autorest.WithPath("/loggers"), 341 autorest.WithQueryParameters(queryParameters)) 342 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 343} 344 345// ListSender sends the List request. The method will close the 346// http.Response Body if it receives an error. 347func (client LoggerClient) ListSender(req *http.Request) (*http.Response, error) { 348 return autorest.SendWithSender(client, req, 349 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 350} 351 352// ListResponder handles the response to the List request. The method always 353// closes the http.Response Body. 354func (client LoggerClient) ListResponder(resp *http.Response) (result LoggerCollection, err error) { 355 err = autorest.Respond( 356 resp, 357 client.ByInspecting(), 358 azure.WithErrorUnlessStatusCode(http.StatusOK), 359 autorest.ByUnmarshallingJSON(&result), 360 autorest.ByClosing()) 361 result.Response = autorest.Response{Response: resp} 362 return 363} 364 365// listNextResults retrieves the next set of results, if any. 366func (client LoggerClient) listNextResults(lastResults LoggerCollection) (result LoggerCollection, err error) { 367 req, err := lastResults.loggerCollectionPreparer() 368 if err != nil { 369 return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", nil, "Failure preparing next results request") 370 } 371 if req == nil { 372 return 373 } 374 resp, err := client.ListSender(req) 375 if err != nil { 376 result.Response = autorest.Response{Response: resp} 377 return result, autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", resp, "Failure sending next results request") 378 } 379 result, err = client.ListResponder(resp) 380 if err != nil { 381 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "listNextResults", resp, "Failure responding to next results request") 382 } 383 return 384} 385 386// ListComplete enumerates all values, automatically crossing page boundaries as required. 387func (client LoggerClient) ListComplete(ctx context.Context, apimBaseURL string, filter string, top *int32, skip *int32) (result LoggerCollectionIterator, err error) { 388 result.page, err = client.List(ctx, apimBaseURL, filter, top, skip) 389 return 390} 391 392// Update updates an existing logger. 393// Parameters: 394// apimBaseURL - the management endpoint of the API Management service, for example 395// https://myapimservice.management.azure-api.net. 396// loggerid - logger identifier. Must be unique in the API Management service instance. 397// parameters - update parameters. 398// ifMatch - the entity state (Etag) version of the logger to update. A value of "*" can be used for If-Match 399// to unconditionally apply the operation. 400func (client LoggerClient) Update(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerUpdateContract, ifMatch string) (result autorest.Response, err error) { 401 if err := validation.Validate([]validation.Validation{ 402 {TargetValue: loggerid, 403 Constraints: []validation.Constraint{{Target: "loggerid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 404 {Target: "loggerid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 405 return result, validation.NewError("apimanagement.LoggerClient", "Update", err.Error()) 406 } 407 408 req, err := client.UpdatePreparer(ctx, apimBaseURL, loggerid, parameters, ifMatch) 409 if err != nil { 410 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", nil, "Failure preparing request") 411 return 412 } 413 414 resp, err := client.UpdateSender(req) 415 if err != nil { 416 result.Response = resp 417 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure sending request") 418 return 419 } 420 421 result, err = client.UpdateResponder(resp) 422 if err != nil { 423 err = autorest.NewErrorWithError(err, "apimanagement.LoggerClient", "Update", resp, "Failure responding to request") 424 } 425 426 return 427} 428 429// UpdatePreparer prepares the Update request. 430func (client LoggerClient) UpdatePreparer(ctx context.Context, apimBaseURL string, loggerid string, parameters LoggerUpdateContract, ifMatch string) (*http.Request, error) { 431 urlParameters := map[string]interface{}{ 432 "apimBaseUrl": apimBaseURL, 433 } 434 435 pathParameters := map[string]interface{}{ 436 "loggerid": autorest.Encode("path", loggerid), 437 } 438 439 const APIVersion = "2017-03-01" 440 queryParameters := map[string]interface{}{ 441 "api-version": APIVersion, 442 } 443 444 preparer := autorest.CreatePreparer( 445 autorest.AsContentType("application/json; charset=utf-8"), 446 autorest.AsPatch(), 447 autorest.WithCustomBaseURL("{apimBaseUrl}", urlParameters), 448 autorest.WithPathParameters("/loggers/{loggerid}", pathParameters), 449 autorest.WithJSON(parameters), 450 autorest.WithQueryParameters(queryParameters), 451 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 452 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 453} 454 455// UpdateSender sends the Update request. The method will close the 456// http.Response Body if it receives an error. 457func (client LoggerClient) UpdateSender(req *http.Request) (*http.Response, error) { 458 return autorest.SendWithSender(client, req, 459 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 460} 461 462// UpdateResponder handles the response to the Update request. The method always 463// closes the http.Response Body. 464func (client LoggerClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 465 err = autorest.Respond( 466 resp, 467 client.ByInspecting(), 468 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 469 autorest.ByClosing()) 470 result.Response = resp 471 return 472} 473