1package apimanagement
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// UserConfirmationPasswordClient is the apiManagement Client
19type UserConfirmationPasswordClient struct {
20	BaseClient
21}
22
23// NewUserConfirmationPasswordClient creates an instance of the UserConfirmationPasswordClient client.
24func NewUserConfirmationPasswordClient(subscriptionID string) UserConfirmationPasswordClient {
25	return NewUserConfirmationPasswordClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewUserConfirmationPasswordClientWithBaseURI creates an instance of the UserConfirmationPasswordClient client using
29// a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewUserConfirmationPasswordClientWithBaseURI(baseURI string, subscriptionID string) UserConfirmationPasswordClient {
32	return UserConfirmationPasswordClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// SendMethod sends confirmation
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// serviceName - the name of the API Management service.
39// userID - user identifier. Must be unique in the current API Management service instance.
40func (client UserConfirmationPasswordClient) SendMethod(ctx context.Context, resourceGroupName string, serviceName string, userID string) (result autorest.Response, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/UserConfirmationPasswordClient.SendMethod")
43		defer func() {
44			sc := -1
45			if result.Response != nil {
46				sc = result.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	if err := validation.Validate([]validation.Validation{
52		{TargetValue: serviceName,
53			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
54				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
55				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
56		{TargetValue: userID,
57			Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil},
58				{Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
59		return result, validation.NewError("apimanagement.UserConfirmationPasswordClient", "SendMethod", err.Error())
60	}
61
62	req, err := client.SendMethodPreparer(ctx, resourceGroupName, serviceName, userID)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.SendMethodSender(req)
69	if err != nil {
70		result.Response = resp
71		err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.SendMethodResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "apimanagement.UserConfirmationPasswordClient", "SendMethod", resp, "Failure responding to request")
78		return
79	}
80
81	return
82}
83
84// SendMethodPreparer prepares the SendMethod request.
85func (client UserConfirmationPasswordClient) SendMethodPreparer(ctx context.Context, resourceGroupName string, serviceName string, userID string) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"resourceGroupName": autorest.Encode("path", resourceGroupName),
88		"serviceName":       autorest.Encode("path", serviceName),
89		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
90		"userId":            autorest.Encode("path", userID),
91	}
92
93	const APIVersion = "2019-12-01-preview"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsPost(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/users/{userId}/confirmations/password/send", pathParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// SendMethodSender sends the SendMethod request. The method will close the
107// http.Response Body if it receives an error.
108func (client UserConfirmationPasswordClient) SendMethodSender(req *http.Request) (*http.Response, error) {
109	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
110}
111
112// SendMethodResponder handles the response to the SendMethod request. The method always
113// closes the http.Response Body.
114func (client UserConfirmationPasswordClient) SendMethodResponder(resp *http.Response) (result autorest.Response, err error) {
115	err = autorest.Respond(
116		resp,
117		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
118		autorest.ByClosing())
119	result.Response = resp
120	return
121}
122