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// AadPropertiesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
18type AadPropertiesClient struct {
19	BaseClient
20}
21
22// NewAadPropertiesClient creates an instance of the AadPropertiesClient client.
23func NewAadPropertiesClient(subscriptionID string) AadPropertiesClient {
24	return NewAadPropertiesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewAadPropertiesClientWithBaseURI creates an instance of the AadPropertiesClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewAadPropertiesClientWithBaseURI(baseURI string, subscriptionID string) AadPropertiesClient {
30	return AadPropertiesClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// Get sends the get request.
34// Parameters:
35// azureRegion - azure region to hit Api
36// filter - oData filter options.
37func (client AadPropertiesClient) Get(ctx context.Context, azureRegion string, filter string) (result AADPropertiesResource, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/AadPropertiesClient.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, azureRegion, filter)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "backup.AadPropertiesClient", "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.AadPropertiesClient", "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.AadPropertiesClient", "Get", resp, "Failure responding to request")
64		return
65	}
66
67	return
68}
69
70// GetPreparer prepares the Get request.
71func (client AadPropertiesClient) GetPreparer(ctx context.Context, azureRegion string, filter string) (*http.Request, error) {
72	pathParameters := map[string]interface{}{
73		"azureRegion":    autorest.Encode("path", azureRegion),
74		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
75	}
76
77	const APIVersion = "2018-12-20"
78	queryParameters := map[string]interface{}{
79		"api-version": APIVersion,
80	}
81	if len(filter) > 0 {
82		queryParameters["$filter"] = autorest.Encode("query", filter)
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsGet(),
87		autorest.WithBaseURL(client.BaseURI),
88		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{azureRegion}/backupAadProperties", 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 AadPropertiesClient) 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 AadPropertiesClient) GetResponder(resp *http.Response) (result AADPropertiesResource, 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