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}, 70 {Target: "userID", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 71 return result, validation.NewError("apimanagement.UserConfirmationPasswordClient", "SendMethod", err.Error()) 72 } 73 74 req, err := client.SendMethodPreparer(ctx, resourceGroupName, serviceName, userID) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", nil, "Failure preparing request") 77 return 78 } 79 80 resp, err := client.SendMethodSender(req) 81 if err != nil { 82 result.Response = resp 83 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure sending request") 84 return 85 } 86 87 result, err = client.SendMethodResponder(resp) 88 if err != nil { 89 err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure responding to request") 90 return 91 } 92 93 return 94} 95 96// SendMethodPreparer prepares the SendMethod request. 97func (client UserConfirmationPasswordClient) SendMethodPreparer(ctx context.Context, resourceGroupName string, serviceName string, userID string) (*http.Request, error) { 98 pathParameters := map[string]interface{}{ 99 "resourceGroupName": autorest.Encode("path", resourceGroupName), 100 "serviceName": autorest.Encode("path", serviceName), 101 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 102 "userId": autorest.Encode("path", userID), 103 } 104 105 const APIVersion = "2018-06-01-preview" 106 queryParameters := map[string]interface{}{ 107 "api-version": APIVersion, 108 } 109 110 preparer := autorest.CreatePreparer( 111 autorest.AsPost(), 112 autorest.WithBaseURL(client.BaseURI), 113 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{userId}/confirmations/password/send", pathParameters), 114 autorest.WithQueryParameters(queryParameters)) 115 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 116} 117 118// SendMethodSender sends the SendMethod request. The method will close the 119// http.Response Body if it receives an error. 120func (client UserConfirmationPasswordClient) SendMethodSender(req *http.Request) (*http.Response, error) { 121 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 122} 123 124// SendMethodResponder handles the response to the SendMethod request. The method always 125// closes the http.Response Body. 126func (client UserConfirmationPasswordClient) SendMethodResponder(resp *http.Response) (result autorest.Response, err error) { 127 err = autorest.Respond( 128 resp, 129 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 130 autorest.ByClosing()) 131 result.Response = resp 132 return 133} 134