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// UserConfirmationPasswordClient is the apiManagement Client 30type UserConfirmationPasswordClient struct { 31 BaseClient 32} 33 34// NewUserConfirmationPasswordClient creates an instance of the UserConfirmationPasswordClient client. 35func NewUserConfirmationPasswordClient(subscriptionID string) UserConfirmationPasswordClient { 36 return NewUserConfirmationPasswordClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewUserConfirmationPasswordClientWithBaseURI creates an instance of the UserConfirmationPasswordClient client using 40// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 41// clouds, Azure stack). 42func NewUserConfirmationPasswordClientWithBaseURI(baseURI string, subscriptionID string) UserConfirmationPasswordClient { 43 return UserConfirmationPasswordClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// SendMethod sends confirmation 47// Parameters: 48// resourceGroupName - the name of the resource group. 49// serviceName - the name of the API Management service. 50// userID - user identifier. Must be unique in the current API Management service instance. 51func (client UserConfirmationPasswordClient) SendMethod(ctx context.Context, resourceGroupName string, serviceName string, userID string) (result autorest.Response, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/UserConfirmationPasswordClient.SendMethod") 54 defer func() { 55 sc := -1 56 if result.Response != nil { 57 sc = result.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: serviceName, 64 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 65 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 67 {TargetValue: userID, 68 Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil}, 69 {Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("apimanagement.UserConfirmationPasswordClient", "SendMethod", err.Error()) 71 } 72 73 req, err := client.SendMethodPreparer(ctx, resourceGroupName, serviceName, userID) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", nil, "Failure preparing request") 76 return 77 } 78 79 resp, err := client.SendMethodSender(req) 80 if err != nil { 81 result.Response = resp 82 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure sending request") 83 return 84 } 85 86 result, err = client.SendMethodResponder(resp) 87 if err != nil { 88 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure responding to request") 89 } 90 91 return 92} 93 94// SendMethodPreparer prepares the SendMethod request. 95func (client UserConfirmationPasswordClient) SendMethodPreparer(ctx context.Context, resourceGroupName string, serviceName string, userID string) (*http.Request, error) { 96 pathParameters := map[string]interface{}{ 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "serviceName": autorest.Encode("path", serviceName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 "userId": autorest.Encode("path", userID), 101 } 102 103 const APIVersion = "2019-12-01" 104 queryParameters := map[string]interface{}{ 105 "api-version": APIVersion, 106 } 107 108 preparer := autorest.CreatePreparer( 109 autorest.AsPost(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{userId}/confirmations/password/send", pathParameters), 112 autorest.WithQueryParameters(queryParameters)) 113 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 114} 115 116// SendMethodSender sends the SendMethod request. The method will close the 117// http.Response Body if it receives an error. 118func (client UserConfirmationPasswordClient) SendMethodSender(req *http.Request) (*http.Response, error) { 119 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120} 121 122// SendMethodResponder handles the response to the SendMethod request. The method always 123// closes the http.Response Body. 124func (client UserConfirmationPasswordClient) SendMethodResponder(resp *http.Response) (result autorest.Response, err error) { 125 err = autorest.Respond( 126 resp, 127 client.ByInspecting(), 128 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 129 autorest.ByClosing()) 130 result.Response = resp 131 return 132} 133