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// CertificatesClient is the apiManagement Client 29type CertificatesClient struct { 30 BaseClient 31} 32 33// NewCertificatesClient creates an instance of the CertificatesClient client. 34func NewCertificatesClient(subscriptionID string) CertificatesClient { 35 return NewCertificatesClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewCertificatesClientWithBaseURI creates an instance of the CertificatesClient client. 39func NewCertificatesClientWithBaseURI(baseURI string, subscriptionID string) CertificatesClient { 40 return CertificatesClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// CreateOrUpdate creates or updates the certificate being used for authentication with the backend. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// serviceName - the name of the API Management service. 47// certificateID - identifier of the certificate entity. Must be unique in the current API Management service 48// instance. 49// parameters - create parameters. 50// ifMatch - the entity state (Etag) version of the certificate to update. A value of "*" can be used for 51// If-Match to unconditionally apply the operation.. 52func (client CertificatesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, certificateID string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (result autorest.Response, 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: certificateID, 59 Constraints: []validation.Constraint{{Target: "certificateID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 60 {Target: "certificateID", Name: validation.MinLength, Rule: 1, Chain: nil}, 61 {Target: "certificateID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}, 62 {TargetValue: parameters, 63 Constraints: []validation.Constraint{{Target: "parameters.Data", Name: validation.Null, Rule: true, Chain: nil}, 64 {Target: "parameters.Password", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("apimanagement.CertificatesClient", "CreateOrUpdate", err.Error()) 66 } 67 68 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, certificateID, parameters, ifMatch) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "CreateOrUpdate", nil, "Failure preparing request") 71 return 72 } 73 74 resp, err := client.CreateOrUpdateSender(req) 75 if err != nil { 76 result.Response = resp 77 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "CreateOrUpdate", resp, "Failure sending request") 78 return 79 } 80 81 result, err = client.CreateOrUpdateResponder(resp) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "CreateOrUpdate", resp, "Failure responding to request") 84 } 85 86 return 87} 88 89// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 90func (client CertificatesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, certificateID string, parameters CertificateCreateOrUpdateParameters, ifMatch string) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "certificateId": autorest.Encode("path", certificateID), 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "serviceName": autorest.Encode("path", serviceName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2016-10-10" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/certificates/{certificateId}", pathParameters), 108 autorest.WithJSON(parameters), 109 autorest.WithQueryParameters(queryParameters)) 110 if len(ifMatch) > 0 { 111 preparer = autorest.DecoratePreparer(preparer, 112 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 113 } 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 118// http.Response Body if it receives an error. 119func (client CertificatesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 120 return autorest.SendWithSender(client, req, 121 azure.DoRetryWithRegistration(client.Client)) 122} 123 124// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 125// closes the http.Response Body. 126func (client CertificatesClient) CreateOrUpdateResponder(resp *http.Response) (result autorest.Response, err error) { 127 err = autorest.Respond( 128 resp, 129 client.ByInspecting(), 130 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusNoContent), 131 autorest.ByClosing()) 132 result.Response = resp 133 return 134} 135 136// Delete deletes specific certificate. 137// Parameters: 138// resourceGroupName - the name of the resource group. 139// serviceName - the name of the API Management service. 140// certificateID - identifier of the certificate entity. Must be unique in the current API Management service 141// instance. 142// ifMatch - the entity state (Etag) version of the certificate to delete. A value of "*" can be used for 143// If-Match to unconditionally apply the operation. 144func (client CertificatesClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, certificateID string, ifMatch string) (result autorest.Response, err error) { 145 if err := validation.Validate([]validation.Validation{ 146 {TargetValue: serviceName, 147 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 148 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 149 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 150 {TargetValue: certificateID, 151 Constraints: []validation.Constraint{{Target: "certificateID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 152 {Target: "certificateID", Name: validation.MinLength, Rule: 1, Chain: nil}, 153 {Target: "certificateID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 154 return result, validation.NewError("apimanagement.CertificatesClient", "Delete", err.Error()) 155 } 156 157 req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, certificateID, ifMatch) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Delete", nil, "Failure preparing request") 160 return 161 } 162 163 resp, err := client.DeleteSender(req) 164 if err != nil { 165 result.Response = resp 166 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Delete", resp, "Failure sending request") 167 return 168 } 169 170 result, err = client.DeleteResponder(resp) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Delete", resp, "Failure responding to request") 173 } 174 175 return 176} 177 178// DeletePreparer prepares the Delete request. 179func (client CertificatesClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, certificateID string, ifMatch string) (*http.Request, error) { 180 pathParameters := map[string]interface{}{ 181 "certificateId": autorest.Encode("path", certificateID), 182 "resourceGroupName": autorest.Encode("path", resourceGroupName), 183 "serviceName": autorest.Encode("path", serviceName), 184 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 185 } 186 187 const APIVersion = "2016-10-10" 188 queryParameters := map[string]interface{}{ 189 "api-version": APIVersion, 190 } 191 192 preparer := autorest.CreatePreparer( 193 autorest.AsDelete(), 194 autorest.WithBaseURL(client.BaseURI), 195 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/certificates/{certificateId}", pathParameters), 196 autorest.WithQueryParameters(queryParameters), 197 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 198 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 199} 200 201// DeleteSender sends the Delete request. The method will close the 202// http.Response Body if it receives an error. 203func (client CertificatesClient) DeleteSender(req *http.Request) (*http.Response, error) { 204 return autorest.SendWithSender(client, req, 205 azure.DoRetryWithRegistration(client.Client)) 206} 207 208// DeleteResponder handles the response to the Delete request. The method always 209// closes the http.Response Body. 210func (client CertificatesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 211 err = autorest.Respond( 212 resp, 213 client.ByInspecting(), 214 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 215 autorest.ByClosing()) 216 result.Response = resp 217 return 218} 219 220// Get gets the details of the certificate specified by its identifier. 221// Parameters: 222// resourceGroupName - the name of the resource group. 223// serviceName - the name of the API Management service. 224// certificateID - identifier of the certificate entity. Must be unique in the current API Management service 225// instance. 226func (client CertificatesClient) Get(ctx context.Context, resourceGroupName string, serviceName string, certificateID string) (result CertificateContract, err error) { 227 if err := validation.Validate([]validation.Validation{ 228 {TargetValue: serviceName, 229 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 230 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 231 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 232 {TargetValue: certificateID, 233 Constraints: []validation.Constraint{{Target: "certificateID", Name: validation.MaxLength, Rule: 256, Chain: nil}, 234 {Target: "certificateID", Name: validation.MinLength, Rule: 1, Chain: nil}, 235 {Target: "certificateID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 236 return result, validation.NewError("apimanagement.CertificatesClient", "Get", err.Error()) 237 } 238 239 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, certificateID) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Get", nil, "Failure preparing request") 242 return 243 } 244 245 resp, err := client.GetSender(req) 246 if err != nil { 247 result.Response = autorest.Response{Response: resp} 248 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Get", resp, "Failure sending request") 249 return 250 } 251 252 result, err = client.GetResponder(resp) 253 if err != nil { 254 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "Get", resp, "Failure responding to request") 255 } 256 257 return 258} 259 260// GetPreparer prepares the Get request. 261func (client CertificatesClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, certificateID string) (*http.Request, error) { 262 pathParameters := map[string]interface{}{ 263 "certificateId": autorest.Encode("path", certificateID), 264 "resourceGroupName": autorest.Encode("path", resourceGroupName), 265 "serviceName": autorest.Encode("path", serviceName), 266 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 267 } 268 269 const APIVersion = "2016-10-10" 270 queryParameters := map[string]interface{}{ 271 "api-version": APIVersion, 272 } 273 274 preparer := autorest.CreatePreparer( 275 autorest.AsGet(), 276 autorest.WithBaseURL(client.BaseURI), 277 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/certificates/{certificateId}", pathParameters), 278 autorest.WithQueryParameters(queryParameters)) 279 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 280} 281 282// GetSender sends the Get request. The method will close the 283// http.Response Body if it receives an error. 284func (client CertificatesClient) GetSender(req *http.Request) (*http.Response, error) { 285 return autorest.SendWithSender(client, req, 286 azure.DoRetryWithRegistration(client.Client)) 287} 288 289// GetResponder handles the response to the Get request. The method always 290// closes the http.Response Body. 291func (client CertificatesClient) GetResponder(resp *http.Response) (result CertificateContract, err error) { 292 err = autorest.Respond( 293 resp, 294 client.ByInspecting(), 295 azure.WithErrorUnlessStatusCode(http.StatusOK), 296 autorest.ByUnmarshallingJSON(&result), 297 autorest.ByClosing()) 298 result.Response = autorest.Response{Response: resp} 299 return 300} 301 302// ListByService lists a collection of all certificates in the specified service instance. 303// Parameters: 304// resourceGroupName - the name of the resource group. 305// serviceName - the name of the API Management service. 306// filter - | Field | Supported operators | Supported functions | 307// |----------------|------------------------|---------------------------------------------| 308// | id | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 309// | subject | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 310// | thumbprint | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith | 311// | expirationDate | ge, le, eq, ne, gt, lt | N/A | 312// top - number of records to return. 313// skip - number of records to skip. 314func (client CertificatesClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result CertificateCollectionPage, err error) { 315 if err := validation.Validate([]validation.Validation{ 316 {TargetValue: serviceName, 317 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 318 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 319 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 320 {TargetValue: top, 321 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 322 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}}, 323 {TargetValue: skip, 324 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 325 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil { 326 return result, validation.NewError("apimanagement.CertificatesClient", "ListByService", err.Error()) 327 } 328 329 result.fn = client.listByServiceNextResults 330 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "ListByService", nil, "Failure preparing request") 333 return 334 } 335 336 resp, err := client.ListByServiceSender(req) 337 if err != nil { 338 result.cc.Response = autorest.Response{Response: resp} 339 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "ListByService", resp, "Failure sending request") 340 return 341 } 342 343 result.cc, err = client.ListByServiceResponder(resp) 344 if err != nil { 345 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "ListByService", resp, "Failure responding to request") 346 } 347 348 return 349} 350 351// ListByServicePreparer prepares the ListByService request. 352func (client CertificatesClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) { 353 pathParameters := map[string]interface{}{ 354 "resourceGroupName": autorest.Encode("path", resourceGroupName), 355 "serviceName": autorest.Encode("path", serviceName), 356 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 357 } 358 359 const APIVersion = "2016-10-10" 360 queryParameters := map[string]interface{}{ 361 "api-version": APIVersion, 362 } 363 if len(filter) > 0 { 364 queryParameters["$filter"] = autorest.Encode("query", filter) 365 } 366 if top != nil { 367 queryParameters["$top"] = autorest.Encode("query", *top) 368 } 369 if skip != nil { 370 queryParameters["$skip"] = autorest.Encode("query", *skip) 371 } 372 373 preparer := autorest.CreatePreparer( 374 autorest.AsGet(), 375 autorest.WithBaseURL(client.BaseURI), 376 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/certificates", pathParameters), 377 autorest.WithQueryParameters(queryParameters)) 378 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 379} 380 381// ListByServiceSender sends the ListByService request. The method will close the 382// http.Response Body if it receives an error. 383func (client CertificatesClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 384 return autorest.SendWithSender(client, req, 385 azure.DoRetryWithRegistration(client.Client)) 386} 387 388// ListByServiceResponder handles the response to the ListByService request. The method always 389// closes the http.Response Body. 390func (client CertificatesClient) ListByServiceResponder(resp *http.Response) (result CertificateCollection, err error) { 391 err = autorest.Respond( 392 resp, 393 client.ByInspecting(), 394 azure.WithErrorUnlessStatusCode(http.StatusOK), 395 autorest.ByUnmarshallingJSON(&result), 396 autorest.ByClosing()) 397 result.Response = autorest.Response{Response: resp} 398 return 399} 400 401// listByServiceNextResults retrieves the next set of results, if any. 402func (client CertificatesClient) listByServiceNextResults(lastResults CertificateCollection) (result CertificateCollection, err error) { 403 req, err := lastResults.certificateCollectionPreparer() 404 if err != nil { 405 return result, autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "listByServiceNextResults", nil, "Failure preparing next results request") 406 } 407 if req == nil { 408 return 409 } 410 resp, err := client.ListByServiceSender(req) 411 if err != nil { 412 result.Response = autorest.Response{Response: resp} 413 return result, autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "listByServiceNextResults", resp, "Failure sending next results request") 414 } 415 result, err = client.ListByServiceResponder(resp) 416 if err != nil { 417 err = autorest.NewErrorWithError(err, "apimanagement.CertificatesClient", "listByServiceNextResults", resp, "Failure responding to next results request") 418 } 419 return 420} 421 422// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 423func (client CertificatesClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result CertificateCollectionIterator, err error) { 424 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip) 425 return 426} 427