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 ProtectionIntentClient struct {
19 BaseClient
20 }
21
22
23 func NewProtectionIntentClient(subscriptionID string) ProtectionIntentClient {
24 return NewProtectionIntentClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewProtectionIntentClientWithBaseURI(baseURI string, subscriptionID string) ProtectionIntentClient {
31 return ProtectionIntentClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41 func (client ProtectionIntentClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string, parameters ProtectionIntentResource) (result ProtectionIntentResource, err error) {
42 if tracing.IsEnabled() {
43 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.CreateOrUpdate")
44 defer func() {
45 sc := -1
46 if result.Response.Response != nil {
47 sc = result.Response.Response.StatusCode
48 }
49 tracing.EndSpan(ctx, sc, err)
50 }()
51 }
52 req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName, parameters)
53 if err != nil {
54 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", nil, "Failure preparing request")
55 return
56 }
57
58 resp, err := client.CreateOrUpdateSender(req)
59 if err != nil {
60 result.Response = autorest.Response{Response: resp}
61 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", resp, "Failure sending request")
62 return
63 }
64
65 result, err = client.CreateOrUpdateResponder(resp)
66 if err != nil {
67 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", resp, "Failure responding to request")
68 return
69 }
70
71 return
72 }
73
74
75 func (client ProtectionIntentClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string, parameters ProtectionIntentResource) (*http.Request, error) {
76 pathParameters := map[string]interface{}{
77 "fabricName": autorest.Encode("path", fabricName),
78 "intentObjectName": autorest.Encode("path", intentObjectName),
79 "resourceGroupName": autorest.Encode("path", resourceGroupName),
80 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
81 "vaultName": autorest.Encode("path", vaultName),
82 }
83
84 const APIVersion = "2022-03-01"
85 queryParameters := map[string]interface{}{
86 "api-version": APIVersion,
87 }
88
89 preparer := autorest.CreatePreparer(
90 autorest.AsContentType("application/json; charset=utf-8"),
91 autorest.AsPut(),
92 autorest.WithBaseURL(client.BaseURI),
93 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
94 autorest.WithJSON(parameters),
95 autorest.WithQueryParameters(queryParameters))
96 return preparer.Prepare((&http.Request{}).WithContext(ctx))
97 }
98
99
100
101 func (client ProtectionIntentClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
102 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103 }
104
105
106
107 func (client ProtectionIntentClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionIntentResource, err error) {
108 err = autorest.Respond(
109 resp,
110 azure.WithErrorUnlessStatusCode(http.StatusOK),
111 autorest.ByUnmarshallingJSON(&result),
112 autorest.ByClosing())
113 result.Response = autorest.Response{Response: resp}
114 return
115 }
116
117
118
119
120
121
122
123 func (client ProtectionIntentClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (result autorest.Response, err error) {
124 if tracing.IsEnabled() {
125 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Delete")
126 defer func() {
127 sc := -1
128 if result.Response != nil {
129 sc = result.Response.StatusCode
130 }
131 tracing.EndSpan(ctx, sc, err)
132 }()
133 }
134 req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName)
135 if err != nil {
136 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", nil, "Failure preparing request")
137 return
138 }
139
140 resp, err := client.DeleteSender(req)
141 if err != nil {
142 result.Response = resp
143 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", resp, "Failure sending request")
144 return
145 }
146
147 result, err = client.DeleteResponder(resp)
148 if err != nil {
149 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", resp, "Failure responding to request")
150 return
151 }
152
153 return
154 }
155
156
157 func (client ProtectionIntentClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (*http.Request, error) {
158 pathParameters := map[string]interface{}{
159 "fabricName": autorest.Encode("path", fabricName),
160 "intentObjectName": autorest.Encode("path", intentObjectName),
161 "resourceGroupName": autorest.Encode("path", resourceGroupName),
162 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
163 "vaultName": autorest.Encode("path", vaultName),
164 }
165
166 const APIVersion = "2022-03-01"
167 queryParameters := map[string]interface{}{
168 "api-version": APIVersion,
169 }
170
171 preparer := autorest.CreatePreparer(
172 autorest.AsDelete(),
173 autorest.WithBaseURL(client.BaseURI),
174 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
175 autorest.WithQueryParameters(queryParameters))
176 return preparer.Prepare((&http.Request{}).WithContext(ctx))
177 }
178
179
180
181 func (client ProtectionIntentClient) DeleteSender(req *http.Request) (*http.Response, error) {
182 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
183 }
184
185
186
187 func (client ProtectionIntentClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
188 err = autorest.Respond(
189 resp,
190 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
191 autorest.ByClosing())
192 result.Response = resp
193 return
194 }
195
196
197
198
199
200
201
202
203
204 func (client ProtectionIntentClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (result ProtectionIntentResource, err error) {
205 if tracing.IsEnabled() {
206 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Get")
207 defer func() {
208 sc := -1
209 if result.Response.Response != nil {
210 sc = result.Response.Response.StatusCode
211 }
212 tracing.EndSpan(ctx, sc, err)
213 }()
214 }
215 req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName)
216 if err != nil {
217 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", nil, "Failure preparing request")
218 return
219 }
220
221 resp, err := client.GetSender(req)
222 if err != nil {
223 result.Response = autorest.Response{Response: resp}
224 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", resp, "Failure sending request")
225 return
226 }
227
228 result, err = client.GetResponder(resp)
229 if err != nil {
230 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", resp, "Failure responding to request")
231 return
232 }
233
234 return
235 }
236
237
238 func (client ProtectionIntentClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (*http.Request, error) {
239 pathParameters := map[string]interface{}{
240 "fabricName": autorest.Encode("path", fabricName),
241 "intentObjectName": autorest.Encode("path", intentObjectName),
242 "resourceGroupName": autorest.Encode("path", resourceGroupName),
243 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
244 "vaultName": autorest.Encode("path", vaultName),
245 }
246
247 const APIVersion = "2022-03-01"
248 queryParameters := map[string]interface{}{
249 "api-version": APIVersion,
250 }
251
252 preparer := autorest.CreatePreparer(
253 autorest.AsGet(),
254 autorest.WithBaseURL(client.BaseURI),
255 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
256 autorest.WithQueryParameters(queryParameters))
257 return preparer.Prepare((&http.Request{}).WithContext(ctx))
258 }
259
260
261
262 func (client ProtectionIntentClient) GetSender(req *http.Request) (*http.Response, error) {
263 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
264 }
265
266
267
268 func (client ProtectionIntentClient) GetResponder(resp *http.Response) (result ProtectionIntentResource, err error) {
269 err = autorest.Respond(
270 resp,
271 azure.WithErrorUnlessStatusCode(http.StatusOK),
272 autorest.ByUnmarshallingJSON(&result),
273 autorest.ByClosing())
274 result.Response = autorest.Response{Response: resp}
275 return
276 }
277
278
279
280
281
282 func (client ProtectionIntentClient) Validate(ctx context.Context, azureRegion string, parameters PreValidateEnableBackupRequest) (result PreValidateEnableBackupResponse, err error) {
283 if tracing.IsEnabled() {
284 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Validate")
285 defer func() {
286 sc := -1
287 if result.Response.Response != nil {
288 sc = result.Response.Response.StatusCode
289 }
290 tracing.EndSpan(ctx, sc, err)
291 }()
292 }
293 req, err := client.ValidatePreparer(ctx, azureRegion, parameters)
294 if err != nil {
295 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", nil, "Failure preparing request")
296 return
297 }
298
299 resp, err := client.ValidateSender(req)
300 if err != nil {
301 result.Response = autorest.Response{Response: resp}
302 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", resp, "Failure sending request")
303 return
304 }
305
306 result, err = client.ValidateResponder(resp)
307 if err != nil {
308 err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", resp, "Failure responding to request")
309 return
310 }
311
312 return
313 }
314
315
316 func (client ProtectionIntentClient) ValidatePreparer(ctx context.Context, azureRegion string, parameters PreValidateEnableBackupRequest) (*http.Request, error) {
317 pathParameters := map[string]interface{}{
318 "azureRegion": autorest.Encode("path", azureRegion),
319 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
320 }
321
322 const APIVersion = "2022-03-01"
323 queryParameters := map[string]interface{}{
324 "api-version": APIVersion,
325 }
326
327 preparer := autorest.CreatePreparer(
328 autorest.AsContentType("application/json; charset=utf-8"),
329 autorest.AsPost(),
330 autorest.WithBaseURL(client.BaseURI),
331 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{azureRegion}/backupPreValidateProtection", pathParameters),
332 autorest.WithJSON(parameters),
333 autorest.WithQueryParameters(queryParameters))
334 return preparer.Prepare((&http.Request{}).WithContext(ctx))
335 }
336
337
338
339 func (client ProtectionIntentClient) ValidateSender(req *http.Request) (*http.Response, error) {
340 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
341 }
342
343
344
345 func (client ProtectionIntentClient) ValidateResponder(resp *http.Response) (result PreValidateEnableBackupResponse, err error) {
346 err = autorest.Respond(
347 resp,
348 azure.WithErrorUnlessStatusCode(http.StatusOK),
349 autorest.ByUnmarshallingJSON(&result),
350 autorest.ByClosing())
351 result.Response = autorest.Response{Response: resp}
352 return
353 }
354
View as plain text