| 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 | // RenewLease renewes the lock based on the Lease ID |
| 14 | func (client Client) RenewLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { |
| 15 | if accountName == "" { |
| 16 | return result, validation.NewError("containers.Client", "RenewLease", "`accountName` cannot be an empty string.") |
| 17 | } |
| 18 | if containerName == "" { |
| 19 | return result, validation.NewError("containers.Client", "RenewLease", "`containerName` cannot be an empty string.") |
| 20 | } |
| 21 | if leaseID == "" { |
| 22 | return result, validation.NewError("containers.Client", "RenewLease", "`leaseID` cannot be an empty string.") |
| 23 | } |
| 24 | |
| 25 | req, err := client.RenewLeasePreparer(ctx, accountName, containerName, leaseID) |
| 26 | if err != nil { |
| 27 | err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", nil, "Failure preparing request") |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | resp, err := client.RenewLeaseSender(req) |
| 32 | if err != nil { |
| 33 | result = autorest.Response{Response: resp} |
| 34 | err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure sending request") |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | result, err = client.RenewLeaseResponder(resp) |
| 39 | if err != nil { |
| 40 | err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure responding to request") |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | // RenewLeasePreparer prepares the RenewLease request. |
| 48 | func (client Client) RenewLeasePreparer(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": "renew", |
| 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 | // RenewLeaseSender sends the RenewLease request. The method will close the |
| 75 | // http.Response Body if it receives an error. |
| 76 | func (client Client) RenewLeaseSender(req *http.Request) (*http.Response, error) { |
| 77 | return autorest.SendWithSender(client, req, |
| 78 | azure.DoRetryWithRegistration(client.Client)) |
| 79 | } |
| 80 | |
| 81 | // RenewLeaseResponder handles the response to the RenewLease request. The method always |
| 82 | // closes the http.Response Body. |
| 83 | func (client Client) RenewLeaseResponder(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 | } |