aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Azure/azure-storage-blob-go/2018-03-28/azblob/zz_generated_append_blob.go
blob: 8f3dc99349735e8d87a525c88cec0d632b2e43a8 (plain) (blame)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package azblob

// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

import (
    "context"
    "encoding/base64"
    "github.com/Azure/azure-pipeline-go/pipeline"
    "io"
    "io/ioutil"
    "net/http"
    "net/url"
    "strconv"
    "time"
)

// appendBlobClient is the client for the AppendBlob methods of the Azblob service.
type appendBlobClient struct {
    managementClient
}

// newAppendBlobClient creates an instance of the appendBlobClient client.
func newAppendBlobClient(url url.URL, p pipeline.Pipeline) appendBlobClient {
    return appendBlobClient{newManagementClient(url, p)}
}

// AppendBlock the Append Block operation commits a new block of data to the end of an existing append blob. The Append
// Block operation is permitted only if the blob was created with x-ms-blob-type set to AppendBlob. Append Block is
// supported only on version 2015-02-21 version or later.
//
// body is initial data body will be closed upon successful return. Callers should ensure closure when receiving an
// error.contentLength is the length of the request. timeout is the timeout parameter is expressed in seconds. For more
// information, see <a
// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
// Timeouts for Blob Service Operations.</a> leaseID is if specified, the operation only succeeds if the container's
// lease is active and matches this ID. maxSize is optional conditional header. The max length in bytes permitted for
// the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is
// already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error
// (HTTP status code 412 - Precondition Failed). appendPosition is optional conditional header, used only for the
// Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append
// position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error
// (HTTP status code 412 - Precondition Failed). ifModifiedSince is specify this header value to operate only on a blob
// if it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to operate
// only on a blob if it has not been modified since the specified date/time. ifMatches is specify an ETag value to
// operate only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs without a
// matching value. requestID is provides a client-generated, opaque value with a 1 KB character limit that is recorded
// in the analytics logs when storage analytics logging is enabled.
func (client appendBlobClient) AppendBlock(ctx context.Context, body io.ReadSeeker, contentLength int64, timeout *int32, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatches *ETag, ifNoneMatch *ETag, requestID *string) (*AppendBlobAppendBlockResponse, error) {
    if err := validate([]validation{
        {targetValue: body,
            constraints: []constraint{{target: "body", name: null, rule: true, chain: nil}}},
        {targetValue: timeout,
            constraints: []constraint{{target: "timeout", name: null, rule: false,
                chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil {
        return nil, err
    }
    req, err := client.appendBlockPreparer(body, contentLength, timeout, leaseID, maxSize, appendPosition, ifModifiedSince, ifUnmodifiedSince, ifMatches, ifNoneMatch, requestID)
    if err != nil {
        return nil, err
    }
    resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.appendBlockResponder}, req)
    if err != nil {
        return nil, err
    }
    return resp.(*AppendBlobAppendBlockResponse), err
}

// appendBlockPreparer prepares the AppendBlock request.
func (client appendBlobClient) appendBlockPreparer(body io.ReadSeeker, contentLength int64, timeout *int32, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatches *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) {
    req, err := pipeline.NewRequest("PUT", client.url, body)
    if err != nil {
        return req, pipeline.NewError(err, "failed to create request")
    }
    params := req.URL.Query()
    if timeout != nil {
        params.Set("timeout", strconv.FormatInt(int64(*timeout), 10))
    }
    params.Set("comp", "appendblock")
    req.URL.RawQuery = params.Encode()
    req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10))
    if leaseID != nil {
        req.Header.Set("x-ms-lease-id", *leaseID)
    }
    if maxSize != nil {
        req.Header.Set("x-ms-blob-condition-maxsize", strconv.FormatInt(*maxSize, 10))
    }
    if appendPosition != nil {
        req.Header.Set("x-ms-blob-condition-appendpos", strconv.FormatInt(*appendPosition, 10))
    }
    if ifModifiedSince != nil {
        req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123))
    }
    if ifUnmodifiedSince != nil {
        req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123))
    }
    if ifMatches != nil {
        req.Header.Set("If-Match", string(*ifMatches))
    }
    if ifNoneMatch != nil {
        req.Header.Set("If-None-Match", string(*ifNoneMatch))
    }
    req.Header.Set("x-ms-version", ServiceVersion)
    if requestID != nil {
        req.Header.Set("x-ms-client-request-id", *requestID)
    }
    return req, nil
}

// appendBlockResponder handles the response to the AppendBlock request.
func (client appendBlobClient) appendBlockResponder(resp pipeline.Response) (pipeline.Response, error) {
    err := validateResponse(resp, http.StatusOK, http.StatusCreated)
    if resp == nil {
        return nil, err
    }
    io.Copy(ioutil.Discard, resp.Response().Body)
    resp.Response().Body.Close()
    return &AppendBlobAppendBlockResponse{rawResponse: resp.Response()}, err
}

// Create the Create Append Blob operation creates a new append blob.
//
// contentLength is the length of the request. timeout is the timeout parameter is expressed in seconds. For more
// information, see <a
// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting
// Timeouts for Blob Service Operations.</a> blobContentType is optional. Sets the blob's content type. If specified,
// this property is stored with the blob and returned with a read request. blobContentEncoding is optional. Sets the
// blob's content encoding. If specified, this property is stored with the blob and returned with a read request.
// blobContentLanguage is optional. Set the blob's content language. If specified, this property is stored with the
// blob and returned with a read request. blobContentMD5 is optional. An MD5 hash of the blob content. Note that this
// hash is not validated, as the hashes for the individual blocks were validated when each was uploaded.
// blobCacheControl is optional. Sets the blob's cache control. If specified, this property is stored with the blob and
// returned with a read request. metadata is optional. Specifies a user-defined name-value pair associated with the
// blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the
// destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified
// metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19,
// metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and
// Metadata for more information. leaseID is if specified, the operation only succeeds if the container's lease is
// active and matches this ID. blobContentDisposition is optional. Sets the blob's Content-Disposition header.
// ifModifiedSince is specify this header value to operate only on a blob if it has been modified since the specified
// date/time. ifUnmodifiedSince is specify this header value to operate only on a blob if it has not been modified
// since the specified date/time. ifMatches is specify an ETag value to operate only on blobs with a matching value.
// ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. requestID is provides a
// client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage
// analytics logging is enabled.
func (client appendBlobClient) Create(ctx context.Context, contentLength int64, timeout *int32, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatches *ETag, ifNoneMatch *ETag, requestID *string) (*AppendBlobCreateResponse, error) {
    if err := validate([]validation{
        {targetValue: timeout,
            constraints: []constraint{{target: "timeout", name: null, rule: false,
                chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}},
        {targetValue: metadata,
            constraints: []constraint{{target: "metadata", name: null, rule: false,
                chain: []constraint{{target: "metadata", name: pattern, rule: `^[a-zA-Z]+$`, chain: nil}}}}}}); err != nil {
        return nil, err
    }
    req, err := client.createPreparer(contentLength, timeout, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5, blobCacheControl, metadata, leaseID, blobContentDisposition, ifModifiedSince, ifUnmodifiedSince, ifMatches, ifNoneMatch, requestID)
    if err != nil {
        return nil, err
    }
    resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req)
    if err != nil {
        return nil, err
    }
    return resp.(*AppendBlobCreateResponse), err
}

// createPreparer prepares the Create request.
func (client appendBlobClient) createPreparer(contentLength int64, timeout *int32, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatches *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) {
    req, err := pipeline.NewRequest("PUT", client.url, nil)
    if err != nil {
        return req, pipeline.NewError(err, "failed to create request")
    }
    params := req.URL.Query()
    if timeout != nil {
        params.Set("timeout", strconv.FormatInt(int64(*timeout), 10))
    }
    req.URL.RawQuery = params.Encode()
    req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10))
    if blobContentType != nil {
        req.Header.Set("x-ms-blob-content-type", *blobContentType)
    }
    if blobContentEncoding != nil {
        req.Header.Set("x-ms-blob-content-encoding", *blobContentEncoding)
    }
    if blobContentLanguage != nil {
        req.Header.Set("x-ms-blob-content-language", *blobContentLanguage)
    }
    if blobContentMD5 != nil {
        req.Header.Set("x-ms-blob-content-md5", base64.StdEncoding.EncodeToString(blobContentMD5))
    }
    if blobCacheControl != nil {
        req.Header.Set("x-ms-blob-cache-control", *blobCacheControl)
    }
    if metadata != nil {
        for k, v := range metadata {
            req.Header.Set("x-ms-meta-"+k, v)
        }
    }
    if leaseID != nil {
        req.Header.Set("x-ms-lease-id", *leaseID)
    }
    if blobContentDisposition != nil {
        req.Header.Set("x-ms-blob-content-disposition", *blobContentDisposition)
    }
    if ifModifiedSince != nil {
        req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123))
    }
    if ifUnmodifiedSince != nil {
        req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123))
    }
    if ifMatches != nil {
        req.Header.Set("If-Match", string(*ifMatches))
    }
    if ifNoneMatch != nil {
        req.Header.Set("If-None-Match", string(*ifNoneMatch))
    }
    req.Header.Set("x-ms-version", ServiceVersion)
    if requestID != nil {
        req.Header.Set("x-ms-client-request-id", *requestID)
    }
    req.Header.Set("x-ms-blob-type", "AppendBlob")
    return req, nil
}

// createResponder handles the response to the Create request.
func (client appendBlobClient) createResponder(resp pipeline.Response) (pipeline.Response, error) {
    err := validateResponse(resp, http.StatusOK, http.StatusCreated)
    if resp == nil {
        return nil, err
    }
    io.Copy(ioutil.Discard, resp.Response().Body)
    resp.Response().Body.Close()
    return &AppendBlobCreateResponse{rawResponse: resp.Response()}, err
}