Debian Codegraph @

storage/2018-11-09/blob/blobs/lease_renew.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 func (client Client) RenewLease(ctx context.Context, accountName, containerName, blobName, leaseID string) (result autorest.Response, err error) {
15 if accountName == "" {
16 return result, validation.NewError("blobs.Client", "RenewLease", "`accountName` cannot be an empty string.")
17 }
18 if containerName == "" {
19 return result, validation.NewError("blobs.Client", "RenewLease", "`containerName` cannot be an empty string.")
20 }
21 if strings.ToLower(containerName) != containerName {
22 return result, validation.NewError("blobs.Client", "RenewLease", "`containerName` must be a lower-cased string.")
23 }
24 if blobName == "" {
25 return result, validation.NewError("blobs.Client", "RenewLease", "`blobName` cannot be an empty string.")
26 }
27 if leaseID == "" {
28 return result, validation.NewError("blobs.Client", "RenewLease", "`leaseID` cannot be an empty string.")
29 }
30
31 req, err := client.RenewLeasePreparer(ctx, accountName, containerName, blobName, leaseID)
32 if err != nil {
33 err = autorest.NewErrorWithError(err, "blobs.Client", "RenewLease", nil, "Failure preparing request")
34 return
35 }
36
37 resp, err := client.RenewLeaseSender(req)
38 if err != nil {
39 result = autorest.Response{Response: resp}
40 err = autorest.NewErrorWithError(err, "blobs.Client", "RenewLease", resp, "Failure sending request")
41 return
42 }
43
44 result, err = client.RenewLeaseResponder(resp)
45 if err != nil {
46 err = autorest.NewErrorWithError(err, "blobs.Client", "RenewLease", resp, "Failure responding to request")
47 return
48 }
49
50 return
51 }
52
53 // RenewLeasePreparer prepares the RenewLease request.
54 func (client Client) RenewLeasePreparer(ctx context.Context, accountName, containerName, blobName, leaseID string) (*http.Request, error) {
55 pathParameters := map[string]interface{}{
56 "containerName": autorest.Encode("path", containerName),
57 "blobName": autorest.Encode("path", blobName),
58 }
59
60 queryParameters := map[string]interface{}{
61 "comp": autorest.Encode("query", "lease"),
62 }
63
64 headers := map[string]interface{}{
65 "x-ms-version": APIVersion,
66 "x-ms-lease-action": "renew",
67 "x-ms-lease-id": leaseID,
68 }
69
70 preparer := autorest.CreatePreparer(
71 autorest.AsPut(),
72 autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
73 autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
74 autorest.WithHeaders(headers),
75 autorest.WithQueryParameters(queryParameters))
76 return preparer.Prepare((&http.Request{}).WithContext(ctx))
77 }
78
79 // RenewLeaseSender sends the RenewLease request. The method will close the
80 // http.Response Body if it receives an error.
81 func (client Client) RenewLeaseSender(req *http.Request) (*http.Response, error) {
82 return autorest.SendWithSender(client, req,
83 azure.DoRetryWithRegistration(client.Client))
84 }
85
86 // RenewLeaseResponder handles the response to the RenewLease request. The method always
87 // closes the http.Response Body.
88 func (client Client) RenewLeaseResponder(resp *http.Response) (result autorest.Response, err error) {
89 err = autorest.Respond(
90 resp,
91 client.ByInspecting(),
92 azure.WithErrorUnlessStatusCode(http.StatusOK),
93 autorest.ByClosing())
94 result = autorest.Response{Response: resp}
95
96 return
97 }