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