Debian Codegraph @

storage/2018-11-09/blob/blobs/undelete.go

raw
1 package blobs
2
3 import (
4 "context"
5 "net/http"
6 "strings"
7
8 "github.com/Azure/go-autorest/autorest"
9 "github.com/Azure/go-autorest/autorest/azure"
10 "github.com/Azure/go-autorest/autorest/validation"
11 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
12 )
13
14 // Undelete restores the contents and metadata of soft deleted blob and any associated soft deleted snapshots.
15 func (client Client) Undelete(ctx context.Context, accountName, containerName, blobName string) (result autorest.Response, err error) {
16 if accountName == "" {
17 return result, validation.NewError("blobs.Client", "Undelete", "`accountName` cannot be an empty string.")
18 }
19 if containerName == "" {
20 return result, validation.NewError("blobs.Client", "Undelete", "`containerName` cannot be an empty string.")
21 }
22 if strings.ToLower(containerName) != containerName {
23 return result, validation.NewError("blobs.Client", "Undelete", "`containerName` must be a lower-cased string.")
24 }
25 if blobName == "" {
26 return result, validation.NewError("blobs.Client", "Undelete", "`blobName` cannot be an empty string.")
27 }
28
29 req, err := client.UndeletePreparer(ctx, accountName, containerName, blobName)
30 if err != nil {
31 err = autorest.NewErrorWithError(err, "blobs.Client", "Undelete", nil, "Failure preparing request")
32 return
33 }
34
35 resp, err := client.UndeleteSender(req)
36 if err != nil {
37 result = autorest.Response{Response: resp}
38 err = autorest.NewErrorWithError(err, "blobs.Client", "Undelete", resp, "Failure sending request")
39 return
40 }
41
42 result, err = client.UndeleteResponder(resp)
43 if err != nil {
44 err = autorest.NewErrorWithError(err, "blobs.Client", "Undelete", resp, "Failure responding to request")
45 return
46 }
47
48 return
49 }
50
51 // UndeletePreparer prepares the Undelete request.
52 func (client Client) UndeletePreparer(ctx context.Context, accountName, containerName, blobName string) (*http.Request, error) {
53 pathParameters := map[string]interface{}{
54 "containerName": autorest.Encode("path", containerName),
55 "blobName": autorest.Encode("path", blobName),
56 }
57
58 queryParameters := map[string]interface{}{
59 "comp": autorest.Encode("path", "undelete"),
60 }
61
62 headers := map[string]interface{}{
63 "x-ms-version": APIVersion,
64 }
65
66 preparer := autorest.CreatePreparer(
67 autorest.AsPut(),
68 autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
69 autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
70 autorest.WithQueryParameters(queryParameters),
71 autorest.WithHeaders(headers))
72 return preparer.Prepare((&http.Request{}).WithContext(ctx))
73 }
74
75 // UndeleteSender sends the Undelete request. The method will close the
76 // http.Response Body if it receives an error.
77 func (client Client) UndeleteSender(req *http.Request) (*http.Response, error) {
78 return autorest.SendWithSender(client, req,
79 azure.DoRetryWithRegistration(client.Client))
80 }
81
82 // UndeleteResponder handles the response to the Undelete request. The method always
83 // closes the http.Response Body.
84 func (client Client) UndeleteResponder(resp *http.Response) (result autorest.Response, err error) {
85 err = autorest.Respond(
86 resp,
87 client.ByInspecting(),
88 azure.WithErrorUnlessStatusCode(http.StatusOK),
89 autorest.ByClosing())
90 result = autorest.Response{Response: resp}
91 return
92 }