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