Debian Codegraph @

storage/2018-11-09/blob/containers/lease_release.go

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