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