-
Notifications
You must be signed in to change notification settings - Fork 22
/
put_page_blob.go
155 lines (124 loc) · 3.95 KB
/
put_page_blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package blobs
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
"github.com/tombuildsstuff/giovanni/storage/internal/metadata"
)
type PutPageBlobInput struct {
CacheControl *string
ContentDisposition *string
ContentEncoding *string
ContentLanguage *string
ContentMD5 *string
ContentType *string
LeaseID *string
EncryptionScope *string
MetaData map[string]string
BlobContentLengthBytes int64
BlobSequenceNumber *int64
AccessTier *AccessTier
}
type PutPageBlobResponse struct {
HttpResponse *http.Response
}
// PutPageBlob is a wrapper around the Put API call (with a stricter input object)
// which creates a new block blob, or updates the content of an existing page blob.
func (c Client) PutPageBlob(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (result PutPageBlobResponse, err error) {
if containerName == "" {
err = fmt.Errorf("`containerName` cannot be an empty string")
return
}
if strings.ToLower(containerName) != containerName {
err = fmt.Errorf("`containerName` must be a lower-cased string")
return
}
if blobName == "" {
err = fmt.Errorf("`blobName` cannot be an empty string")
return
}
if input.BlobContentLengthBytes == 0 || input.BlobContentLengthBytes%512 != 0 {
err = fmt.Errorf("`input.BlobContentLengthBytes` must be aligned to a 512-byte boundary")
return
}
opts := client.RequestOptions{
ExpectedStatusCodes: []int{
http.StatusCreated,
},
HttpMethod: http.MethodPut,
OptionsObject: putPageBlobOptions{
input: input,
},
Path: fmt.Sprintf("/%s/%s", containerName, blobName),
}
req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
err = fmt.Errorf("building request: %+v", err)
return
}
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil && resp.Response != nil {
result.HttpResponse = resp.Response
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}
return
}
type putPageBlobOptions struct {
input PutPageBlobInput
}
func (p putPageBlobOptions) ToHeaders() *client.Headers {
headers := &client.Headers{}
headers.Append("x-ms-blob-type", string(PageBlob))
// For a page blob or an page blob, the value of this header must be set to zero,
// as Put Blob is used only to initialize the blob
headers.Append("Content-Length", "0")
// This header specifies the maximum size for the page blob, up to 8 TB.
// The page blob size must be aligned to a 512-byte boundary.
headers.Append("x-ms-blob-content-length", strconv.Itoa(int(p.input.BlobContentLengthBytes)))
if p.input.AccessTier != nil {
headers.Append("x-ms-access-tier", string(*p.input.AccessTier))
}
if p.input.BlobSequenceNumber != nil {
headers.Append("x-ms-blob-sequence-number", strconv.Itoa(int(*p.input.BlobSequenceNumber)))
}
if p.input.CacheControl != nil {
headers.Append("x-ms-blob-cache-control", *p.input.CacheControl)
}
if p.input.ContentDisposition != nil {
headers.Append("x-ms-blob-content-disposition", *p.input.ContentDisposition)
}
if p.input.ContentEncoding != nil {
headers.Append("x-ms-blob-content-encoding", *p.input.ContentEncoding)
}
if p.input.ContentLanguage != nil {
headers.Append("x-ms-blob-content-language", *p.input.ContentLanguage)
}
if p.input.ContentMD5 != nil {
headers.Append("x-ms-blob-content-md5", *p.input.ContentMD5)
}
if p.input.ContentType != nil {
headers.Append("x-ms-blob-content-type", *p.input.ContentType)
}
if p.input.LeaseID != nil {
headers.Append("x-ms-lease-id", *p.input.LeaseID)
}
if p.input.EncryptionScope != nil {
headers.Append("x-ms-encryption-scope", *p.input.EncryptionScope)
}
headers.Merge(metadata.SetMetaDataHeaders(p.input.MetaData))
return headers
}
func (p putPageBlobOptions) ToOData() *odata.Query {
return nil
}
func (p putPageBlobOptions) ToQuery() *client.QueryParams {
return nil
}