1 package backup
2
3
4
5
6
7
8
9 import (
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
18 type ProtectionIntentGroupClient struct {
19 BaseClient
20 }
21
22
23 func NewProtectionIntentGroupClient(subscriptionID string) ProtectionIntentGroupClient {
24 return NewProtectionIntentGroupClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewProtectionIntentGroupClientWithBaseURI(baseURI string, subscriptionID string) ProtectionIntentGroupClient {
31 return ProtectionIntentGroupClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client ProtectionIntentGroupClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectionIntentResourceListPage, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentGroupClient.List")
43 defer func() {
44 sc := -1
45 if result.pirl.Response.Response != nil {
46 sc = result.pirl.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 result.fn = client.listNextResults
52 req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter, skipToken)
53 if err != nil {
54 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", nil, "Failure preparing request")
55 return
56 }
57
58 resp, err := client.ListSender(req)
59 if err != nil {
60 result.pirl.Response = autorest.Response{Response: resp}
61 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", resp, "Failure sending request")
62 return
63 }
64
65 result.pirl, err = client.ListResponder(resp)
66 if err != nil {
67 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", resp, "Failure responding to request")
68 return
69 }
70 if result.pirl.hasNextLink() && result.pirl.IsEmpty() {
71 err = result.NextWithContext(ctx)
72 return
73 }
74
75 return
76 }
77
78
79 func (client ProtectionIntentGroupClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (*http.Request, error) {
80 pathParameters := map[string]interface{}{
81 "resourceGroupName": autorest.Encode("path", resourceGroupName),
82 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
83 "vaultName": autorest.Encode("path", vaultName),
84 }
85
86 const APIVersion = "2022-03-01"
87 queryParameters := map[string]interface{}{
88 "api-version": APIVersion,
89 }
90 if len(filter) > 0 {
91 queryParameters["$filter"] = autorest.Encode("query", filter)
92 }
93 if len(skipToken) > 0 {
94 queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
95 }
96
97 preparer := autorest.CreatePreparer(
98 autorest.AsGet(),
99 autorest.WithBaseURL(client.BaseURI),
100 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectionIntents", pathParameters),
101 autorest.WithQueryParameters(queryParameters))
102 return preparer.Prepare((&http.Request{}).WithContext(ctx))
103 }
104
105
106
107 func (client ProtectionIntentGroupClient) ListSender(req *http.Request) (*http.Response, error) {
108 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109 }
110
111
112
113 func (client ProtectionIntentGroupClient) ListResponder(resp *http.Response) (result ProtectionIntentResourceList, err error) {
114 err = autorest.Respond(
115 resp,
116 azure.WithErrorUnlessStatusCode(http.StatusOK),
117 autorest.ByUnmarshallingJSON(&result),
118 autorest.ByClosing())
119 result.Response = autorest.Response{Response: resp}
120 return
121 }
122
123
124 func (client ProtectionIntentGroupClient) listNextResults(ctx context.Context, lastResults ProtectionIntentResourceList) (result ProtectionIntentResourceList, err error) {
125 req, err := lastResults.protectionIntentResourceListPreparer(ctx)
126 if err != nil {
127 return result, autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", nil, "Failure preparing next results request")
128 }
129 if req == nil {
130 return
131 }
132 resp, err := client.ListSender(req)
133 if err != nil {
134 result.Response = autorest.Response{Response: resp}
135 return result, autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", resp, "Failure sending next results request")
136 }
137 result, err = client.ListResponder(resp)
138 if err != nil {
139 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", resp, "Failure responding to next results request")
140 }
141 return
142 }
143
144
145 func (client ProtectionIntentGroupClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectionIntentResourceListIterator, err error) {
146 if tracing.IsEnabled() {
147 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentGroupClient.List")
148 defer func() {
149 sc := -1
150 if result.Response().Response.Response != nil {
151 sc = result.page.Response().Response.Response.StatusCode
152 }
153 tracing.EndSpan(ctx, sc, err)
154 }()
155 }
156 result.page, err = client.List(ctx, vaultName, resourceGroupName, filter, skipToken)
157 return
158 }
159
View as plain text