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 ProtectionPoliciesClient struct {
19 BaseClient
20 }
21
22
23 func NewProtectionPoliciesClient(subscriptionID string) ProtectionPoliciesClient {
24 return NewProtectionPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewProtectionPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPoliciesClient {
31 return ProtectionPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41
42 func (client ProtectionPoliciesClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, policyName string, parameters ProtectionPolicyResource) (result ProtectionPolicyResource, err error) {
43 if tracing.IsEnabled() {
44 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.CreateOrUpdate")
45 defer func() {
46 sc := -1
47 if result.Response.Response != nil {
48 sc = result.Response.Response.StatusCode
49 }
50 tracing.EndSpan(ctx, sc, err)
51 }()
52 }
53 req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, policyName, parameters)
54 if err != nil {
55 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
56 return
57 }
58
59 resp, err := client.CreateOrUpdateSender(req)
60 if err != nil {
61 result.Response = autorest.Response{Response: resp}
62 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure sending request")
63 return
64 }
65
66 result, err = client.CreateOrUpdateResponder(resp)
67 if err != nil {
68 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
69 return
70 }
71
72 return
73 }
74
75
76 func (client ProtectionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, parameters ProtectionPolicyResource) (*http.Request, error) {
77 pathParameters := map[string]interface{}{
78 "policyName": autorest.Encode("path", policyName),
79 "resourceGroupName": autorest.Encode("path", resourceGroupName),
80 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
81 "vaultName": autorest.Encode("path", vaultName),
82 }
83
84 const APIVersion = "2019-05-13"
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}/backupPolicies/{policyName}", pathParameters),
94 autorest.WithJSON(parameters),
95 autorest.WithQueryParameters(queryParameters))
96 return preparer.Prepare((&http.Request{}).WithContext(ctx))
97 }
98
99
100
101 func (client ProtectionPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
102 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103 }
104
105
106
107 func (client ProtectionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
108 err = autorest.Respond(
109 resp,
110 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
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
124 func (client ProtectionPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result autorest.Response, err error) {
125 if tracing.IsEnabled() {
126 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
127 defer func() {
128 sc := -1
129 if result.Response != nil {
130 sc = result.Response.StatusCode
131 }
132 tracing.EndSpan(ctx, sc, err)
133 }()
134 }
135 req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, policyName)
136 if err != nil {
137 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request")
138 return
139 }
140
141 resp, err := client.DeleteSender(req)
142 if err != nil {
143 result.Response = resp
144 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure sending request")
145 return
146 }
147
148 result, err = client.DeleteResponder(resp)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure responding to request")
151 return
152 }
153
154 return
155 }
156
157
158 func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
159 pathParameters := map[string]interface{}{
160 "policyName": autorest.Encode("path", policyName),
161 "resourceGroupName": autorest.Encode("path", resourceGroupName),
162 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
163 "vaultName": autorest.Encode("path", vaultName),
164 }
165
166 const APIVersion = "2016-12-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}/backupPolicies/{policyName}", pathParameters),
175 autorest.WithQueryParameters(queryParameters))
176 return preparer.Prepare((&http.Request{}).WithContext(ctx))
177 }
178
179
180
181 func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
182 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
183 }
184
185
186
187 func (client ProtectionPoliciesClient) 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 func (client ProtectionPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPolicyResource, err error) {
203 if tracing.IsEnabled() {
204 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Get")
205 defer func() {
206 sc := -1
207 if result.Response.Response != nil {
208 sc = result.Response.Response.StatusCode
209 }
210 tracing.EndSpan(ctx, sc, err)
211 }()
212 }
213 req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName)
214 if err != nil {
215 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", nil, "Failure preparing request")
216 return
217 }
218
219 resp, err := client.GetSender(req)
220 if err != nil {
221 result.Response = autorest.Response{Response: resp}
222 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure sending request")
223 return
224 }
225
226 result, err = client.GetResponder(resp)
227 if err != nil {
228 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure responding to request")
229 return
230 }
231
232 return
233 }
234
235
236 func (client ProtectionPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
237 pathParameters := map[string]interface{}{
238 "policyName": autorest.Encode("path", policyName),
239 "resourceGroupName": autorest.Encode("path", resourceGroupName),
240 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
241 "vaultName": autorest.Encode("path", vaultName),
242 }
243
244 const APIVersion = "2019-05-13"
245 queryParameters := map[string]interface{}{
246 "api-version": APIVersion,
247 }
248
249 preparer := autorest.CreatePreparer(
250 autorest.AsGet(),
251 autorest.WithBaseURL(client.BaseURI),
252 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
253 autorest.WithQueryParameters(queryParameters))
254 return preparer.Prepare((&http.Request{}).WithContext(ctx))
255 }
256
257
258
259 func (client ProtectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
260 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
261 }
262
263
264
265 func (client ProtectionPoliciesClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
266 err = autorest.Respond(
267 resp,
268 azure.WithErrorUnlessStatusCode(http.StatusOK),
269 autorest.ByUnmarshallingJSON(&result),
270 autorest.ByClosing())
271 result.Response = autorest.Response{Response: resp}
272 return
273 }
274
View as plain text