Debian Codegraph @

storage/2018-11-09/blob/blobs/snapshot_get_properties.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/validation"
10 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
11 )
12
13 type GetSnapshotPropertiesInput struct {
14 // The ID of the Lease
15 // This must be specified if a Lease is present on the Blob, else a 403 is returned
16 LeaseID *string
17
18 // The ID of the Snapshot which should be retrieved
19 SnapshotID string
20 }
21
22 // GetSnapshotProperties returns all user-defined metadata, standard HTTP properties, and system properties for
23 // the specified snapshot of a blob
24 func (client Client) GetSnapshotProperties(ctx context.Context, accountName, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResult, err error) {
25 if accountName == "" {
26 return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`accountName` cannot be an empty string.")
27 }
28 if containerName == "" {
29 return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`containerName` cannot be an empty string.")
30 }
31 if strings.ToLower(containerName) != containerName {
32 return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`containerName` must be a lower-cased string.")
33 }
34 if blobName == "" {
35 return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`blobName` cannot be an empty string.")
36 }
37 if input.SnapshotID == "" {
38 return result, validation.NewError("blobs.Client", "GetSnapshotProperties", "`input.SnapshotID` cannot be an empty string.")
39 }
40
41 req, err := client.GetSnapshotPropertiesPreparer(ctx, accountName, containerName, blobName, input)
42 if err != nil {
43 err = autorest.NewErrorWithError(err, "blobs.Client", "GetSnapshotProperties", nil, "Failure preparing request")
44 return
45 }
46
47 // we re-use the GetProperties methods since this is otherwise the same
48 resp, err := client.GetPropertiesSender(req)
49 if err != nil {
50 result.Response = autorest.Response{Response: resp}
51 err = autorest.NewErrorWithError(err, "blobs.Client", "GetSnapshotProperties", resp, "Failure sending request")
52 return
53 }
54
55 result, err = client.GetPropertiesResponder(resp)
56 if err != nil {
57 err = autorest.NewErrorWithError(err, "blobs.Client", "GetSnapshotProperties", resp, "Failure responding to request")
58 return
59 }
60
61 return
62 }
63
64 // GetSnapshotPreparer prepares the GetSnapshot request.
65 func (client Client) GetSnapshotPropertiesPreparer(ctx context.Context, accountName, containerName, blobName string, input GetSnapshotPropertiesInput) (*http.Request, error) {
66 pathParameters := map[string]interface{}{
67 "containerName": autorest.Encode("path", containerName),
68 "blobName": autorest.Encode("path", blobName),
69 }
70
71 queryParameters := map[string]interface{}{
72 "snapshot": autorest.Encode("query", input.SnapshotID),
73 }
74
75 headers := map[string]interface{}{
76 "x-ms-version": APIVersion,
77 }
78
79 if input.LeaseID != nil {
80 headers["x-ms-lease-id"] = *input.LeaseID
81 }
82
83 preparer := autorest.CreatePreparer(
84 autorest.AsHead(),
85 autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
86 autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
87 autorest.WithHeaders(headers),
88 autorest.WithQueryParameters(queryParameters))
89 return preparer.Prepare((&http.Request{}).WithContext(ctx))
90 }