Merge pull request #28 from JeffreyRichter/master
Various small improvements
This commit is contained in:
Коммит
cf023500f0
|
@ -0,0 +1,21 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/Azure/azure-pipeline-go"
|
||||
packages = ["pipeline"]
|
||||
revision = "0f0dbf237bd47d5688310dbd3fac369353f280d0"
|
||||
version = "0.1.5"
|
||||
|
||||
[[projects]]
|
||||
branch = "v1"
|
||||
name = "gopkg.in/check.v1"
|
||||
packages = ["."]
|
||||
revision = "20d25e2804050c1cd24a7eea1e7a6447dd0e74ec"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "a6aef008d020b1455ef28ec8264c056f69bc26c0d32f711127c05dde5802f737"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
|
@ -0,0 +1,38 @@
|
|||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/Azure/azure-pipeline-go"
|
||||
version = "0.1.5"
|
||||
|
||||
[[constraint]]
|
||||
branch = "v1"
|
||||
name = "gopkg.in/check.v1"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
|
@ -9,10 +9,11 @@ import (
|
|||
"net/http"
|
||||
|
||||
"bytes"
|
||||
"github.com/Azure/azure-pipeline-go/pipeline"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-pipeline-go/pipeline"
|
||||
)
|
||||
|
||||
// CommonResponseHeaders returns the headers common to all blob REST API responses.
|
||||
|
@ -150,7 +151,7 @@ func UploadBufferToBlockBlob(ctx context.Context, b []byte,
|
|||
}
|
||||
}
|
||||
// All put blocks were successful, call Put Block List to finalize the blob
|
||||
return blockBlobURL.PutBlockList(ctx, blockIDList, o.Metadata, o.BlobHTTPHeaders, o.AccessConditions)
|
||||
return blockBlobURL.PutBlockList(ctx, blockIDList, o.BlobHTTPHeaders, o.Metadata, o.AccessConditions)
|
||||
}
|
||||
|
||||
// UploadFileToBlockBlob uploads a file in blocks to a block blob.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build linux darwin
|
||||
|
||||
package azblob
|
||||
|
||||
import (
|
|
@ -57,7 +57,7 @@ func NewBlobURLParts(u url.URL) BlobURLParts {
|
|||
// If we recognized the query parameter, remove it from the map
|
||||
delete(paramsMap, "snapshot")
|
||||
}
|
||||
up.SAS = NewSASQueryParameters(paramsMap, true)
|
||||
up.SAS = newSASQueryParameters(paramsMap, true)
|
||||
up.UnparsedParams = paramsMap.Encode()
|
||||
return up
|
||||
}
|
||||
|
|
|
@ -161,11 +161,12 @@ func NewRetryPolicyFactory(o RetryOptions) pipeline.Factory {
|
|||
|
||||
// Clone the original request to ensure that each try starts with the original (unmutated) request.
|
||||
requestCopy := request.Copy()
|
||||
if try > 1 {
|
||||
// For a retry, seek to the beginning of the Body stream.
|
||||
if err = requestCopy.RewindBody(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// For each try, seek to the beginning of the Body stream. We do this even for the 1st try because
|
||||
// the stream may not be at offset 0 when we first get it and we want the same behavior for the
|
||||
// 1st try as for additional tries.
|
||||
if err = requestCopy.RewindBody(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !tryingPrimary {
|
||||
requestCopy.Request.URL.Host = o.RetryReadsFromSecondaryHost
|
||||
|
|
|
@ -6,8 +6,6 @@ import (
|
|||
"github.com/Azure/azure-pipeline-go/pipeline"
|
||||
)
|
||||
|
||||
/**/
|
||||
|
||||
// NewUniqueRequestIDPolicyFactory creates a UniqueRequestIDPolicyFactory object
|
||||
// that sets the request's x-ms-client-request-id header if it doesn't already exist.
|
||||
func NewUniqueRequestIDPolicyFactory() pipeline.Factory {
|
||||
|
@ -23,36 +21,5 @@ func NewUniqueRequestIDPolicyFactory() pipeline.Factory {
|
|||
})
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
const xMsClientRequestID = "x-ms-client-request-id"
|
||||
|
||||
/*
|
||||
// NewUniqueRequestIDPolicyFactory creates a UniqueRequestIDPolicyFactory object
|
||||
// that sets the request's x-ms-client-request-id header if it doesn't already exist.
|
||||
func NewUniqueRequestIDPolicyFactory() pipeline.Factory {
|
||||
return &uniqueRequestIDPolicyFactory{}
|
||||
}
|
||||
|
||||
// uniqueRequestIDPolicyFactory struct
|
||||
type uniqueRequestIDPolicyFactory struct {
|
||||
}
|
||||
|
||||
// New creates a UniqueRequestIDPolicy object.
|
||||
func (f *uniqueRequestIDPolicyFactory) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy {
|
||||
return &uniqueRequestIDPolicy{next: next}
|
||||
}
|
||||
|
||||
// UniqueRequestIDPolicy ...
|
||||
type uniqueRequestIDPolicy struct {
|
||||
next pipeline.Policy
|
||||
}
|
||||
|
||||
func (p *uniqueRequestIDPolicy) Do(ctx context.Context, request pipeline.Request) (pipeline.Response, error) {
|
||||
id := request.Header.Get(xMsClientRequestID)
|
||||
if id == "" { // Add a unique request ID if the caller didn't specify one already
|
||||
request.Header.Set(xMsClientRequestID, newUUID().String())
|
||||
}
|
||||
return p.next.Do(ctx, request)
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -2,45 +2,22 @@ package azblob
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SASVersion indicates the SAS version.
|
||||
const SASVersion = "2015-04-05"
|
||||
|
||||
const (
|
||||
// SASProtocolHTTPS can be specified for a SAS protocol
|
||||
SASProtocolHTTPS = "https"
|
||||
|
||||
// SASProtocolHTTPSandHTTP can be specified for a SAS protocol
|
||||
SASProtocolHTTPSandHTTP = "https,http"
|
||||
)
|
||||
|
||||
// FormatTimesForSASSigning converts a time.Time to a snapshotTimeFormat string suitable for a
|
||||
// SASField's StartTime or ExpiryTime fields. Returns "" if value.IsZero().
|
||||
func FormatTimesForSASSigning(startTime, expiryTime time.Time) (string, string) {
|
||||
ss := ""
|
||||
if !startTime.IsZero() {
|
||||
ss = startTime.Format(SASTimeFormat) // "yyyy-MM-ddTHH:mm:ssZ"
|
||||
}
|
||||
se := ""
|
||||
if !expiryTime.IsZero() {
|
||||
se = expiryTime.Format(SASTimeFormat) // "yyyy-MM-ddTHH:mm:ssZ"
|
||||
}
|
||||
return ss, se
|
||||
}
|
||||
|
||||
// AccountSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage account.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/constructing-an-account-sas
|
||||
type AccountSASSignatureValues struct {
|
||||
Version string `param:"sv"` // If not specified, this defaults to azstorage.SASVersion
|
||||
Protocol string `param:"spr"` // See the SASProtocol* constants
|
||||
StartTime time.Time `param:"st"` // Not specified if IsZero
|
||||
ExpiryTime time.Time `param:"se"` // Not specified if IsZero
|
||||
Permissions string `param:"sp"`
|
||||
IPRange IPRange `param:"sip"`
|
||||
Services string `param:"ss"`
|
||||
ResourceTypes string `param:"srt"`
|
||||
Version string `param:"sv"` // If not specified, this defaults to SASVersion
|
||||
Protocol SASProtocol `param:"spr"` // See the SASProtocol* constants
|
||||
StartTime time.Time `param:"st"` // Not specified if IsZero
|
||||
ExpiryTime time.Time `param:"se"` // Not specified if IsZero
|
||||
Permissions string `param:"sp"` // Create by initializing a AccountSASPermissions and then call String()
|
||||
IPRange IPRange `param:"sip"`
|
||||
Services string `param:"ss"` // Create by initializing AccountSASServices and then call String()
|
||||
ResourceTypes string `param:"srt"` // Create by initializing AccountSASResourceTypes and then call String()
|
||||
}
|
||||
|
||||
// NewSASQueryParameters uses an account's shared key credential to sign this signature values to produce
|
||||
|
@ -53,6 +30,12 @@ func (v AccountSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Sh
|
|||
if v.Version == "" {
|
||||
v.Version = SASVersion
|
||||
}
|
||||
perms := &AccountSASPermissions{}
|
||||
if err := perms.Parse(v.Permissions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
v.Permissions = perms.String()
|
||||
|
||||
startTime, expiryTime := FormatTimesForSASSigning(v.StartTime, v.ExpiryTime)
|
||||
|
||||
stringToSign := strings.Join([]string{
|
||||
|
@ -63,7 +46,7 @@ func (v AccountSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Sh
|
|||
startTime,
|
||||
expiryTime,
|
||||
v.IPRange.String(),
|
||||
v.Protocol,
|
||||
string(v.Protocol),
|
||||
v.Version,
|
||||
""}, // That right, the account SAS requires a terminating extra newline
|
||||
"\n")
|
||||
|
@ -71,19 +54,19 @@ func (v AccountSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Sh
|
|||
signature := sharedKeyCredential.ComputeHMACSHA256(stringToSign)
|
||||
p := SASQueryParameters{
|
||||
// Common SAS parameters
|
||||
Version: v.Version,
|
||||
Protocol: v.Protocol,
|
||||
StartTime: v.StartTime,
|
||||
ExpiryTime: v.ExpiryTime,
|
||||
Permissions: v.Permissions,
|
||||
IPRange: v.IPRange,
|
||||
version: v.Version,
|
||||
protocol: v.Protocol,
|
||||
startTime: v.StartTime,
|
||||
expiryTime: v.ExpiryTime,
|
||||
permissions: v.Permissions,
|
||||
ipRange: v.IPRange,
|
||||
|
||||
// Account-specific SAS parameters
|
||||
Services: v.Services,
|
||||
ResourceTypes: v.ResourceTypes,
|
||||
services: v.Services,
|
||||
resourceTypes: v.ResourceTypes,
|
||||
|
||||
// Calculated SAS signature
|
||||
Signature: signature,
|
||||
signature: signature,
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
@ -125,6 +108,34 @@ func (p AccountSASPermissions) String() string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
// Parse initializes the AccountSASPermissions's fields from a string.
|
||||
func (p *AccountSASPermissions) Parse(s string) error {
|
||||
*p = AccountSASPermissions{} // Clear out the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 'r':
|
||||
p.Read = true
|
||||
case 'w':
|
||||
p.Write = true
|
||||
case 'd':
|
||||
p.Delete = true
|
||||
case 'l':
|
||||
p.List = true
|
||||
case 'a':
|
||||
p.Add = true
|
||||
case 'c':
|
||||
p.Create = true
|
||||
case 'u':
|
||||
p.Update = true
|
||||
case 'p':
|
||||
p.Process = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid permission character: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// The AccountSASServices type simplifies creating the services string for an Azure Storage Account SAS.
|
||||
// Initialize an instance of this type and then call its String method to set AccountSASSignatureValues's Services field.
|
||||
type AccountSASServices struct {
|
||||
|
@ -147,6 +158,24 @@ func (s AccountSASServices) String() string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
// Parse initializes the AccountSASServices' fields from a string.
|
||||
func (a *AccountSASServices) Parse(s string) error {
|
||||
*a = AccountSASServices{} // Clear out the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 'b':
|
||||
a.Blob = true
|
||||
case 'q':
|
||||
a.Queue = true
|
||||
case 'f':
|
||||
a.File = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid service character: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// The AccountSASResourceTypes type simplifies creating the resource types string for an Azure Storage Account SAS.
|
||||
// Initialize an instance of this type and then call its String method to set AccountSASSignatureValues's ResourceTypes field.
|
||||
type AccountSASResourceTypes struct {
|
||||
|
@ -168,3 +197,21 @@ func (rt AccountSASResourceTypes) String() string {
|
|||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
// Parse initializes the AccountSASResourceType's fields from a string.
|
||||
func (rt *AccountSASResourceTypes) Parse(s string) error {
|
||||
*rt = AccountSASResourceTypes{} // Clear out the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 's':
|
||||
rt.Service = true
|
||||
case 'q':
|
||||
rt.Container = true
|
||||
case 'o':
|
||||
rt.Object = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid resource type: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,6 +7,33 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// SASVersion indicates the SAS version.
|
||||
const SASVersion = "2015-04-05"
|
||||
|
||||
type SASProtocol string
|
||||
|
||||
const (
|
||||
// SASProtocolHTTPS can be specified for a SAS protocol
|
||||
SASProtocolHTTPS SASProtocol = "https"
|
||||
|
||||
// SASProtocolHTTPSandHTTP can be specified for a SAS protocol
|
||||
SASProtocolHTTPSandHTTP SASProtocol = "https,http"
|
||||
)
|
||||
|
||||
// FormatTimesForSASSigning converts a time.Time to a snapshotTimeFormat string suitable for a
|
||||
// SASField's StartTime or ExpiryTime fields. Returns "" if value.IsZero().
|
||||
func FormatTimesForSASSigning(startTime, expiryTime time.Time) (string, string) {
|
||||
ss := ""
|
||||
if !startTime.IsZero() {
|
||||
ss = startTime.Format(SASTimeFormat) // "yyyy-MM-ddTHH:mm:ssZ"
|
||||
}
|
||||
se := ""
|
||||
if !expiryTime.IsZero() {
|
||||
se = expiryTime.Format(SASTimeFormat) // "yyyy-MM-ddTHH:mm:ssZ"
|
||||
}
|
||||
return ss, se
|
||||
}
|
||||
|
||||
// SASTimeFormat represents the format of a SAS start or expiry time. Use it when formatting/parsing a time.Time.
|
||||
const SASTimeFormat = "2006-01-02T15:04:05Z" //"2017-07-27T00:00:00Z" // ISO 8601
|
||||
|
||||
|
@ -20,17 +47,56 @@ const SASTimeFormat = "2006-01-02T15:04:05Z" //"2017-07-27T00:00:00Z" // ISO 860
|
|||
// This type defines the components used by all Azure Storage resources (Containers, Blobs, Files, & Queues).
|
||||
type SASQueryParameters struct {
|
||||
// All members are immutable or values so copies of this struct are goroutine-safe.
|
||||
Version string `param:"sv"`
|
||||
Services string `param:"ss"`
|
||||
ResourceTypes string `param:"srt"`
|
||||
Protocol string `param:"spr"`
|
||||
StartTime time.Time `param:"st"`
|
||||
ExpiryTime time.Time `param:"se"`
|
||||
IPRange IPRange `param:"sip"`
|
||||
Identifier string `param:"si"`
|
||||
Resource string `param:"sr"`
|
||||
Permissions string `param:"sp"`
|
||||
Signature string `param:"sig"`
|
||||
version string `param:"sv"`
|
||||
services string `param:"ss"`
|
||||
resourceTypes string `param:"srt"`
|
||||
protocol SASProtocol `param:"spr"`
|
||||
startTime time.Time `param:"st"`
|
||||
expiryTime time.Time `param:"se"`
|
||||
ipRange IPRange `param:"sip"`
|
||||
identifier string `param:"si"`
|
||||
resource string `param:"sr"`
|
||||
permissions string `param:"sp"`
|
||||
signature string `param:"sig"`
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) Version() string {
|
||||
return p.version
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) Services() string {
|
||||
return p.services
|
||||
}
|
||||
func (p *SASQueryParameters) ResourceTypes() string {
|
||||
return p.resourceTypes
|
||||
}
|
||||
func (p *SASQueryParameters) Protocol() SASProtocol {
|
||||
return p.protocol
|
||||
}
|
||||
func (p *SASQueryParameters) StartTime() time.Time {
|
||||
return p.startTime
|
||||
}
|
||||
func (p *SASQueryParameters) ExpiryTime() time.Time {
|
||||
return p.expiryTime
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) IPRange() IPRange {
|
||||
return p.ipRange
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) Identifier() string {
|
||||
return p.identifier
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) Resource() string {
|
||||
return p.resource
|
||||
}
|
||||
func (p *SASQueryParameters) Permissions() string {
|
||||
return p.permissions
|
||||
}
|
||||
|
||||
func (p *SASQueryParameters) Signature() string {
|
||||
return p.signature
|
||||
}
|
||||
|
||||
// IPRange represents a SAS IP range's start IP and (optionally) end IP.
|
||||
|
@ -55,40 +121,40 @@ func (ipr *IPRange) String() string {
|
|||
// query parameter map's passed-in values. If deleteSASParametersFromValues is true,
|
||||
// all SAS-related query parameters are removed from the passed-in map. If
|
||||
// deleteSASParametersFromValues is false, the map passed-in map is unaltered.
|
||||
func NewSASQueryParameters(values url.Values, deleteSASParametersFromValues bool) SASQueryParameters {
|
||||
func newSASQueryParameters(values url.Values, deleteSASParametersFromValues bool) SASQueryParameters {
|
||||
p := SASQueryParameters{}
|
||||
for k, v := range values {
|
||||
val := v[0]
|
||||
isSASKey := true
|
||||
switch strings.ToLower(k) {
|
||||
case "sv":
|
||||
p.Version = val
|
||||
p.version = val
|
||||
case "ss":
|
||||
p.Services = val
|
||||
p.services = val
|
||||
case "srt":
|
||||
p.ResourceTypes = val
|
||||
p.resourceTypes = val
|
||||
case "spr":
|
||||
p.Protocol = val
|
||||
p.protocol = SASProtocol(val)
|
||||
case "st":
|
||||
p.StartTime, _ = time.Parse(SASTimeFormat, val)
|
||||
p.startTime, _ = time.Parse(SASTimeFormat, val)
|
||||
case "se":
|
||||
p.ExpiryTime, _ = time.Parse(SASTimeFormat, val)
|
||||
p.expiryTime, _ = time.Parse(SASTimeFormat, val)
|
||||
case "sip":
|
||||
dashIndex := strings.Index(val, "-")
|
||||
if dashIndex == -1 {
|
||||
p.IPRange.Start = net.ParseIP(val)
|
||||
p.ipRange.Start = net.ParseIP(val)
|
||||
} else {
|
||||
p.IPRange.Start = net.ParseIP(val[:dashIndex])
|
||||
p.IPRange.End = net.ParseIP(val[dashIndex+1:])
|
||||
p.ipRange.Start = net.ParseIP(val[:dashIndex])
|
||||
p.ipRange.End = net.ParseIP(val[dashIndex+1:])
|
||||
}
|
||||
case "si":
|
||||
p.Identifier = val
|
||||
p.identifier = val
|
||||
case "sr":
|
||||
p.Resource = val
|
||||
p.resource = val
|
||||
case "sp":
|
||||
p.Permissions = val
|
||||
p.permissions = val
|
||||
case "sig":
|
||||
p.Signature = val
|
||||
p.signature = val
|
||||
default:
|
||||
isSASKey = false // We didn't recognize the query parameter
|
||||
}
|
||||
|
@ -100,39 +166,39 @@ func NewSASQueryParameters(values url.Values, deleteSASParametersFromValues bool
|
|||
}
|
||||
|
||||
// AddToValues adds the SAS components to the specified query parameters map.
|
||||
func (p *SASQueryParameters) AddToValues(v url.Values) url.Values {
|
||||
if p.Version != "" {
|
||||
v.Add("sv", p.Version)
|
||||
func (p *SASQueryParameters) addToValues(v url.Values) url.Values {
|
||||
if p.version != "" {
|
||||
v.Add("sv", p.version)
|
||||
}
|
||||
if p.Services != "" {
|
||||
v.Add("ss", p.Services)
|
||||
if p.services != "" {
|
||||
v.Add("ss", p.services)
|
||||
}
|
||||
if p.ResourceTypes != "" {
|
||||
v.Add("srt", p.ResourceTypes)
|
||||
if p.resourceTypes != "" {
|
||||
v.Add("srt", p.resourceTypes)
|
||||
}
|
||||
if p.Protocol != "" {
|
||||
v.Add("spr", p.Protocol)
|
||||
if p.protocol != "" {
|
||||
v.Add("spr", string(p.protocol))
|
||||
}
|
||||
if !p.StartTime.IsZero() {
|
||||
v.Add("st", p.StartTime.Format(SASTimeFormat))
|
||||
if !p.startTime.IsZero() {
|
||||
v.Add("st", p.startTime.Format(SASTimeFormat))
|
||||
}
|
||||
if !p.ExpiryTime.IsZero() {
|
||||
v.Add("se", p.ExpiryTime.Format(SASTimeFormat))
|
||||
if !p.expiryTime.IsZero() {
|
||||
v.Add("se", p.expiryTime.Format(SASTimeFormat))
|
||||
}
|
||||
if len(p.IPRange.Start) > 0 {
|
||||
v.Add("sip", p.IPRange.String())
|
||||
if len(p.ipRange.Start) > 0 {
|
||||
v.Add("sip", p.ipRange.String())
|
||||
}
|
||||
if p.Identifier != "" {
|
||||
v.Add("si", p.Identifier)
|
||||
if p.identifier != "" {
|
||||
v.Add("si", p.identifier)
|
||||
}
|
||||
if p.Resource != "" {
|
||||
v.Add("sr", p.Resource)
|
||||
if p.resource != "" {
|
||||
v.Add("sr", p.resource)
|
||||
}
|
||||
if p.Permissions != "" {
|
||||
v.Add("sp", p.Permissions)
|
||||
if p.permissions != "" {
|
||||
v.Add("sp", p.permissions)
|
||||
}
|
||||
if p.Signature != "" {
|
||||
v.Add("sig", p.Signature)
|
||||
if p.signature != "" {
|
||||
v.Add("sig", p.signature)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
@ -140,6 +206,6 @@ func (p *SASQueryParameters) AddToValues(v url.Values) url.Values {
|
|||
// Encode encodes the SAS query parameters into URL encoded form sorted by key.
|
||||
func (p *SASQueryParameters) Encode() string {
|
||||
v := url.Values{}
|
||||
p.AddToValues(v)
|
||||
p.addToValues(v)
|
||||
return v.Encode()
|
||||
}
|
||||
|
|
|
@ -2,21 +2,22 @@ package azblob
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BlobSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage container or blob.
|
||||
type BlobSASSignatureValues struct {
|
||||
Version string `param:"sv"` // If not specified, this defaults to SASVersion
|
||||
Protocol string `param:"spr"` // See the SASProtocol* constants
|
||||
StartTime time.Time `param:"st"` // Not specified if IsZero
|
||||
ExpiryTime time.Time `param:"se"` // Not specified if IsZero
|
||||
Permissions string `param:"sp"`
|
||||
IPRange IPRange `param:"sip"`
|
||||
Version string `param:"sv"` // If not specified, this defaults to SASVersion
|
||||
Protocol SASProtocol `param:"spr"` // See the SASProtocol* constants
|
||||
StartTime time.Time `param:"st"` // Not specified if IsZero
|
||||
ExpiryTime time.Time `param:"se"` // Not specified if IsZero
|
||||
Permissions string `param:"sp"` // Create by initializing a ContainerSASPermissions or BlobSASPermissions and then call String()
|
||||
IPRange IPRange `param:"sip"`
|
||||
Identifier string `param:"si"`
|
||||
ContainerName string
|
||||
BlobName string // Use "" to create a Container SAS
|
||||
Identifier string `param:"si"`
|
||||
CacheControl string // rscc
|
||||
ContentDisposition string // rscd
|
||||
ContentEncoding string // rsce
|
||||
|
@ -32,8 +33,21 @@ func (v BlobSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Share
|
|||
}
|
||||
|
||||
resource := "c"
|
||||
if v.BlobName != "" {
|
||||
if v.BlobName == "" {
|
||||
// Make sure the permission characters are in the correct order
|
||||
perms := &ContainerSASPermissions{}
|
||||
if err := perms.Parse(v.Permissions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
v.Permissions = perms.String()
|
||||
} else {
|
||||
resource = "b"
|
||||
// Make sure the permission characters are in the correct order
|
||||
perms := &BlobSASPermissions{}
|
||||
if err := perms.Parse(v.Permissions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
v.Permissions = perms.String()
|
||||
}
|
||||
if v.Version == "" {
|
||||
v.Version = SASVersion
|
||||
|
@ -48,7 +62,7 @@ func (v BlobSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Share
|
|||
getCanonicalName(sharedKeyCredential.AccountName(), v.ContainerName, v.BlobName),
|
||||
v.Identifier,
|
||||
v.IPRange.String(),
|
||||
v.Protocol,
|
||||
string(v.Protocol),
|
||||
v.Version,
|
||||
v.CacheControl, // rscc
|
||||
v.ContentDisposition, // rscd
|
||||
|
@ -60,19 +74,19 @@ func (v BlobSASSignatureValues) NewSASQueryParameters(sharedKeyCredential *Share
|
|||
|
||||
p := SASQueryParameters{
|
||||
// Common SAS parameters
|
||||
Version: v.Version,
|
||||
Protocol: v.Protocol,
|
||||
StartTime: v.StartTime,
|
||||
ExpiryTime: v.ExpiryTime,
|
||||
Permissions: v.Permissions,
|
||||
IPRange: v.IPRange,
|
||||
version: v.Version,
|
||||
protocol: v.Protocol,
|
||||
startTime: v.StartTime,
|
||||
expiryTime: v.ExpiryTime,
|
||||
permissions: v.Permissions,
|
||||
ipRange: v.IPRange,
|
||||
|
||||
// Container/Blob-specific SAS parameters
|
||||
Resource: resource,
|
||||
Identifier: v.Identifier,
|
||||
resource: resource,
|
||||
identifier: v.Identifier,
|
||||
|
||||
// Calculated SAS signature
|
||||
Signature: signature,
|
||||
signature: signature,
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
@ -120,13 +134,27 @@ func (p ContainerSASPermissions) String() string {
|
|||
}
|
||||
|
||||
// Parse initializes the ContainerSASPermissions's fields from a string.
|
||||
func (p *ContainerSASPermissions) Parse(s string) {
|
||||
p.Read = strings.ContainsRune(s, 'r')
|
||||
p.Add = strings.ContainsRune(s, 'a')
|
||||
p.Create = strings.ContainsRune(s, 'c')
|
||||
p.Write = strings.ContainsRune(s, 'w')
|
||||
p.Delete = strings.ContainsRune(s, 'd')
|
||||
p.List = strings.ContainsRune(s, 'l')
|
||||
func (p *ContainerSASPermissions) Parse(s string) error {
|
||||
*p = ContainerSASPermissions{} // Clear the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 'r':
|
||||
p.Read = true
|
||||
case 'a':
|
||||
p.Add = true
|
||||
case 'c':
|
||||
p.Create = true
|
||||
case 'w':
|
||||
p.Write = true
|
||||
case 'd':
|
||||
p.Delete = true
|
||||
case 'l':
|
||||
p.List = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid permission: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// The BlobSASPermissions type simplifies creating the permissions string for an Azure Storage blob SAS.
|
||||
|
@ -156,10 +184,23 @@ func (p BlobSASPermissions) String() string {
|
|||
}
|
||||
|
||||
// Parse initializes the BlobSASPermissions's fields from a string.
|
||||
func (p *BlobSASPermissions) Parse(s string) {
|
||||
p.Read = strings.ContainsRune(s, 'r')
|
||||
p.Add = strings.ContainsRune(s, 'a')
|
||||
p.Create = strings.ContainsRune(s, 'c')
|
||||
p.Write = strings.ContainsRune(s, 'w')
|
||||
p.Delete = strings.ContainsRune(s, 'd')
|
||||
func (p *BlobSASPermissions) Parse(s string) error {
|
||||
*p = BlobSASPermissions{} // Clear the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 'r':
|
||||
p.Read = true
|
||||
case 'a':
|
||||
p.Add = true
|
||||
case 'c':
|
||||
p.Create = true
|
||||
case 'w':
|
||||
p.Write = true
|
||||
case 'd':
|
||||
p.Delete = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid permission: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ import (
|
|||
"github.com/Azure/azure-pipeline-go/pipeline"
|
||||
)
|
||||
|
||||
const (
|
||||
// AppendBlobMaxAppendBlockBytes indicates the maximum number of bytes that can be sent in a call to AppendBlock.
|
||||
AppendBlobMaxAppendBlockBytes = 4 * 1024 * 1024 // 4MB
|
||||
|
||||
// AppendBlobMaxBlocks indicates the maximum number of blocks allowed in an append blob.
|
||||
AppendBlobMaxBlocks = 50000
|
||||
)
|
||||
|
||||
// AppendBlobURL defines a set of operations applicable to append blobs.
|
||||
type AppendBlobURL struct {
|
||||
BlobURL
|
||||
|
@ -37,7 +45,7 @@ func (ab AppendBlobURL) WithSnapshot(snapshot time.Time) AppendBlobURL {
|
|||
|
||||
// Create creates a 0-length append blob. Call AppendBlock to append data to an append blob.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
|
||||
func (ab AppendBlobURL) Create(ctx context.Context, metadata Metadata, h BlobHTTPHeaders, ac BlobAccessConditions) (*BlobsPutResponse, error) {
|
||||
func (ab AppendBlobURL) Create(ctx context.Context, h BlobHTTPHeaders, metadata Metadata, ac BlobAccessConditions) (*BlobsPutResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch := ac.HTTPAccessConditions.pointers()
|
||||
return ab.blobClient.Put(ctx, BlobAppendBlob, nil, nil, nil,
|
||||
&h.ContentType, &h.ContentEncoding, &h.ContentLanguage, h.contentMD5Pointer(), &h.CacheControl,
|
||||
|
@ -48,6 +56,7 @@ func (ab AppendBlobURL) Create(ctx context.Context, metadata Metadata, h BlobHTT
|
|||
}
|
||||
|
||||
// AppendBlock commits a new block of data to the end of the existing append blob.
|
||||
// Note that the http client closes the body stream after the request is sent to the service.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/append-block.
|
||||
func (ab AppendBlobURL) AppendBlock(ctx context.Context, body io.ReadSeeker, ac BlobAccessConditions) (*AppendBlobsAppendBlockResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.HTTPAccessConditions.pointers()
|
||||
|
|
|
@ -196,12 +196,12 @@ func (b BlobURL) ReleaseLease(ctx context.Context, leaseID string, ac HTTPAccess
|
|||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag, nil)
|
||||
}
|
||||
|
||||
// BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant to break
|
||||
// a fixed-duration lease when it expires or an infinite lease immediately.
|
||||
// BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1)
|
||||
// constant to break a fixed-duration lease when it expires or an infinite lease immediately.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/lease-blob.
|
||||
func (b BlobURL) BreakLease(ctx context.Context, leaseID string, breakPeriodInSeconds int32, ac HTTPAccessConditions) (*BlobsLeaseResponse, error) {
|
||||
func (b BlobURL) BreakLease(ctx context.Context, breakPeriodInSeconds int32, ac HTTPAccessConditions) (*BlobsLeaseResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.pointers()
|
||||
return b.blobClient.Lease(ctx, LeaseActionBreak, nil, &leaseID, leasePeriodPointer(breakPeriodInSeconds), nil, nil,
|
||||
return b.blobClient.Lease(ctx, LeaseActionBreak, nil, nil, leasePeriodPointer(breakPeriodInSeconds), nil, nil,
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ func (bb BlockBlobURL) WithSnapshot(snapshot time.Time) BlockBlobURL {
|
|||
// PutBlob creates a new block blob, or updates the content of an existing block blob.
|
||||
// Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not
|
||||
// supported with PutBlob; the content of the existing blob is overwritten with the new content. To
|
||||
// perform a partial update of a block blob's, use PutBlock and PutBlockList.
|
||||
// perform a partial update of a block blob's, use PutBlock and PutBlockList. Note that the http client
|
||||
// closes the body stream after the request is sent to the service.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
|
||||
func (bb BlockBlobURL) PutBlob(ctx context.Context, body io.ReadSeeker, h BlobHTTPHeaders, metadata Metadata, ac BlobAccessConditions) (*BlobsPutResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.HTTPAccessConditions.pointers()
|
||||
|
@ -69,6 +70,7 @@ func (bb BlockBlobURL) GetBlockList(ctx context.Context, listType BlockListType,
|
|||
}
|
||||
|
||||
// PutBlock uploads the specified block to the block blob's "staging area" to be later committed by a call to PutBlockList.
|
||||
// Note that the http client closes the body stream after the request is sent to the service.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-block.
|
||||
func (bb BlockBlobURL) PutBlock(ctx context.Context, base64BlockID string, body io.ReadSeeker, ac LeaseAccessConditions) (*BlockBlobsPutBlockResponse, error) {
|
||||
return bb.bbClient.PutBlock(ctx, base64BlockID, body, nil, ac.pointers(), nil)
|
||||
|
@ -80,8 +82,8 @@ func (bb BlockBlobURL) PutBlock(ctx context.Context, base64BlockID string, body
|
|||
// by uploading only those blocks that have changed, then committing the new and existing
|
||||
// blocks together. Any blocks not specified in the block list and permanently deleted.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-block-list.
|
||||
func (bb BlockBlobURL) PutBlockList(ctx context.Context, base64BlockIDs []string, metadata Metadata,
|
||||
h BlobHTTPHeaders, ac BlobAccessConditions) (*BlockBlobsPutBlockListResponse, error) {
|
||||
func (bb BlockBlobURL) PutBlockList(ctx context.Context, base64BlockIDs []string, h BlobHTTPHeaders,
|
||||
metadata Metadata, ac BlobAccessConditions) (*BlockBlobsPutBlockListResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.HTTPAccessConditions.pointers()
|
||||
return bb.bbClient.PutBlockList(ctx, BlockLookupList{Latest: base64BlockIDs}, nil,
|
||||
&h.CacheControl, &h.ContentType, &h.ContentEncoding, &h.ContentLanguage, h.contentMD5Pointer(),
|
||||
|
|
|
@ -3,6 +3,7 @@ package azblob
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
@ -152,13 +153,27 @@ func (p AccessPolicyPermission) String() string {
|
|||
}
|
||||
|
||||
// Parse initializes the AccessPolicyPermission's fields from a string.
|
||||
func (p *AccessPolicyPermission) Parse(s string) {
|
||||
p.Read = strings.ContainsRune(s, 'r')
|
||||
p.Add = strings.ContainsRune(s, 'a')
|
||||
p.Create = strings.ContainsRune(s, 'c')
|
||||
p.Write = strings.ContainsRune(s, 'w')
|
||||
p.Delete = strings.ContainsRune(s, 'd')
|
||||
p.List = strings.ContainsRune(s, 'l')
|
||||
func (p *AccessPolicyPermission) Parse(s string) error {
|
||||
*p = AccessPolicyPermission{} // Clear the flags
|
||||
for _, r := range s {
|
||||
switch r {
|
||||
case 'r':
|
||||
p.Read = true
|
||||
case 'a':
|
||||
p.Add = true
|
||||
case 'c':
|
||||
p.Create = true
|
||||
case 'w':
|
||||
p.Write = true
|
||||
case 'd':
|
||||
p.Delete = true
|
||||
case 'l':
|
||||
p.List = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid permission: '%v'", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPermissions sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly.
|
||||
|
@ -196,9 +211,9 @@ func (c ContainerURL) ReleaseLease(ctx context.Context, leaseID string, ac HTTPA
|
|||
|
||||
// BreakLease breaks the container's previously-acquired lease (if it exists).
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/lease-container.
|
||||
func (c ContainerURL) BreakLease(ctx context.Context, leaseID string, period int32, ac HTTPAccessConditions) (*ContainerLeaseResponse, error) {
|
||||
func (c ContainerURL) BreakLease(ctx context.Context, period int32, ac HTTPAccessConditions) (*ContainerLeaseResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, _, _ := ac.pointers()
|
||||
return c.client.Lease(ctx, LeaseActionBreak, nil, &leaseID, leasePeriodPointer(period), nil, nil, ifModifiedSince, ifUnmodifiedSince, nil)
|
||||
return c.client.Lease(ctx, LeaseActionBreak, nil, nil, leasePeriodPointer(period), nil, nil, ifModifiedSince, ifUnmodifiedSince, nil)
|
||||
}
|
||||
|
||||
// ChangeLease changes the container's lease ID.
|
||||
|
|
|
@ -50,7 +50,7 @@ func (pb PageBlobURL) WithSnapshot(snapshot time.Time) PageBlobURL {
|
|||
|
||||
// Create creates a page blob of the specified length. Call PutPage to upload data data to a page blob.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
|
||||
func (pb PageBlobURL) Create(ctx context.Context, size int64, sequenceNumber int64, metadata Metadata, h BlobHTTPHeaders, ac BlobAccessConditions) (*BlobsPutResponse, error) {
|
||||
func (pb PageBlobURL) Create(ctx context.Context, size int64, sequenceNumber int64, h BlobHTTPHeaders, metadata Metadata, ac BlobAccessConditions) (*BlobsPutResponse, error) {
|
||||
if sequenceNumber < 0 {
|
||||
panic("sequenceNumber must be greater than or equal to 0")
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ func (pb PageBlobURL) Create(ctx context.Context, size int64, sequenceNumber int
|
|||
}
|
||||
|
||||
// PutPages writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512.
|
||||
// Note that the http client closes the body stream after the request is sent to the service.
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-page.
|
||||
func (pb PageBlobURL) PutPages(ctx context.Context, pr PageRange, body io.ReadSeeker, ac BlobAccessConditions) (*PageBlobsPutPageResponse, error) {
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.HTTPAccessConditions.pointers()
|
||||
|
@ -99,13 +100,13 @@ func (pb PageBlobURL) GetPageRangesDiff(ctx context.Context, br BlobRange, prevS
|
|||
|
||||
// Resize resizes the page blob to the specified size (which must be a multiple of 512).
|
||||
// For more information, see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties.
|
||||
func (pb PageBlobURL) Resize(ctx context.Context, length int64, ac BlobAccessConditions) (*BlobsSetPropertiesResponse, error) {
|
||||
if length%PageBlobPageBytes != 0 {
|
||||
panic("Length must be a multiple of PageBlobPageBytes (512)")
|
||||
func (pb PageBlobURL) Resize(ctx context.Context, size int64, ac BlobAccessConditions) (*BlobsSetPropertiesResponse, error) {
|
||||
if size%PageBlobPageBytes != 0 {
|
||||
panic("Size must be a multiple of PageBlobPageBytes (512)")
|
||||
}
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.HTTPAccessConditions.pointers()
|
||||
return pb.blobClient.SetProperties(ctx, nil, nil, nil, nil, nil, nil, ac.LeaseAccessConditions.pointers(),
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag, nil, &length, SequenceNumberActionNone, nil, nil)
|
||||
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag, nil, &size, SequenceNumberActionNone, nil, nil)
|
||||
}
|
||||
|
||||
// SetSequenceNumber sets the page blob's sequence number.
|
||||
|
|
|
@ -297,10 +297,9 @@ func ExampleAccountSASSignatureValues() {
|
|||
serviceURL := NewServiceURL(*u, NewPipeline(NewAnonymousCredential(), PipelineOptions{}))
|
||||
// Now, you can use this serviceURL just like any other to make requests of the resource.
|
||||
|
||||
// If you have a SAS query parameter string, you can parse it into its parts:
|
||||
values, _ := url.ParseQuery(qp)
|
||||
sasQueryParams = NewSASQueryParameters(values, true)
|
||||
fmt.Printf("SAS expiry time=%v", sasQueryParams.ExpiryTime)
|
||||
// You can parse a URL into its constituent parts:
|
||||
blobURLParts := NewBlobURLParts(serviceURL.URL())
|
||||
fmt.Printf("SAS expiry time=%v", blobURLParts.SAS.ExpiryTime())
|
||||
|
||||
_ = serviceURL // Avoid compiler's "declared and not used" error
|
||||
}
|
||||
|
@ -347,9 +346,8 @@ func ExampleBlobSASSignatureValues() {
|
|||
// Now, you can use this blobURL just like any other to make requests of the resource.
|
||||
|
||||
// If you have a SAS query parameter string, you can parse it into its parts:
|
||||
values, _ := url.ParseQuery(qp)
|
||||
sasQueryParams = NewSASQueryParameters(values, true)
|
||||
fmt.Printf("SAS expiry time=%v", sasQueryParams.ExpiryTime)
|
||||
blobURLParts := NewBlobURLParts(blobURL.URL())
|
||||
fmt.Printf("SAS expiry time=%v", blobURLParts.SAS.ExpiryTime())
|
||||
|
||||
_ = blobURL // Avoid compiler's "declared and not used" error
|
||||
}
|
||||
|
@ -650,7 +648,7 @@ func ExampleBlockBlobURL() {
|
|||
}
|
||||
|
||||
// After all the blocks are uploaded, atomically commit them to the blob.
|
||||
_, err := blobURL.PutBlockList(ctx, base64BlockIDs, Metadata{}, BlobHTTPHeaders{}, BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, base64BlockIDs, BlobHTTPHeaders{}, Metadata{}, BlobAccessConditions{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -688,7 +686,7 @@ func ExampleAppendBlobURL() {
|
|||
appendBlobURL := NewAppendBlobURL(*u, NewPipeline(NewSharedKeyCredential(accountName, accountKey), PipelineOptions{}))
|
||||
|
||||
ctx := context.Background() // This example uses a never-expiring context
|
||||
_, err := appendBlobURL.Create(ctx, Metadata{}, BlobHTTPHeaders{}, BlobAccessConditions{})
|
||||
_, err := appendBlobURL.Create(ctx, BlobHTTPHeaders{}, Metadata{}, BlobAccessConditions{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -722,7 +720,7 @@ func ExamplePageBlobURL() {
|
|||
NewPipeline(NewSharedKeyCredential(accountName, accountKey), PipelineOptions{}))
|
||||
|
||||
ctx := context.Background() // This example uses a never-expiring context
|
||||
_, err := blobURL.Create(ctx, PageBlobPageBytes*4, 0, Metadata{}, BlobHTTPHeaders{}, BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, PageBlobPageBytes*4, 0, BlobHTTPHeaders{}, Metadata{}, BlobAccessConditions{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ func createNewBlockBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.Bl
|
|||
func createNewAppendBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.AppendBlobURL, name string) {
|
||||
blob, name = getAppendBlobURL(c, container)
|
||||
|
||||
resp, err := blob.Create(ctx, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
resp, err := blob.Create(ctx, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(resp.StatusCode(), chk.Equals, 201)
|
||||
|
@ -179,7 +179,7 @@ func createNewAppendBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.A
|
|||
func createNewPageBlob(c *chk.C, container azblob.ContainerURL) (blob azblob.PageBlobURL, name string) {
|
||||
blob, name = getPageBlobURL(c, container)
|
||||
|
||||
resp, err := blob.Create(ctx, azblob.PageBlobPageBytes*10, 0, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
resp, err := blob.Create(ctx, azblob.PageBlobPageBytes*10, 0, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(resp.StatusCode(), chk.Equals, 201)
|
||||
|
@ -3275,7 +3275,7 @@ func (s *aztestsSuite) TestBlobGetBlockListCommitted(c *chk.C) {
|
|||
_, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0000"}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
|
||||
resp, err := blobURL.GetBlockList(ctx, azblob.BlockListCommitted, azblob.LeaseAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
@ -3319,7 +3319,7 @@ func (s *aztestsSuite) TestBlobGetBlockListBothNotEmpty(c *chk.C) {
|
|||
c.Assert(err, chk.IsNil)
|
||||
_, err = blobURL.PutBlock(ctx, "0001", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0001", "0000"}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0001", "0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
// Put two uncommitted blocks
|
||||
|
@ -3357,7 +3357,7 @@ func (s *aztestsSuite) TestBlobGetBlockListSnapshot(c *chk.C) {
|
|||
|
||||
_, err := blobURL.PutBlock(ctx, "0000", strings.NewReader(blockBlobDefaultData), azblob.LeaseAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0000"}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0000"}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.CreateSnapshot(ctx, nil, azblob.BlobAccessConditions{})
|
||||
|
@ -3416,7 +3416,7 @@ func (s *aztestsSuite) TestBlobPutBlockListInvalidID(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id[:2]}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id[:2]}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
validateStorageError(c, err, azblob.ServiceCodeInvalidBlockID)
|
||||
}
|
||||
|
||||
|
@ -3424,7 +3424,7 @@ func (s *aztestsSuite) TestBlobPutBlockListDuplicateBlocks(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id, id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id, id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
|
||||
|
@ -3436,7 +3436,7 @@ func (s *aztestsSuite) TestBlobPutBlockListEmptyList(c *chk.C) {
|
|||
containerURL, blobURL, _ := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{}, azblob.Metadata{}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{}, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
|
||||
|
@ -3448,7 +3448,7 @@ func (s *aztestsSuite) TestBlobPutBlockListMetadataEmpty(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.Metadata{}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3460,7 +3460,7 @@ func (s *aztestsSuite) TestBlobPutBlockListMetadataNonEmpty(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, basicMetadata, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, basicMetadata, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3472,7 +3472,7 @@ func (s *aztestsSuite) TestBlobPutBlockListHTTPHeaders(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, basicHeaders, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, basicHeaders, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3484,10 +3484,10 @@ func (s *aztestsSuite) TestBlobPutBlockListHTTPHeadersEmpty(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{ContentDisposition: "my_disposition"}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3504,12 +3504,12 @@ func validateBlobCommitted(c *chk.C, blobURL azblob.BlockBlobURL) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfModifiedSinceTrue(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3522,7 +3522,7 @@ func (s *aztestsSuite) TestBlobPutBlockListIfModifiedSinceFalse(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -3530,12 +3530,12 @@ func (s *aztestsSuite) TestBlobPutBlockListIfModifiedSinceFalse(c *chk.C) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceTrue(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3544,12 +3544,12 @@ func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceTrue(c *chk.C) {
|
|||
|
||||
func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceFalse(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
|
@ -3558,10 +3558,10 @@ func (s *aztestsSuite) TestBlobPutBlockListIfUnmodifiedSinceFalse(c *chk.C) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfMatchTrue(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
resp, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
resp, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3571,10 +3571,10 @@ func (s *aztestsSuite) TestBlobPutBlockListIfMatchTrue(c *chk.C) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfMatchFalse(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
|
||||
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
|
@ -3583,10 +3583,10 @@ func (s *aztestsSuite) TestBlobPutBlockListIfMatchFalse(c *chk.C) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfNoneMatchTrue(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3596,10 +3596,10 @@ func (s *aztestsSuite) TestBlobPutBlockListIfNoneMatchTrue(c *chk.C) {
|
|||
func (s *aztestsSuite) TestBlobPutBlockListIfNoneMatchFalse(c *chk.C) {
|
||||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
resp, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
resp, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{}) // The blob must actually exist to have a modifed time
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{},
|
||||
_, err = blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{},nil,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
|
||||
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
|
@ -3609,7 +3609,7 @@ func (s *aztestsSuite) TestBlobPutBlockListValidateData(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
|
||||
|
||||
resp, err := blobURL.GetBlob(ctx, azblob.BlobRange{}, azblob.BlobAccessConditions{}, false)
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
@ -3621,7 +3621,7 @@ func (s *aztestsSuite) TestBlobPutBlockListModifyBlob(c *chk.C) {
|
|||
containerURL, blobURL, id := setupPutBlockListTest(c)
|
||||
defer deleteContainer(c, containerURL)
|
||||
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.PutBlockList(ctx, []string{id}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlock(ctx, "0001", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
|
||||
|
@ -3633,7 +3633,7 @@ func (s *aztestsSuite) TestBlobPutBlockListModifyBlob(c *chk.C) {
|
|||
_, err = blobURL.PutBlock(ctx, "0100", bytes.NewReader([]byte("new data")), azblob.LeaseAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0001", "0011"}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err = blobURL.PutBlockList(ctx, []string{"0001", "0011"}, azblob.BlobHTTPHeaders{}, nil,azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetBlockList(ctx, azblob.BlockListAll, azblob.LeaseAccessConditions{})
|
||||
|
@ -3650,7 +3650,7 @@ func (s *aztestsSuite) TestBlobCreateAppendMetadataNonEmpty(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getAppendBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, basicMetadata,azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3664,7 +3664,7 @@ func (s *aztestsSuite) TestBlobCreateAppendMetadataEmpty(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getAppendBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.Metadata{}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, azblob.Metadata{},azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3678,7 +3678,7 @@ func (s *aztestsSuite) TestBlobCreateAppendMetadataInvalid(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getAppendBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.Metadata{"In valid!": "bar"}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{}, azblob.Metadata{"In valid!": "bar"}, azblob.BlobAccessConditions{})
|
||||
c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
|
||||
}
|
||||
|
||||
|
@ -3688,7 +3688,7 @@ func (s *aztestsSuite) TestBlobCreateAppendHTTPHeaders(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getAppendBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, nil, basicHeaders, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, basicHeaders, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -3711,7 +3711,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfModifiedSinceTrue(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3726,7 +3726,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfModifiedSinceFalse(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -3739,7 +3739,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfUnmodifiedSinceTrue(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3754,7 +3754,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfUnmodifiedSinceFalse(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -3767,7 +3767,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfMatchTrue(c *chk.C) {
|
|||
|
||||
resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3780,7 +3780,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfMatchFalse(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := createNewAppendBlob(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -3791,7 +3791,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfNoneMatchTrue(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := createNewAppendBlob(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -3806,7 +3806,7 @@ func (s *aztestsSuite) TestBlobCreateAppendIfNoneMatchFalse(c *chk.C) {
|
|||
|
||||
resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
||||
_, err := blobURL.Create(ctx, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -4050,7 +4050,7 @@ func (s *aztestsSuite) TestBlobCreatePageSizeInvalid(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getPageBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, 1, 0, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, 1, 0, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
validateStorageError(c, err, azblob.ServiceCodeInvalidHeaderValue)
|
||||
}
|
||||
|
||||
|
@ -4065,7 +4065,7 @@ func (s *aztestsSuite) TestBlobCreatePageSequenceInvalid(c *chk.C) {
|
|||
recover()
|
||||
}()
|
||||
|
||||
blobURL.Create(ctx, azblob.PageBlobPageBytes, -1, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
blobURL.Create(ctx, azblob.PageBlobPageBytes, -1, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Fail()
|
||||
|
||||
}
|
||||
|
@ -4076,7 +4076,7 @@ func (s *aztestsSuite) TestBlobCreatePageMetadataNonEmpty(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getPageBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, basicMetadata,azblob.BlobAccessConditions{})
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
@ -4089,7 +4089,7 @@ func (s *aztestsSuite) TestBlobCreatePageMetadataEmpty(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getPageBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.Metadata{}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
@ -4102,7 +4102,7 @@ func (s *aztestsSuite) TestBlobCreatePageMetadataInvalid(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getPageBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.Metadata{"In valid1": "bar"}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, azblob.Metadata{"In valid1": "bar"}, azblob.BlobAccessConditions{})
|
||||
c.Assert(strings.Contains(err.Error(), validationErrorSubstring), chk.Equals, true)
|
||||
|
||||
}
|
||||
|
@ -4113,7 +4113,7 @@ func (s *aztestsSuite) TestBlobCreatePageHTTPHeaders(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := getPageBlobURL(c, containerURL)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, nil, basicHeaders, azblob.BlobAccessConditions{})
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicHeaders, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
resp, err := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
@ -4136,7 +4136,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfModifiedSinceTrue(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{}, basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -4151,7 +4151,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfModifiedSinceFalse(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfModifiedSince: currentTime}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -4164,7 +4164,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfUnmodifiedSinceTrue(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(10)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -4179,7 +4179,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfUnmodifiedSinceFalse(c *chk.C) {
|
|||
|
||||
currentTime := getRelativeTimeGMT(-10)
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfUnmodifiedSince: currentTime}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -4192,7 +4192,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfMatchTrue(c *chk.C) {
|
|||
|
||||
resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: resp.ETag()}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -4205,7 +4205,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfMatchFalse(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfMatch: azblob.ETag("garbage")}})
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
}
|
||||
|
@ -4216,7 +4216,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfNoneMatchTrue(c *chk.C) {
|
|||
defer deleteContainer(c, containerURL)
|
||||
blobURL, _ := createNewPageBlob(c, containerURL) // Originally created without metadata
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: azblob.ETag("garbage")}})
|
||||
c.Assert(err, chk.IsNil)
|
||||
|
||||
|
@ -4231,7 +4231,7 @@ func (s *aztestsSuite) TestBlobCreatePageIfNoneMatchFalse(c *chk.C) {
|
|||
|
||||
resp, _ := blobURL.GetPropertiesAndMetadata(ctx, azblob.BlobAccessConditions{})
|
||||
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, basicMetadata, azblob.BlobHTTPHeaders{},
|
||||
_, err := blobURL.Create(ctx, azblob.PageBlobPageBytes, 0, azblob.BlobHTTPHeaders{},basicMetadata,
|
||||
azblob.BlobAccessConditions{HTTPAccessConditions: azblob.HTTPAccessConditions{IfNoneMatch: resp.ETag()}})
|
||||
|
||||
validateStorageError(c, err, azblob.ServiceCodeConditionNotMet)
|
||||
|
|
|
@ -18,7 +18,7 @@ func (b *AppendBlobURLSuite) TestAppendBlock(c *chk.C) {
|
|||
|
||||
blob := container.NewAppendBlobURL(generateBlobName())
|
||||
|
||||
resp, err := blob.Create(context.Background(), nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
resp, err := blob.Create(context.Background(), azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(resp.StatusCode(), chk.Equals, 201)
|
||||
|
||||
|
|
|
@ -292,7 +292,7 @@ func (b *BlobURLSuite) TestLeaseRenewChangeBreak(c *chk.C) {
|
|||
c.Assert(resp.RequestID(), chk.Not(chk.Equals), "")
|
||||
c.Assert(resp.Version(), chk.Not(chk.Equals), "")
|
||||
|
||||
resp, err = blob.BreakLease(context.Background(), newID, 5, azblob.HTTPAccessConditions{})
|
||||
resp, err = blob.BreakLease(context.Background(), 5, azblob.HTTPAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(resp.Response().StatusCode, chk.Equals, 202)
|
||||
c.Assert(resp.Date().IsZero(), chk.Equals, false)
|
||||
|
|
|
@ -43,7 +43,7 @@ func (b *BlockBlobURLSuite) TestPutGetBlocks(c *chk.C) {
|
|||
c.Assert(blockList.CommittedBlocks, chk.HasLen, 0)
|
||||
c.Assert(blockList.UncommittedBlocks, chk.HasLen, 1)
|
||||
|
||||
listResp, err := blob.PutBlockList(context.Background(), []string{blockID}, nil, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{})
|
||||
listResp, err := blob.PutBlockList(context.Background(), []string{blockID}, azblob.BlobHTTPHeaders{}, nil, azblob.BlobAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(listResp.Response().StatusCode, chk.Equals, 201)
|
||||
c.Assert(listResp.LastModified().IsZero(), chk.Equals, false)
|
||||
|
|
|
@ -248,7 +248,7 @@ func (s *ContainerURLSuite) TestLeaseRenewChangeBreak(c *chk.C) {
|
|||
c.Assert(resp.RequestID(), chk.Not(chk.Equals), "")
|
||||
c.Assert(resp.Version(), chk.Not(chk.Equals), "")
|
||||
|
||||
resp, err = container.BreakLease(context.Background(), newID, 5, azblob.HTTPAccessConditions{})
|
||||
resp, err = container.BreakLease(context.Background(), 5, azblob.HTTPAccessConditions{})
|
||||
c.Assert(err, chk.IsNil)
|
||||
c.Assert(resp.Response().StatusCode, chk.Equals, 202)
|
||||
c.Assert(resp.Date().IsZero(), chk.Equals, false)
|
||||
|
|
Загрузка…
Ссылка в новой задаче