1package apimanagement 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 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// APIIssueClient is the apiManagement Client 19type APIIssueClient struct { 20 BaseClient 21} 22 23// NewAPIIssueClient creates an instance of the APIIssueClient client. 24func NewAPIIssueClient(subscriptionID string) APIIssueClient { 25 return NewAPIIssueClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewAPIIssueClientWithBaseURI creates an instance of the APIIssueClient client using a custom endpoint. Use this 29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewAPIIssueClientWithBaseURI(baseURI string, subscriptionID string) APIIssueClient { 31 return APIIssueClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates a new Issue for an API or updates an existing one. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38// apiid - API identifier. Must be unique in the current API Management service instance. 39// issueID - issue identifier. Must be unique in the current API Management service instance. 40// parameters - create parameters. 41// ifMatch - eTag of the Issue Entity. ETag should match the current entity state from the header response of 42// the GET request or it should be * for unconditional update. 43func (client APIIssueClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (result IssueContract, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.CreateOrUpdate") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: serviceName, 56 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 57 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 59 {TargetValue: apiid, 60 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 61 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 62 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 63 {TargetValue: issueID, 64 Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 65 {Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 67 {TargetValue: parameters, 68 Constraints: []validation.Constraint{{Target: "parameters.IssueContractProperties", Name: validation.Null, Rule: false, 69 Chain: []validation.Constraint{{Target: "parameters.IssueContractProperties.Title", Name: validation.Null, Rule: true, Chain: nil}, 70 {Target: "parameters.IssueContractProperties.Description", Name: validation.Null, Rule: true, Chain: nil}, 71 {Target: "parameters.IssueContractProperties.UserID", Name: validation.Null, Rule: true, Chain: nil}, 72 }}}}}); err != nil { 73 return result, validation.NewError("apimanagement.APIIssueClient", "CreateOrUpdate", err.Error()) 74 } 75 76 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, parameters, ifMatch) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.CreateOrUpdateSender(req) 83 if err != nil { 84 result.Response = autorest.Response{Response: resp} 85 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure sending request") 86 return 87 } 88 89 result, err = client.CreateOrUpdateResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "CreateOrUpdate", resp, "Failure responding to request") 92 return 93 } 94 95 return 96} 97 98// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 99func (client APIIssueClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, parameters IssueContract, ifMatch string) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "apiId": autorest.Encode("path", apiid), 102 "issueId": autorest.Encode("path", issueID), 103 "resourceGroupName": autorest.Encode("path", resourceGroupName), 104 "serviceName": autorest.Encode("path", serviceName), 105 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 106 } 107 108 const APIVersion = "2017-03-01" 109 queryParameters := map[string]interface{}{ 110 "api-version": APIVersion, 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsContentType("application/json; charset=utf-8"), 115 autorest.AsPut(), 116 autorest.WithBaseURL(client.BaseURI), 117 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters), 118 autorest.WithJSON(parameters), 119 autorest.WithQueryParameters(queryParameters)) 120 if len(ifMatch) > 0 { 121 preparer = autorest.DecoratePreparer(preparer, 122 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 123 } 124 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 125} 126 127// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 128// http.Response Body if it receives an error. 129func (client APIIssueClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 130 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 131} 132 133// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 134// closes the http.Response Body. 135func (client APIIssueClient) CreateOrUpdateResponder(resp *http.Response) (result IssueContract, err error) { 136 err = autorest.Respond( 137 resp, 138 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 139 autorest.ByUnmarshallingJSON(&result), 140 autorest.ByClosing()) 141 result.Response = autorest.Response{Response: resp} 142 return 143} 144 145// Delete deletes the specified Issue from an API. 146// Parameters: 147// resourceGroupName - the name of the resource group. 148// serviceName - the name of the API Management service. 149// apiid - API identifier. Must be unique in the current API Management service instance. 150// issueID - issue identifier. Must be unique in the current API Management service instance. 151// ifMatch - eTag of the Issue Entity. ETag should match the current entity state from the header response of 152// the GET request or it should be * for unconditional update. 153func (client APIIssueClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (result autorest.Response, err error) { 154 if tracing.IsEnabled() { 155 ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Delete") 156 defer func() { 157 sc := -1 158 if result.Response != nil { 159 sc = result.Response.StatusCode 160 } 161 tracing.EndSpan(ctx, sc, err) 162 }() 163 } 164 if err := validation.Validate([]validation.Validation{ 165 {TargetValue: serviceName, 166 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 167 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 168 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 169 {TargetValue: apiid, 170 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 171 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 172 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 173 {TargetValue: issueID, 174 Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 175 {Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil}, 176 {Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 177 return result, validation.NewError("apimanagement.APIIssueClient", "Delete", err.Error()) 178 } 179 180 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, issueID, ifMatch) 181 if err != nil { 182 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", nil, "Failure preparing request") 183 return 184 } 185 186 resp, err := client.DeleteSender(req) 187 if err != nil { 188 result.Response = resp 189 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", resp, "Failure sending request") 190 return 191 } 192 193 result, err = client.DeleteResponder(resp) 194 if err != nil { 195 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Delete", resp, "Failure responding to request") 196 return 197 } 198 199 return 200} 201 202// DeletePreparer prepares the Delete request. 203func (client APIIssueClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string, ifMatch string) (*http.Request, error) { 204 pathParameters := map[string]interface{}{ 205 "apiId": autorest.Encode("path", apiid), 206 "issueId": autorest.Encode("path", issueID), 207 "resourceGroupName": autorest.Encode("path", resourceGroupName), 208 "serviceName": autorest.Encode("path", serviceName), 209 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 210 } 211 212 const APIVersion = "2017-03-01" 213 queryParameters := map[string]interface{}{ 214 "api-version": APIVersion, 215 } 216 217 preparer := autorest.CreatePreparer( 218 autorest.AsDelete(), 219 autorest.WithBaseURL(client.BaseURI), 220 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters), 221 autorest.WithQueryParameters(queryParameters), 222 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 223 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 224} 225 226// DeleteSender sends the Delete request. The method will close the 227// http.Response Body if it receives an error. 228func (client APIIssueClient) DeleteSender(req *http.Request) (*http.Response, error) { 229 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 230} 231 232// DeleteResponder handles the response to the Delete request. The method always 233// closes the http.Response Body. 234func (client APIIssueClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 235 err = autorest.Respond( 236 resp, 237 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 238 autorest.ByClosing()) 239 result.Response = resp 240 return 241} 242 243// Get gets the details of the Issue for an API specified by its identifier. 244// Parameters: 245// resourceGroupName - the name of the resource group. 246// serviceName - the name of the API Management service. 247// apiid - API identifier. Must be unique in the current API Management service instance. 248// issueID - issue identifier. Must be unique in the current API Management service instance. 249func (client APIIssueClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (result IssueContract, err error) { 250 if tracing.IsEnabled() { 251 ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Get") 252 defer func() { 253 sc := -1 254 if result.Response.Response != nil { 255 sc = result.Response.Response.StatusCode 256 } 257 tracing.EndSpan(ctx, sc, err) 258 }() 259 } 260 if err := validation.Validate([]validation.Validation{ 261 {TargetValue: serviceName, 262 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 263 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 264 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 265 {TargetValue: apiid, 266 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 267 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 268 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 269 {TargetValue: issueID, 270 Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 271 {Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil}, 272 {Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 273 return result, validation.NewError("apimanagement.APIIssueClient", "Get", err.Error()) 274 } 275 276 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, issueID) 277 if err != nil { 278 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", nil, "Failure preparing request") 279 return 280 } 281 282 resp, err := client.GetSender(req) 283 if err != nil { 284 result.Response = autorest.Response{Response: resp} 285 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure sending request") 286 return 287 } 288 289 result, err = client.GetResponder(resp) 290 if err != nil { 291 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Get", resp, "Failure responding to request") 292 return 293 } 294 295 return 296} 297 298// GetPreparer prepares the Get request. 299func (client APIIssueClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) { 300 pathParameters := map[string]interface{}{ 301 "apiId": autorest.Encode("path", apiid), 302 "issueId": autorest.Encode("path", issueID), 303 "resourceGroupName": autorest.Encode("path", resourceGroupName), 304 "serviceName": autorest.Encode("path", serviceName), 305 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 306 } 307 308 const APIVersion = "2017-03-01" 309 queryParameters := map[string]interface{}{ 310 "api-version": APIVersion, 311 } 312 313 preparer := autorest.CreatePreparer( 314 autorest.AsGet(), 315 autorest.WithBaseURL(client.BaseURI), 316 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters), 317 autorest.WithQueryParameters(queryParameters)) 318 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 319} 320 321// GetSender sends the Get request. The method will close the 322// http.Response Body if it receives an error. 323func (client APIIssueClient) GetSender(req *http.Request) (*http.Response, error) { 324 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 325} 326 327// GetResponder handles the response to the Get request. The method always 328// closes the http.Response Body. 329func (client APIIssueClient) GetResponder(resp *http.Response) (result IssueContract, err error) { 330 err = autorest.Respond( 331 resp, 332 azure.WithErrorUnlessStatusCode(http.StatusOK), 333 autorest.ByUnmarshallingJSON(&result), 334 autorest.ByClosing()) 335 result.Response = autorest.Response{Response: resp} 336 return 337} 338 339// Head gets the entity state (Etag) version of the Issue for an API specified by its identifier. 340// Parameters: 341// resourceGroupName - the name of the resource group. 342// serviceName - the name of the API Management service. 343// apiid - API identifier. Must be unique in the current API Management service instance. 344// issueID - issue identifier. Must be unique in the current API Management service instance. 345func (client APIIssueClient) Head(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (result autorest.Response, err error) { 346 if tracing.IsEnabled() { 347 ctx = tracing.StartSpan(ctx, fqdn+"/APIIssueClient.Head") 348 defer func() { 349 sc := -1 350 if result.Response != nil { 351 sc = result.Response.StatusCode 352 } 353 tracing.EndSpan(ctx, sc, err) 354 }() 355 } 356 if err := validation.Validate([]validation.Validation{ 357 {TargetValue: serviceName, 358 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 359 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 360 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 361 {TargetValue: apiid, 362 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 363 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 364 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 365 {TargetValue: issueID, 366 Constraints: []validation.Constraint{{Target: "issueID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 367 {Target: "issueID", Name: validation.MinLength, Rule: 1, Chain: nil}, 368 {Target: "issueID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 369 return result, validation.NewError("apimanagement.APIIssueClient", "Head", err.Error()) 370 } 371 372 req, err := client.HeadPreparer(ctx, resourceGroupName, serviceName, apiid, issueID) 373 if err != nil { 374 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", nil, "Failure preparing request") 375 return 376 } 377 378 resp, err := client.HeadSender(req) 379 if err != nil { 380 result.Response = resp 381 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", resp, "Failure sending request") 382 return 383 } 384 385 result, err = client.HeadResponder(resp) 386 if err != nil { 387 err = autorest.NewErrorWithError(err, "apimanagement.APIIssueClient", "Head", resp, "Failure responding to request") 388 return 389 } 390 391 return 392} 393 394// HeadPreparer prepares the Head request. 395func (client APIIssueClient) HeadPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, issueID string) (*http.Request, error) { 396 pathParameters := map[string]interface{}{ 397 "apiId": autorest.Encode("path", apiid), 398 "issueId": autorest.Encode("path", issueID), 399 "resourceGroupName": autorest.Encode("path", resourceGroupName), 400 "serviceName": autorest.Encode("path", serviceName), 401 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 402 } 403 404 const APIVersion = "2017-03-01" 405 queryParameters := map[string]interface{}{ 406 "api-version": APIVersion, 407 } 408 409 preparer := autorest.CreatePreparer( 410 autorest.AsHead(), 411 autorest.WithBaseURL(client.BaseURI), 412 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/issues/{issueId}", pathParameters), 413 autorest.WithQueryParameters(queryParameters)) 414 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 415} 416 417// HeadSender sends the Head request. The method will close the 418// http.Response Body if it receives an error. 419func (client APIIssueClient) HeadSender(req *http.Request) (*http.Response, error) { 420 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 421} 422 423// HeadResponder handles the response to the Head request. The method always 424// closes the http.Response Body. 425func (client APIIssueClient) HeadResponder(resp *http.Response) (result autorest.Response, err error) { 426 err = autorest.Respond( 427 resp, 428 azure.WithErrorUnlessStatusCode(http.StatusOK), 429 autorest.ByClosing()) 430 result.Response = resp 431 return 432} 433