Skip to content

Commit

Permalink
Merge pull request Azure#1 from mohsha-msft/track2-mohit/test-migrati…
Browse files Browse the repository at this point in the history
…on-2

Track2 mohit/test migration 2
  • Loading branch information
adreed-msft authored Jan 19, 2021
2 parents 0980f1e + b1d5978 commit 302f563
Show file tree
Hide file tree
Showing 30 changed files with 9,164 additions and 300 deletions.
1 change: 1 addition & 0 deletions sdk/storage/azblob/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.13.4
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.6.0
github.com/Azure/azure-sdk-for-go/sdk/to v0.1.2
github.com/google/uuid v1.1.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
)
2 changes: 2 additions & 0 deletions sdk/storage/azblob/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.0 h1:HG1ggl8L3ZkV/Ydanf7lKr5
github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.0/go.mod h1:k4KbFSunV/+0hOHL1vyFaPsiYQ1Vmvy1TBpmtvCDLZM=
github.com/Azure/azure-sdk-for-go/sdk/to v0.1.2 h1:TZTVOb/ce7nCmOZYga9+ELtPPVVFG2Px4s/w5OycYS0=
github.com/Azure/azure-sdk-for-go/sdk/to v0.1.2/go.mod h1:UL/d4lvWAzSJUuX+19uKdN0ktyjoOyQhgY+HWNgtIYI=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
5 changes: 5 additions & 0 deletions sdk/storage/azblob/shared_policy_shared_key_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type SharedKeyCredential struct {
accountKey atomic.Value // []byte
}

// noop function to satisfy StorageAccountCredential interface
func (c *SharedKeyCredential) GetUDKParams() *UserDelegationKey {
return nil
}

// AccountName returns the Storage account's name.
func (c *SharedKeyCredential) AccountName() string {
return c.accountName
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azblob/zc_access_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
// ContainerAccessConditions identifies container-specific access conditions which you optionally set.
type ContainerAccessConditions struct {
ModifiedAccessConditions *ModifiedAccessConditions
LeaseAccessConditions *LeaseAccessConditions
LeaseAccessConditions *LeaseAccessConditions
}

func (ac *ContainerAccessConditions) pointers() (*ModifiedAccessConditions, *LeaseAccessConditions) {
Expand All @@ -25,7 +25,7 @@ func (ac *ContainerAccessConditions) pointers() (*ModifiedAccessConditions, *Lea
// BlobAccessConditions identifies blob-specific access conditions which you optionally set.
type BlobAccessConditions struct {
ModifiedAccessConditions *ModifiedAccessConditions
LeaseAccessConditions *LeaseAccessConditions
LeaseAccessConditions *LeaseAccessConditions
}

func (ac *BlobAccessConditions) pointers() (*ModifiedAccessConditions, *LeaseAccessConditions) {
Expand All @@ -34,4 +34,4 @@ func (ac *BlobAccessConditions) pointers() (*ModifiedAccessConditions, *LeaseAcc
}

return ac.ModifiedAccessConditions, ac.LeaseAccessConditions
}
}
61 changes: 61 additions & 0 deletions sdk/storage/azblob/zc_access_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package azblob

import (
"bytes"
"fmt"
)

// The AccessPolicyPermission type simplifies creating the permissions string for a container's access policy.
// Initialize an instance of this type and then call its String method to set AccessPolicy's Permission field.
type AccessPolicyPermission struct {
Read, Add, Create, Write, Delete, List bool
}

// String produces the access policy permission string for an Azure Storage container.
// Call this method to set AccessPolicy's Permission field.
func (p AccessPolicyPermission) String() string {
var b bytes.Buffer
if p.Read {
b.WriteRune('r')
}
if p.Add {
b.WriteRune('a')
}
if p.Create {
b.WriteRune('c')
}
if p.Write {
b.WriteRune('w')
}
if p.Delete {
b.WriteRune('d')
}
if p.List {
b.WriteRune('l')
}
return b.String()
}

// Parse initializes the AccessPolicyPermission's fields from a string.
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
}
63 changes: 47 additions & 16 deletions sdk/storage/azblob/zc_appendBlobClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,65 @@ func NewAppendBlobClient(blobURL string, cred azcore.Credential, options *connec
return AppendBlobClient{}, err
}
con := newConnection(blobURL, cred, options)
return AppendBlobClient{client: &appendBlobClient{con: con}, u: *u}, nil
}

func (ab AppendBlobClient) WithPipeline(pipeline azcore.Pipeline) AppendBlobClient {
con := newConnectionWithPipeline(ab.u.String(), pipeline)
return AppendBlobClient{client: &appendBlobClient{con}, u: ab.u}
}

func (ab AppendBlobClient) GetAccountInfo(ctx context.Context) (BlobGetAccountInfoResponse, error) {
blobClient := BlobClient{client: &blobClient{ab.client.con, nil}}

return blobClient.GetAccountInfo(ctx)
return AppendBlobClient{
client: &appendBlobClient{con: con},
u: *u,
BlobClient: BlobClient{client: &blobClient{con: con}},
}, nil
}

func (ab AppendBlobClient) URL() url.URL {
return ab.u
}

func (ab AppendBlobClient) WithPipeline(pipeline azcore.Pipeline) AppendBlobClient {
con := newConnectionWithPipeline(ab.u.String(), pipeline)
return AppendBlobClient{
client: &appendBlobClient{con},
u: ab.u,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

// WithSnapshot creates a new AppendBlobURL object identical to the source but with the specified snapshot timestamp.
// Pass "" to remove the snapshot returning a URL to the base blob.
func (ab AppendBlobClient) WithSnapshot(snapshot string) AppendBlobClient {
p := NewBlobURLParts(ab.URL())
p.Snapshot = snapshot
snapshotURL := p.URL()
con := newConnectionWithPipeline(snapshotURL.String(), ab.client.con.p)
return AppendBlobClient{
client: &appendBlobClient{con: con},
u: snapshotURL,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

// WithVersionID creates a new AppendBlobURL object identical to the source but with the specified version id.
// Pass "" to remove the versionID returning a URL to the base blob.
func (ab AppendBlobClient) WithVersionID(versionID string) AppendBlobClient {
p := NewBlobURLParts(ab.URL())
p.VersionID = versionID
versionIDURL := p.URL()
con := newConnectionWithPipeline(versionIDURL.String(), ab.client.con.p)
return AppendBlobClient{
client: &appendBlobClient{
newConnectionWithPipeline(snapshotURL.String(), ab.client.con.p),
},
u: ab.u,
client: &appendBlobClient{con: con},
u: versionIDURL,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

// Create creates a 0-size 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 AppendBlobClient) Create(ctx context.Context, options *CreateAppendBlobOptions) (AppendBlobCreateResponse, error) {
appendBlobAppendBlockOptions, blobHttpHeaders, leaseAccessConditions, cpkInfo, cpkScopeInfo, modifiedAccessConditions := options.pointers()
return ab.client.Create(ctx, 0, appendBlobAppendBlockOptions, blobHttpHeaders, leaseAccessConditions, cpkInfo, cpkScopeInfo, modifiedAccessConditions)
}

// AppendBlock writes a stream to a new block of data to the end of the existing append blob.
// This method panics if the stream is not at position 0.
// 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 AppendBlobClient) AppendBlock(ctx context.Context, body io.ReadSeeker, options *AppendBlockOptions) (AppendBlobAppendBlockResponse, error) {
count, err := validateSeekableStreamAt0AndGetCount(body)
if err != nil {
Expand All @@ -66,6 +95,8 @@ func (ab AppendBlobClient) AppendBlock(ctx context.Context, body io.ReadSeeker,
return ab.client.AppendBlock(ctx, count, azcore.NopCloser(body), appendOptions, lac, aac, cpkinfo, cpkscope, mac)
}

// AppendBlockFromURL copies a new block of data from source URL to the end of the existing append blob.
// For more information, see https://docs.microsoft.com/rest/api/storageservices/append-block-from-url.
func (ab AppendBlobClient) AppendBlockFromURL(ctx context.Context, source url.URL, contentLength int64, options *AppendBlockURLOptions) (AppendBlobAppendBlockFromURLResponse, error) {
appendOptions, aac, cpkinfo, cpkscope, mac, lac, smac := options.pointers()

Expand Down
60 changes: 50 additions & 10 deletions sdk/storage/azblob/zc_appendBlobRequestOptions.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
package azblob

type CreateAppendBlobOptions struct {
BlobAccessConditions

BlobHttpHeaders *BlobHttpHeaders

CpkInfo *CpkInfo

CpkScopeInfo *CpkScopeInfo
// Optional. Used to set blob tags in various blob operations.
BlobTagsMap *map[string]string
// 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.
Metadata *map[string]string
// 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.
RequestId *string

Timeout *int32
}

func (o *CreateAppendBlobOptions) pointers() (*AppendBlobCreateOptions, *BlobHttpHeaders, *LeaseAccessConditions, *CpkInfo, *CpkScopeInfo, *ModifiedAccessConditions) {
if o == nil {
return nil, nil, nil, nil, nil, nil
}

options := AppendBlobCreateOptions{
BlobTagsString: SerializeBlobTagsToStrPtr(o.BlobTagsMap),
Metadata: o.Metadata,
RequestId: o.RequestId,
Timeout: o.Timeout,
}
return &options, o.BlobHttpHeaders, o.LeaseAccessConditions, o.CpkInfo, o.CpkScopeInfo, o.ModifiedAccessConditions
}

type AppendBlockOptions struct {
// Specify the transactional crc64 for the body, to be validated by the service.
TransactionalContentCrc64 *[]byte
// Specify the transactional md5 for the body, to be validated by the service.
TransactionalContentMd5 *[]byte

AppendPositionAccessConditions *AppendPositionAccessConditions
CpkInfo *CpkInfo
CpkScopeInfo *CpkScopeInfo
CpkInfo *CpkInfo
CpkScopeInfo *CpkScopeInfo
BlobAccessConditions
}

func (o *AppendBlockOptions) pointers() (*AppendBlobAppendBlockOptions, *AppendPositionAccessConditions, *CpkInfo, *CpkScopeInfo, *ModifiedAccessConditions, *LeaseAccessConditions){
func (o *AppendBlockOptions) pointers() (*AppendBlobAppendBlockOptions, *AppendPositionAccessConditions, *CpkInfo, *CpkScopeInfo, *ModifiedAccessConditions, *LeaseAccessConditions) {
if o == nil {
return nil, nil, nil, nil, nil, nil
}
Expand All @@ -34,22 +70,26 @@ type AppendBlockURLOptions struct {
TransactionalContentMd5 *[]byte

AppendPositionAccessConditions *AppendPositionAccessConditions
CpkInfo *CpkInfo
CpkScopeInfo *CpkScopeInfo
CpkInfo *CpkInfo
CpkScopeInfo *CpkScopeInfo
SourceModifiedAccessConditions *SourceModifiedAccessConditions
BlobAccessConditions
// Optional, you can specify whether a particular range of the blob is read
Offset *int64
Count *int64
}

func (o *AppendBlockURLOptions) pointers() (*AppendBlobAppendBlockFromURLOptions, *AppendPositionAccessConditions, *CpkInfo, *CpkScopeInfo, *ModifiedAccessConditions, *LeaseAccessConditions, *SourceModifiedAccessConditions){
func (o *AppendBlockURLOptions) pointers() (*AppendBlobAppendBlockFromURLOptions, *AppendPositionAccessConditions, *CpkInfo, *CpkScopeInfo, *ModifiedAccessConditions, *LeaseAccessConditions, *SourceModifiedAccessConditions) {
if o == nil {
return nil, nil, nil, nil, nil, nil, nil
}

options := &AppendBlobAppendBlockFromURLOptions{
SourceContentMd5: o.SourceContentMd5,
SourceContentcrc64: o.SourceContentCrc64,
TransactionalContentMd5: o.TransactionalContentMd5,
SourceRange: getSourceRange(o.Offset, o.Count),
SourceContentMd5: o.SourceContentMd5,
SourceContentcrc64: o.SourceContentCrc64,
TransactionalContentMd5: o.TransactionalContentMd5,
}

return options, o.AppendPositionAccessConditions, o.CpkInfo, o.CpkScopeInfo, o.ModifiedAccessConditions, o.LeaseAccessConditions, o.SourceModifiedAccessConditions
}
}
37 changes: 27 additions & 10 deletions sdk/storage/azblob/zc_blobClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package azblob

import (
"context"
"net/url"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"net/url"
)

// A BlobClient represents a URL to an Azure Storage blob; the blob may be a block blob, append blob, or page blob.
Expand Down Expand Up @@ -59,26 +58,29 @@ func (b BlobClient) WithSnapshot(snapshot string) BlobClient {
func (b BlobClient) ToAppendBlobURL() AppendBlobClient {
con := newConnectionWithPipeline(b.String(), b.client.con.p)
return AppendBlobClient{
client: &appendBlobClient{con},
u: b.u,
client: &appendBlobClient{con},
u: b.u,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

// ToBlockBlobURL creates a BlockBlobClient using the source's URL and pipeline.
func (b BlobClient) ToBlockBlobClient() BlockBlobClient {
con := newConnectionWithPipeline(b.String(), b.client.con.p)
return BlockBlobClient{
client: &blockBlobClient{con},
u: b.u,
client: &blockBlobClient{con},
u: b.u,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

// ToPageBlobURL creates a PageBlobURL using the source's URL and pipeline.
func (b BlobClient) ToPageBlobURL() PageBlobClient {
con := newConnectionWithPipeline(b.String(), b.client.con.p)
return PageBlobClient{
client: &pageBlobClient{con},
u: b.u,
client: &pageBlobClient{con},
u: b.u,
BlobClient: BlobClient{client: &blobClient{con: con}},
}
}

Expand All @@ -96,7 +98,7 @@ func (b BlobClient) Download(ctx context.Context, options *DownloadBlobOptions)
}

offset := int64(0)
count := int64(0)
count := int64(CountToEnd)

if options != nil && options.Offset != nil {
offset = *options.Offset
Expand Down Expand Up @@ -213,7 +215,6 @@ func (b BlobClient) ChangeLease(ctx context.Context, leaseID string, proposedID
// For more information, see https://docs.microsoft.com/rest/api/storageservices/copy-blob.
func (b BlobClient) StartCopyFromURL(ctx context.Context, copySource url.URL, options *StartCopyBlobOptions) (BlobStartCopyFromURLResponse, error) {
basics, srcAccess, destAccess, lease := options.pointers()

return b.client.StartCopyFromURL(ctx, copySource, basics, srcAccess, destAccess, lease)
}

Expand All @@ -223,3 +224,19 @@ func (b BlobClient) AbortCopyFromURL(ctx context.Context, copyID string, options
basics, lease := options.pointers()
return b.client.AbortCopyFromURL(ctx, copyID, basics, lease)
}

// SetTags operation enables users to set tags on a blob or specific blob version, but not snapshot.
// Each call to this operation replaces all existing tags attached to the blob.
// To remove all tags from the blob, call this operation with no tags set.
// https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tags
func (b BlobClient) SetTags(ctx context.Context, options *SetTagsBlobOptions) (BlobSetTagsResponse, error) {
blobSetTagsOptions, modifiedAccessConditions := options.pointers()
return b.client.SetTags(ctx, blobSetTagsOptions, modifiedAccessConditions)
}

// GetTags operation enables users to get tags on a blob or specific blob version, or snapshot.
// https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-tags
func (b BlobClient) GetTags(ctx context.Context, options *GetTagsBlobOptions) (BlobTagsResponse, error) {
blobGetTagsOptions, modifiedAccessConditions := options.pointers()
return b.client.GetTags(ctx, blobGetTagsOptions, modifiedAccessConditions)
}
Loading

0 comments on commit 302f563

Please sign in to comment.