Debian Codegraph @

storage/2018-11-09/blob/blobs/copy_abort.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 type AbortCopyInput struct {
15 // The Copy ID which should be aborted
16 CopyID string
17
18 // The ID of the Lease
19 // This must be specified if a Lease is present on the Blob, else a 403 is returned
20 LeaseID *string
21 }
22
23 // AbortCopy aborts a pending Copy Blob operation, and leaves a destination blob with zero length and full metadata.
24 func (client Client) AbortCopy(ctx context.Context, accountName, containerName, blobName string, input AbortCopyInput) (result autorest.Response, err error) {
25 if accountName == "" {
26 return result, validation.NewError("blobs.Client", "AbortCopy", "`accountName` cannot be an empty string.")
27 }
28 if containerName == "" {
29 return result, validation.NewError("blobs.Client", "AbortCopy", "`containerName` cannot be an empty string.")
30 }
31 if strings.ToLower(containerName) != containerName {
32 return result, validation.NewError("blobs.Client", "AbortCopy", "`containerName` must be a lower-cased string.")
33 }
34 if blobName == "" {
35 return result, validation.NewError("blobs.Client", "AbortCopy", "`blobName` cannot be an empty string.")
36 }
37 if input.CopyID == "" {
38 return result, validation.NewError("blobs.Client", "AbortCopy", "`input.CopyID` cannot be an empty string.")
39 }
40
41 req, err := client.AbortCopyPreparer(ctx, accountName, containerName, blobName, input)
42 if err != nil {
43 err = autorest.NewErrorWithError(err, "blobs.Client", "AbortCopy", nil, "Failure preparing request")
44 return
45 }
46
47 resp, err := client.AbortCopySender(req)
48 if err != nil {
49 result = autorest.Response{Response: resp}
50 err = autorest.NewErrorWithError(err, "blobs.Client", "AbortCopy", resp, "Failure sending request")
51 return
52 }
53
54 result, err = client.AbortCopyResponder(resp)
55 if err != nil {
56 err = autorest.NewErrorWithError(err, "blobs.Client", "AbortCopy", resp, "Failure responding to request")
57 return
58 }
59
60 return
61 }
62
63 // AbortCopyPreparer prepares the AbortCopy request.
64 func (client Client) AbortCopyPreparer(ctx context.Context, accountName, containerName, blobName string, input AbortCopyInput) (*http.Request, error) {
65 pathParameters := map[string]interface{}{
66 "containerName": autorest.Encode("path", containerName),
67 "blobName": autorest.Encode("path", blobName),
68 }
69
70 queryParameters := map[string]interface{}{
71 "comp": autorest.Encode("query", "copy"),
72 "copyid": autorest.Encode("query", input.CopyID),
73 }
74
75 headers := map[string]interface{}{
76 "x-ms-version": APIVersion,
77 "x-ms-copy-action": "abort",
78 }
79
80 if input.LeaseID != nil {
81 headers["x-ms-lease-id"] = *input.LeaseID
82 }
83
84 preparer := autorest.CreatePreparer(
85 autorest.AsPut(),
86 autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
87 autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
88 autorest.WithQueryParameters(queryParameters),
89 autorest.WithHeaders(headers))
90 return preparer.Prepare((&http.Request{}).WithContext(ctx))
91 }
92
93 // AbortCopySender sends the AbortCopy request. The method will close the
94 // http.Response Body if it receives an error.
95 func (client Client) AbortCopySender(req *http.Request) (*http.Response, error) {
96 return autorest.SendWithSender(client, req,
97 azure.DoRetryWithRegistration(client.Client))
98 }
99
100 // AbortCopyResponder handles the response to the AbortCopy request. The method always
101 // closes the http.Response Body.
102 func (client Client) AbortCopyResponder(resp *http.Response) (result autorest.Response, err error) {
103 err = autorest.Respond(
104 resp,
105 client.ByInspecting(),
106 azure.WithErrorUnlessStatusCode(http.StatusNoContent),
107 autorest.ByClosing())
108 result = autorest.Response{Response: resp}
109 return
110 }