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// ProtectionPolicyOperationStatusesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
18type ProtectionPolicyOperationStatusesClient struct {
19	BaseClient
20}
21
22// NewProtectionPolicyOperationStatusesClient creates an instance of the ProtectionPolicyOperationStatusesClient
23// client.
24func NewProtectionPolicyOperationStatusesClient(subscriptionID string) ProtectionPolicyOperationStatusesClient {
25	return NewProtectionPolicyOperationStatusesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewProtectionPolicyOperationStatusesClientWithBaseURI creates an instance of the
29// ProtectionPolicyOperationStatusesClient client using a custom endpoint.  Use this when interacting with an Azure
30// cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
31func NewProtectionPolicyOperationStatusesClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPolicyOperationStatusesClient {
32	return ProtectionPolicyOperationStatusesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// Get provides the status of the asynchronous operations like backup, restore. The status can be in progress,
36// completed
37// or failed. You can refer to the Operation Status enum for all the possible states of an operation. Some operations
38// create jobs. This method returns the list of jobs associated with operation.
39// Parameters:
40// vaultName - the name of the recovery services vault.
41// resourceGroupName - the name of the resource group where the recovery services vault is present.
42// policyName - backup policy name whose operation's status needs to be fetched.
43// operationID - operation ID which represents an operation whose status needs to be fetched.
44func (client ProtectionPolicyOperationStatusesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (result OperationStatus, err error) {
45	if tracing.IsEnabled() {
46		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPolicyOperationStatusesClient.Get")
47		defer func() {
48			sc := -1
49			if result.Response.Response != nil {
50				sc = result.Response.Response.StatusCode
51			}
52			tracing.EndSpan(ctx, sc, err)
53		}()
54	}
55	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName, operationID)
56	if err != nil {
57		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", nil, "Failure preparing request")
58		return
59	}
60
61	resp, err := client.GetSender(req)
62	if err != nil {
63		result.Response = autorest.Response{Response: resp}
64		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", resp, "Failure sending request")
65		return
66	}
67
68	result, err = client.GetResponder(resp)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", resp, "Failure responding to request")
71		return
72	}
73
74	return
75}
76
77// GetPreparer prepares the Get request.
78func (client ProtectionPolicyOperationStatusesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"operationId":       autorest.Encode("path", operationID),
81		"policyName":        autorest.Encode("path", policyName),
82		"resourceGroupName": autorest.Encode("path", resourceGroupName),
83		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
84		"vaultName":         autorest.Encode("path", vaultName),
85	}
86
87	const APIVersion = "2021-01-01"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsGet(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}/operations/{operationId}", pathParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// GetSender sends the Get request. The method will close the
101// http.Response Body if it receives an error.
102func (client ProtectionPolicyOperationStatusesClient) GetSender(req *http.Request) (*http.Response, error) {
103	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
104}
105
106// GetResponder handles the response to the Get request. The method always
107// closes the http.Response Body.
108func (client ProtectionPolicyOperationStatusesClient) GetResponder(resp *http.Response) (result OperationStatus, err error) {
109	err = autorest.Respond(
110		resp,
111		azure.WithErrorUnlessStatusCode(http.StatusOK),
112		autorest.ByUnmarshallingJSON(&result),
113		autorest.ByClosing())
114	result.Response = autorest.Response{Response: resp}
115	return
116}
117