Debian Codegraph @

storage/2020-08-04/file/shares/snapshot_get.go

raw
1 package shares
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 "github.com/tombuildsstuff/giovanni/storage/internal/metadata"
13 )
14
15 type GetSnapshotPropertiesResult struct {
16 autorest.Response
17
18 MetaData map[string]string
19 }
20
21 // GetSnapshot gets information about the specified Snapshot of the specified Storage Share
22 func (client Client) GetSnapshot(ctx context.Context, accountName, shareName, snapshotShare string) (result GetSnapshotPropertiesResult, err error) {
23 if accountName == "" {
24 return result, validation.NewError("shares.Client", "GetSnapshot", "`accountName` cannot be an empty string.")
25 }
26 if shareName == "" {
27 return result, validation.NewError("shares.Client", "GetSnapshot", "`shareName` cannot be an empty string.")
28 }
29 if strings.ToLower(shareName) != shareName {
30 return result, validation.NewError("shares.Client", "GetSnapshot", "`shareName` must be a lower-cased string.")
31 }
32 if snapshotShare == "" {
33 return result, validation.NewError("shares.Client", "GetSnapshot", "`snapshotShare` cannot be an empty string.")
34 }
35
36 req, err := client.GetSnapshotPreparer(ctx, accountName, shareName, snapshotShare)
37 if err != nil {
38 err = autorest.NewErrorWithError(err, "shares.Client", "GetSnapshot", nil, "Failure preparing request")
39 return
40 }
41
42 resp, err := client.GetSnapshotSender(req)
43 if err != nil {
44 result.Response = autorest.Response{Response: resp}
45 err = autorest.NewErrorWithError(err, "shares.Client", "GetSnapshot", resp, "Failure sending request")
46 return
47 }
48
49 result, err = client.GetSnapshotResponder(resp)
50 if err != nil {
51 err = autorest.NewErrorWithError(err, "shares.Client", "GetSnapshot", resp, "Failure responding to request")
52 return
53 }
54
55 return
56 }
57
58 // GetSnapshotPreparer prepares the GetSnapshot request.
59 func (client Client) GetSnapshotPreparer(ctx context.Context, accountName, shareName, snapshotShare string) (*http.Request, error) {
60 pathParameters := map[string]interface{}{
61 "shareName": autorest.Encode("path", shareName),
62 }
63
64 queryParameters := map[string]interface{}{
65 "restype": autorest.Encode("query", "share"),
66 "snapshot": autorest.Encode("query", snapshotShare),
67 }
68
69 headers := map[string]interface{}{
70 "x-ms-version": APIVersion,
71 }
72
73 preparer := autorest.CreatePreparer(
74 autorest.AsContentType("application/xml; charset=utf-8"),
75 autorest.AsGet(),
76 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
77 autorest.WithPathParameters("/{shareName}", pathParameters),
78 autorest.WithQueryParameters(queryParameters),
79 autorest.WithHeaders(headers))
80 return preparer.Prepare((&http.Request{}).WithContext(ctx))
81 }
82
83 // GetSnapshotSender sends the GetSnapshot request. The method will close the
84 // http.Response Body if it receives an error.
85 func (client Client) GetSnapshotSender(req *http.Request) (*http.Response, error) {
86 return autorest.SendWithSender(client, req,
87 azure.DoRetryWithRegistration(client.Client))
88 }
89
90 // GetSnapshotResponder handles the response to the GetSnapshot request. The method always
91 // closes the http.Response Body.
92 func (client Client) GetSnapshotResponder(resp *http.Response) (result GetSnapshotPropertiesResult, err error) {
93 if resp.Header != nil {
94 result.MetaData = metadata.ParseFromHeaders(resp.Header)
95 }
96
97 err = autorest.Respond(
98 resp,
99 client.ByInspecting(),
100 azure.WithErrorUnlessStatusCode(http.StatusOK),
101 autorest.ByClosing())
102 result.Response = autorest.Response{Response: resp}
103
104 return
105 }