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