Skip to content

Commit 07d8804

Browse files
[Blob] Fix API signatures and tests (Azure#19836)
* added tests and fixed apis * fix tests * test fix * fix * sas changes * test failure * more api changes * fix ci * page blob ranges * content length to 0 * fix range issue * format * ci fix
1 parent fe24c19 commit 07d8804

33 files changed

+947
-408
lines changed

sdk/storage/azblob/appendblob/client_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"context"
1212
"crypto/md5"
1313
"encoding/binary"
14-
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/service"
1514
"hash/crc64"
1615
"io"
1716
"math/rand"
@@ -86,7 +85,7 @@ func createNewAppendBlob(ctx context.Context, _require *require.Assertions, appe
8685
return abClient
8786
}
8887

89-
func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlock() {
88+
func (s *AppendBlobRecordedTestsSuite) TestAppendBlock() {
9089
_require := require.New(s.T())
9190
testName := s.T().Name()
9291
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
@@ -1561,9 +1560,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestCreateAppendBlobWithTags() {
15611560

15621561
// Tags with spaces
15631562
where := "\"GO \"='.Net'"
1564-
lResp, err := svcClient.FilterBlobs(context.Background(), &service.FilterBlobsOptions{
1565-
Where: &where,
1566-
})
1563+
lResp, err := svcClient.FilterBlobs(context.Background(), where, nil)
15671564
_require.Nil(err)
15681565
_require.Len(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet, 1)
15691566
_require.Equal(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0], blobTagsSet[2])

sdk/storage/azblob/blob/client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (b *Client) CopyFromURL(ctx context.Context, copySource string, options *Co
266266

267267
// GetSASURL is a convenience method for generating a SAS token for the currently pointed at blob.
268268
// It can only be used if the credential supplied during creation was a SharedKeyCredential.
269-
func (b *Client) GetSASURL(permissions sas.BlobPermissions, start time.Time, expiry time.Time) (string, error) {
269+
func (b *Client) GetSASURL(permissions sas.BlobPermissions, expiry time.Time, o *GetSASURLOptions) (string, error) {
270270
if b.sharedKey() == nil {
271271
return "", errors.New("credential is not a SharedKeyCredential. SAS can only be signed with a SharedKeyCredential")
272272
}
@@ -281,17 +281,16 @@ func (b *Client) GetSASURL(permissions sas.BlobPermissions, start time.Time, exp
281281
if err != nil {
282282
t = time.Time{}
283283
}
284+
st := o.format()
284285

285286
qps, err := sas.BlobSignatureValues{
286287
ContainerName: urlParts.ContainerName,
287288
BlobName: urlParts.BlobName,
288289
SnapshotTime: t,
289290
Version: sas.Version,
290-
291-
Permissions: permissions.String(),
292-
293-
StartTime: start.UTC(),
294-
ExpiryTime: expiry.UTC(),
291+
Permissions: permissions.String(),
292+
StartTime: st,
293+
ExpiryTime: expiry.UTC(),
295294
}.SignWithSharedKey(b.sharedKey())
296295

297296
if err != nil {

sdk/storage/azblob/blob/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopySourcePrivate() {
382382
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
383383
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
384384

385-
_, err = containerClient.SetAccessPolicy(context.Background(), nil, nil)
385+
_, err = containerClient.SetAccessPolicy(context.Background(), nil)
386386
_require.Nil(err)
387387

388388
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, testcommon.GenerateBlobName(testName), containerClient)
@@ -488,7 +488,7 @@ func (s *BlobUnrecordedTestsSuite) TestBlobStartCopyUsingSASDest() {
488488
_require.Nil(err)
489489

490490
containerClient := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName)+strconv.Itoa(i), svcClient)
491-
_, err := containerClient.SetAccessPolicy(context.Background(), nil, nil)
491+
_, err := containerClient.SetAccessPolicy(context.Background(), nil)
492492
_require.Nil(err)
493493

494494
blobClient := testcommon.CreateNewBlockBlob(context.Background(), _require, testcommon.GenerateBlobName(testName), containerClient)
@@ -1023,7 +1023,7 @@ func (s *BlobUnrecordedTestsSuite) TestBlobAbortCopyInProgress() {
10231023
setAccessPolicyOptions := container.SetAccessPolicyOptions{
10241024
Access: to.Ptr(container.PublicAccessTypeBlob),
10251025
}
1026-
_, err = containerClient.SetAccessPolicy(context.Background(), nil, &setAccessPolicyOptions) // So that we don't have to create a SAS
1026+
_, err = containerClient.SetAccessPolicy(context.Background(), &setAccessPolicyOptions) // So that we don't have to create a SAS
10271027
_require.Nil(err)
10281028

10291029
// Must copy across accounts so it takes time to copy

sdk/storage/azblob/blob/models.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,23 @@ func (o *SetLegalHoldOptions) format() *generated.BlobClientSetLegalHoldOptions
496496

497497
// ---------------------------------------------------------------------------------------------------------------------
498498

499+
// GetSASURLOptions contains the optional parameters for the Client.GetSASURL method.
500+
type GetSASURLOptions struct {
501+
StartTime *time.Time
502+
}
503+
504+
func (o *GetSASURLOptions) format() time.Time {
505+
var st time.Time
506+
if o.StartTime != nil {
507+
st = o.StartTime.UTC()
508+
} else {
509+
st = time.Time{}
510+
}
511+
return st
512+
}
513+
514+
// ---------------------------------------------------------------------------------------------------------------------
515+
499516
// CopyFromURLOptions contains the optional parameters for the Client.CopyFromURL method.
500517
type CopyFromURLOptions struct {
501518
// Optional. Used to set blob tags in various blob operations.

sdk/storage/azblob/blockblob/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,11 @@ func (bb *Client) StageBlock(ctx context.Context, base64BlockID string, body io.
190190
// StageBlockFromURL copies the specified block from a source URL to the block blob's "staging area" to be later committed by a call to CommitBlockList.
191191
// If count is CountToEnd (0), then data is read from specified offset to the end.
192192
// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url.
193-
func (bb *Client) StageBlockFromURL(ctx context.Context, base64BlockID string, sourceURL string,
194-
contentLength int64, options *StageBlockFromURLOptions) (StageBlockFromURLResponse, error) {
193+
func (bb *Client) StageBlockFromURL(ctx context.Context, base64BlockID string, sourceURL string, options *StageBlockFromURLOptions) (StageBlockFromURLResponse, error) {
195194

196195
stageBlockFromURLOptions, cpkInfo, cpkScopeInfo, leaseAccessConditions, sourceModifiedAccessConditions := options.format()
197196

198-
resp, err := bb.generated().StageBlockFromURL(ctx, base64BlockID, contentLength, sourceURL, stageBlockFromURLOptions,
197+
resp, err := bb.generated().StageBlockFromURL(ctx, base64BlockID, 0, sourceURL, stageBlockFromURLOptions,
199198
cpkInfo, cpkScopeInfo, leaseAccessConditions, sourceModifiedAccessConditions)
200199

201200
return resp, err

sdk/storage/azblob/blockblob/client_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestCreateBlockBlobReturnsVID() {
21172117
_require.NotEqual(len(found), 0)
21182118
}
21192119

2120-
func (s *BlockBlobUnrecordedTestsSuite) TestORSSource() {
2120+
func (s *BlockBlobRecordedTestsSuite) TestORSSource() {
21212121
_require := require.New(s.T())
21222122
testName := s.T().Name()
21232123
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
@@ -2311,7 +2311,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestSetBlobTagsWithLeaseId() {
23112311
})
23122312
_require.NoError(err)
23132313
ctx := context.Background()
2314-
acquireLeaseResponse, err := blobLeaseClient.AcquireLease(ctx, &lease.BlobAcquireOptions{Duration: to.Ptr[int32](60)})
2314+
acquireLeaseResponse, err := blobLeaseClient.AcquireLease(ctx, int32(60), nil)
23152315
_require.Nil(err)
23162316
_require.NotNil(acquireLeaseResponse.LeaseID)
23172317
_require.EqualValues(acquireLeaseResponse.LeaseID, blobLeaseClient.LeaseID())
@@ -2828,22 +2828,22 @@ func (s *BlockBlobUnrecordedTestsSuite) TestFilterBlobsWithTags() {
28282828

28292829
// Test invalid tag
28302830
where := "\"tag4\"='fourthtag'"
2831-
lResp, err := svcClient.FilterBlobs(context.Background(), &service.FilterBlobsOptions{Where: &where})
2831+
lResp, err := svcClient.FilterBlobs(context.Background(), where, nil)
28322832
_require.Nil(err)
28332833
_require.Equal(len(lResp.Blobs), 0)
28342834

28352835
// Test multiple valid tags
28362836
where = "\"tag1\"='firsttag'AND\"tag2\"='secondtag'"
28372837
// where := "foo=\"value 1\""
2838-
lResp, err = svcClient.FilterBlobs(context.Background(), &service.FilterBlobsOptions{Where: &where})
2838+
lResp, err = svcClient.FilterBlobs(context.Background(), where, nil)
28392839
_require.Nil(err)
28402840
_require.Len(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet, 2)
28412841
_require.Equal(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0], blobTagsSet[1])
28422842
_require.Equal(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[1], blobTagsSet[2])
28432843

28442844
// Test tags with spaces
28452845
where = "\"tag key\"='tag value'"
2846-
lResp, err = svcClient.FilterBlobs(context.Background(), &service.FilterBlobsOptions{Where: &where})
2846+
lResp, err = svcClient.FilterBlobs(context.Background(), where, nil)
28472847
_require.Nil(err)
28482848
_require.Len(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet, 1)
28492849
_require.Equal(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0], blobTagsSet[0])
@@ -3243,7 +3243,7 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlockAndPutBlockListWithCPKByScope(
32433243
// _require.EqualValues(*downloadResp.EncryptionScope, *testcommon.TestCPKByScope.EncryptionScope)
32443244
// }
32453245

3246-
func (s *BlockBlobUnrecordedTestsSuite) TestUploadBlobWithMD5WithCPK() {
3246+
func (s *BlockBlobRecordedTestsSuite) TestUploadBlobWithMD5WithCPK() {
32473247
_require := require.New(s.T())
32483248
testName := s.T().Name()
32493249
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)

sdk/storage/azblob/container/client.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,12 @@ func (c *Client) GetAccessPolicy(ctx context.Context, o *GetAccessPolicyOptions)
217217

218218
// SetAccessPolicy sets the container's permissions. The access policy indicates whether blobs in a container may be accessed publicly.
219219
// For more information, see https://docs.microsoft.com/rest/api/storageservices/set-container-acl.
220-
func (c *Client) SetAccessPolicy(ctx context.Context, containerACL []*SignedIdentifier, o *SetAccessPolicyOptions) (SetAccessPolicyResponse, error) {
221-
accessPolicy, mac, lac := o.format()
222-
for _, c := range containerACL {
223-
err := formatTime(c)
224-
if err != nil {
225-
return SetAccessPolicyResponse{}, err
226-
}
220+
func (c *Client) SetAccessPolicy(ctx context.Context, o *SetAccessPolicyOptions) (SetAccessPolicyResponse, error) {
221+
accessPolicy, mac, lac, acl, err := o.format()
222+
if err != nil {
223+
return SetAccessPolicyResponse{}, err
227224
}
228-
resp, err := c.generated().SetAccessPolicy(ctx, containerACL, accessPolicy, mac, lac)
225+
resp, err := c.generated().SetAccessPolicy(ctx, acl, accessPolicy, mac, lac)
229226
return resp, err
230227
}
231228

@@ -309,23 +306,22 @@ func (c *Client) NewListBlobsHierarchyPager(delimiter string, o *ListBlobsHierar
309306

310307
// GetSASURL is a convenience method for generating a SAS token for the currently pointed at container.
311308
// It can only be used if the credential supplied during creation was a SharedKeyCredential.
312-
func (c *Client) GetSASURL(permissions sas.ContainerPermissions, start time.Time, expiry time.Time) (string, error) {
309+
func (c *Client) GetSASURL(permissions sas.ContainerPermissions, expiry time.Time, o *GetSASURLOptions) (string, error) {
313310
if c.sharedKey() == nil {
314311
return "", errors.New("SAS can only be signed with a SharedKeyCredential")
315312
}
316-
313+
st := o.format()
317314
urlParts, err := blob.ParseURL(c.URL())
318315
if err != nil {
319316
return "", err
320317
}
321-
322318
// Containers do not have snapshots, nor versions.
323319
qps, err := sas.BlobSignatureValues{
324320
Version: sas.Version,
325321
Protocol: sas.ProtocolHTTPS,
326322
ContainerName: urlParts.ContainerName,
327323
Permissions: permissions.String(),
328-
StartTime: start.UTC(),
324+
StartTime: st,
329325
ExpiryTime: expiry.UTC(),
330326
}.SignWithSharedKey(c.sharedKey())
331327
if err != nil {

0 commit comments

Comments
 (0)