1package backup
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/tracing"
14	"net/http"
15)
16
17// SecurityPINsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
18type SecurityPINsClient struct {
19	BaseClient
20}
21
22// NewSecurityPINsClient creates an instance of the SecurityPINsClient client.
23func NewSecurityPINsClient(subscriptionID string) SecurityPINsClient {
24	return NewSecurityPINsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewSecurityPINsClientWithBaseURI creates an instance of the SecurityPINsClient client using a custom endpoint.  Use
28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewSecurityPINsClientWithBaseURI(baseURI string, subscriptionID string) SecurityPINsClient {
30	return SecurityPINsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// Get get the security PIN.
34// Parameters:
35// vaultName - the name of the recovery services vault.
36// resourceGroupName - the name of the resource group where the recovery services vault is present.
37func (client SecurityPINsClient) Get(ctx context.Context, vaultName string, resourceGroupName string) (result TokenInformation, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/SecurityPINsClient.Get")
40		defer func() {
41			sc := -1
42			if result.Response.Response != nil {
43				sc = result.Response.Response.StatusCode
44			}
45			tracing.EndSpan(ctx, sc, err)
46		}()
47	}
48	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "backup.SecurityPINsClient", "Get", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.GetSender(req)
55	if err != nil {
56		result.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "backup.SecurityPINsClient", "Get", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.GetResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "backup.SecurityPINsClient", "Get", resp, "Failure responding to request")
64		return
65	}
66
67	return
68}
69
70// GetPreparer prepares the Get request.
71func (client SecurityPINsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string) (*http.Request, error) {
72	pathParameters := map[string]interface{}{
73		"resourceGroupName": autorest.Encode("path", resourceGroupName),
74		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
75		"vaultName":         autorest.Encode("path", vaultName),
76	}
77
78	const APIVersion = "2021-01-01"
79	queryParameters := map[string]interface{}{
80		"api-version": APIVersion,
81	}
82
83	preparer := autorest.CreatePreparer(
84		autorest.AsPost(),
85		autorest.WithBaseURL(client.BaseURI),
86		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupSecurityPIN", pathParameters),
87		autorest.WithQueryParameters(queryParameters))
88	return preparer.Prepare((&http.Request{}).WithContext(ctx))
89}
90
91// GetSender sends the Get request. The method will close the
92// http.Response Body if it receives an error.
93func (client SecurityPINsClient) GetSender(req *http.Request) (*http.Response, error) {
94	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
95}
96
97// GetResponder handles the response to the Get request. The method always
98// closes the http.Response Body.
99func (client SecurityPINsClient) GetResponder(resp *http.Response) (result TokenInformation, err error) {
100	err = autorest.Respond(
101		resp,
102		azure.WithErrorUnlessStatusCode(http.StatusOK),
103		autorest.ByUnmarshallingJSON(&result),
104		autorest.ByClosing())
105	result.Response = autorest.Response{Response: resp}
106	return
107}
108