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