1// Package backup implements the Azure ARM Backup service API version .
2//
3// Open API 2.0 Specs for Azure RecoveryServices Backup service
4package backup
5
6// Copyright (c) Microsoft and contributors.  All rights reserved.
7//
8// Licensed under the Apache License, Version 2.0 (the "License");
9// you may not use this file except in compliance with the License.
10// You may obtain a copy of the License at
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16//
17// See the License for the specific language governing permissions and
18// limitations under the License.
19//
20// Code generated by Microsoft (R) AutoRest Code Generator.
21// Changes may cause incorrect behavior and will be lost if the code is regenerated.
22
23import (
24	"context"
25	"github.com/Azure/go-autorest/autorest"
26	"github.com/Azure/go-autorest/autorest/azure"
27	"github.com/Azure/go-autorest/tracing"
28	"net/http"
29)
30
31const (
32	// DefaultBaseURI is the default URI used for the service Backup
33	DefaultBaseURI = "https://management.azure.com"
34)
35
36// BaseClient is the base client for Backup.
37type BaseClient struct {
38	autorest.Client
39	BaseURI        string
40	SubscriptionID string
41}
42
43// New creates an instance of the BaseClient client.
44func New(subscriptionID string) BaseClient {
45	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
46}
47
48// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
49// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
50func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
51	return BaseClient{
52		Client:         autorest.NewClientWithUserAgent(UserAgent()),
53		BaseURI:        baseURI,
54		SubscriptionID: subscriptionID,
55	}
56}
57
58// GetOperationStatus sends the get operation status request.
59// Parameters:
60// vaultName - the name of the recovery services vault.
61// resourceGroupName - the name of the resource group where the recovery services vault is present.
62// privateEndpointConnectionName - the name of the private endpoint connection.
63// operationID - operation id
64func (client BaseClient) GetOperationStatus(ctx context.Context, vaultName string, resourceGroupName string, privateEndpointConnectionName string, operationID string) (result OperationStatus, err error) {
65	if tracing.IsEnabled() {
66		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetOperationStatus")
67		defer func() {
68			sc := -1
69			if result.Response.Response != nil {
70				sc = result.Response.Response.StatusCode
71			}
72			tracing.EndSpan(ctx, sc, err)
73		}()
74	}
75	req, err := client.GetOperationStatusPreparer(ctx, vaultName, resourceGroupName, privateEndpointConnectionName, operationID)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", nil, "Failure preparing request")
78		return
79	}
80
81	resp, err := client.GetOperationStatusSender(req)
82	if err != nil {
83		result.Response = autorest.Response{Response: resp}
84		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", resp, "Failure sending request")
85		return
86	}
87
88	result, err = client.GetOperationStatusResponder(resp)
89	if err != nil {
90		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", resp, "Failure responding to request")
91		return
92	}
93
94	return
95}
96
97// GetOperationStatusPreparer prepares the GetOperationStatus request.
98func (client BaseClient) GetOperationStatusPreparer(ctx context.Context, vaultName string, resourceGroupName string, privateEndpointConnectionName string, operationID string) (*http.Request, error) {
99	pathParameters := map[string]interface{}{
100		"operationId":                   autorest.Encode("path", operationID),
101		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
102		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
103		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
104		"vaultName":                     autorest.Encode("path", vaultName),
105	}
106
107	const APIVersion = "2020-02-02"
108	queryParameters := map[string]interface{}{
109		"api-version": APIVersion,
110	}
111
112	preparer := autorest.CreatePreparer(
113		autorest.AsGet(),
114		autorest.WithBaseURL(client.BaseURI),
115		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/privateEndpointConnections/{privateEndpointConnectionName}/operationsStatus/{operationId}", pathParameters),
116		autorest.WithQueryParameters(queryParameters))
117	return preparer.Prepare((&http.Request{}).WithContext(ctx))
118}
119
120// GetOperationStatusSender sends the GetOperationStatus request. The method will close the
121// http.Response Body if it receives an error.
122func (client BaseClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) {
123	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
124}
125
126// GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always
127// closes the http.Response Body.
128func (client BaseClient) GetOperationStatusResponder(resp *http.Response) (result OperationStatus, err error) {
129	err = autorest.Respond(
130		resp,
131		azure.WithErrorUnlessStatusCode(http.StatusOK),
132		autorest.ByUnmarshallingJSON(&result),
133		autorest.ByClosing())
134	result.Response = autorest.Response{Response: resp}
135	return
136}
137