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