Merge pull request #623 from ahmetalpbalkan/azure-vendor
storage/driver/azure: Update vendored Azure SDKmaster
						commit
						d796729b6b
					
				| 
						 | 
				
			
			@ -16,7 +16,7 @@ import (
 | 
			
		|||
	"github.com/docker/distribution/registry/storage/driver/base"
 | 
			
		||||
	"github.com/docker/distribution/registry/storage/driver/factory"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const driverName = "azure"
 | 
			
		||||
| 
						 | 
				
			
			@ -68,7 +68,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
 | 
			
		|||
 | 
			
		||||
	realm, ok := parameters[paramRealm]
 | 
			
		||||
	if !ok || fmt.Sprint(realm) == "" {
 | 
			
		||||
		realm = azure.DefaultBaseUrl
 | 
			
		||||
		realm = azure.DefaultBaseURL
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return New(fmt.Sprint(accountName), fmt.Sprint(accountKey), fmt.Sprint(container), fmt.Sprint(realm))
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
 | 
			
		|||
 | 
			
		||||
// New constructs a new Driver with the given Azure Storage Account credentials
 | 
			
		||||
func New(accountName, accountKey, container, realm string) (*Driver, error) {
 | 
			
		||||
	api, err := azure.NewClient(accountName, accountKey, realm, azure.DefaultApiVersion, true)
 | 
			
		||||
	api, err := azure.NewClient(accountName, accountKey, realm, azure.DefaultAPIVersion, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +89,7 @@ func New(accountName, accountKey, container, realm string) (*Driver, error) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	d := &driver{
 | 
			
		||||
		client:    *blobClient,
 | 
			
		||||
		client:    blobClient,
 | 
			
		||||
		container: container}
 | 
			
		||||
	return &Driver{baseEmbed: baseEmbed{Base: base.Base{StorageDriver: d}}}, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -114,7 +114,16 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
 | 
			
		|||
 | 
			
		||||
// PutContent stores the []byte content at a location designated by "path".
 | 
			
		||||
func (d *driver) PutContent(ctx context.Context, path string, contents []byte) error {
 | 
			
		||||
	return d.client.PutBlockBlob(d.container, path, ioutil.NopCloser(bytes.NewReader(contents)))
 | 
			
		||||
	if _, err := d.client.DeleteBlobIfExists(d.container, path); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if err := d.client.CreateBlockBlob(d.container, path); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	bs := newAzureBlockStorage(d.client)
 | 
			
		||||
	bw := newRandomBlobWriter(&bs, azure.MaxBlobBlockSize)
 | 
			
		||||
	_, err := bw.WriteBlobAt(d.container, path, 0, bytes.NewReader(contents))
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a
 | 
			
		||||
| 
						 | 
				
			
			@ -233,7 +242,7 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
 | 
			
		|||
// Move moves an object stored at sourcePath to destPath, removing the original
 | 
			
		||||
// object.
 | 
			
		||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
 | 
			
		||||
	sourceBlobURL := d.client.GetBlobUrl(d.container, sourcePath)
 | 
			
		||||
	sourceBlobURL := d.client.GetBlobURL(d.container, sourcePath)
 | 
			
		||||
	err := d.client.CopyBlob(d.container, destPath, sourceBlobURL)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if is404(err) {
 | 
			
		||||
| 
						 | 
				
			
			@ -352,6 +361,6 @@ func (d *driver) listBlobs(container, virtPath string) ([]string, error) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func is404(err error) bool {
 | 
			
		||||
	e, ok := err.(azure.StorageServiceError)
 | 
			
		||||
	e, ok := err.(azure.AzureStorageServiceError)
 | 
			
		||||
	return ok && e.StatusCode == http.StatusNotFound
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// azureBlockStorage is adaptor between azure.BlobStorageClient and
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ import (
 | 
			
		|||
	"io"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type StorageSimulator struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -122,12 +122,12 @@ func (s *StorageSimulator) PutBlockList(container, blob string, blocks []azure.B
 | 
			
		|||
 | 
			
		||||
	var blockIDs []string
 | 
			
		||||
	for _, v := range blocks {
 | 
			
		||||
		bl, ok := bb.blocks[v.Id]
 | 
			
		||||
		bl, ok := bb.blocks[v.ID]
 | 
			
		||||
		if !ok { // check if block ID exists
 | 
			
		||||
			return fmt.Errorf("Block id '%s' not found", v.Id)
 | 
			
		||||
			return fmt.Errorf("Block id '%s' not found", v.ID)
 | 
			
		||||
		}
 | 
			
		||||
		bl.committed = true
 | 
			
		||||
		blockIDs = append(blockIDs, v.Id)
 | 
			
		||||
		blockIDs = append(blockIDs, v.ID)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Mark all other blocks uncommitted
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ import (
 | 
			
		|||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type blockIDGenerator struct {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ import (
 | 
			
		|||
	"math"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Test_blockIdGenerator(t *testing.T) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ import (
 | 
			
		|||
	"io"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// blockStorage is the interface required from a block storage service
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +75,7 @@ func (r *randomBlobWriter) WriteBlobAt(container, blob string, offset int64, chu
 | 
			
		|||
		// Use existing block list
 | 
			
		||||
		var existingBlocks []azure.Block
 | 
			
		||||
		for _, v := range blocks.CommittedBlocks {
 | 
			
		||||
			existingBlocks = append(existingBlocks, azure.Block{Id: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
			existingBlocks = append(existingBlocks, azure.Block{ID: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
		}
 | 
			
		||||
		blockList = append(existingBlocks, blockList...)
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +111,7 @@ func (r *randomBlobWriter) writeChunkToBlocks(container, blob string, chunk io.R
 | 
			
		|||
		if err := r.bs.PutBlock(container, blob, blockID, data); err != nil {
 | 
			
		||||
			return newBlocks, nn, err
 | 
			
		||||
		}
 | 
			
		||||
		newBlocks = append(newBlocks, azure.Block{Id: blockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
		newBlocks = append(newBlocks, azure.Block{ID: blockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
	}
 | 
			
		||||
	return newBlocks, nn, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -131,7 +131,7 @@ func (r *randomBlobWriter) blocksLeftSide(container, blob string, writeOffset in
 | 
			
		|||
	for _, v := range bx.CommittedBlocks {
 | 
			
		||||
		blkSize := int64(v.Size)
 | 
			
		||||
		if o >= blkSize { // use existing block
 | 
			
		||||
			left = append(left, azure.Block{Id: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
			left = append(left, azure.Block{ID: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
			o -= blkSize
 | 
			
		||||
			elapsed += blkSize
 | 
			
		||||
		} else if o > 0 { // current block needs to be splitted
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +150,7 @@ func (r *randomBlobWriter) blocksLeftSide(container, blob string, writeOffset in
 | 
			
		|||
			if err = r.bs.PutBlock(container, blob, newBlockID, data); err != nil {
 | 
			
		||||
				return left, err
 | 
			
		||||
			}
 | 
			
		||||
			left = append(left, azure.Block{Id: newBlockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
			left = append(left, azure.Block{ID: newBlockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +177,7 @@ func (r *randomBlobWriter) blocksRightSide(container, blob string, writeOffset i
 | 
			
		|||
		)
 | 
			
		||||
 | 
			
		||||
		if bs > re { // take the block as is
 | 
			
		||||
			right = append(right, azure.Block{Id: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
			right = append(right, azure.Block{ID: v.Name, Status: azure.BlockStatusCommitted})
 | 
			
		||||
		} else if be > re { // current block needs to be splitted
 | 
			
		||||
			part, err := r.bs.GetSectionReader(container, blob, re+1, be-(re+1)+1)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -192,7 +192,7 @@ func (r *randomBlobWriter) blocksRightSide(container, blob string, writeOffset i
 | 
			
		|||
			if err = r.bs.PutBlock(container, blob, newBlockID, data); err != nil {
 | 
			
		||||
				return right, err
 | 
			
		||||
			}
 | 
			
		||||
			right = append(right, azure.Block{Id: newBlockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
			right = append(right, azure.Block{ID: newBlockID, Status: azure.BlockStatusUncommitted})
 | 
			
		||||
		}
 | 
			
		||||
		elapsed += int64(v.Size)
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ import (
 | 
			
		|||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	azure "github.com/MSOpenTech/azure-sdk-for-go/storage"
 | 
			
		||||
	azure "github.com/Azure/azure-sdk-for-go/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestRandomWriter_writeChunkToBlocks(t *testing.T) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue