Skip to content

Commit f3ef14e

Browse files
authored
Added support for get account info in blob and container clients (Azure#20542)
1 parent 4b47ee8 commit f3ef14e

File tree

18 files changed

+160
-2
lines changed

18 files changed

+160
-2
lines changed

sdk/storage/azblob/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Added [Blob Batch API](https://learn.microsoft.com/rest/api/storageservices/blob-batch).
88
* Added support for bearer challenge for identity based managed disks.
9+
* Added support for GetAccountInfo to container and blob level clients.
910

1011
### Breaking Changes
1112

sdk/storage/azblob/appendblob/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ func (ab *Client) GetProperties(ctx context.Context, o *blob.GetPropertiesOption
279279
return ab.BlobClient().GetProperties(ctx, o)
280280
}
281281

282+
// GetAccountInfo provides account level information
283+
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-account-information?tabs=shared-access-signatures.
284+
func (ab *Client) GetAccountInfo(ctx context.Context, o *blob.GetAccountInfoOptions) (blob.GetAccountInfoResponse, error) {
285+
return ab.BlobClient().GetAccountInfo(ctx, o)
286+
}
287+
282288
// SetHTTPHeaders changes a blob's HTTP headers.
283289
// For more information, see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties.
284290
func (ab *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders blob.HTTPHeaders, o *blob.SetHTTPHeadersOptions) (blob.SetHTTPHeadersResponse, error) {

sdk/storage/azblob/appendblob/client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,3 +2962,23 @@ func (s *AppendBlobUnrecordedTestsSuite) TestSetBlobTagsWithLeaseId() {
29622962
_require.Equal(testcommon.BasicBlobTagsMap[*blobTag.Key], *blobTag.Value)
29632963
}
29642964
}
2965+
2966+
func (s *AppendBlobRecordedTestsSuite) TestAppendGetAccountInfo() {
2967+
_require := require.New(s.T())
2968+
testName := s.T().Name()
2969+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
2970+
_require.NoError(err)
2971+
2972+
containerName := testcommon.GenerateContainerName(testName)
2973+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
2974+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
2975+
2976+
abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient)
2977+
_, err = abClient.Create(context.Background(), nil)
2978+
_require.Nil(err)
2979+
2980+
// Ensure the call succeeded. Don't test for specific account properties because we can't/don't want to set account properties.
2981+
bAccInfo, err := abClient.GetAccountInfo(context.Background(), nil)
2982+
_require.Nil(err)
2983+
_require.NotZero(bAccInfo)
2984+
}

sdk/storage/azblob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "go",
44
"TagPrefix": "go/storage/azblob",
5-
"Tag": "go/storage/azblob_cbcc92f524"
5+
"Tag": "go/storage/azblob_5d20008f59"
66
}

sdk/storage/azblob/blob/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ func (b *Client) CopyFromURL(ctx context.Context, copySource string, options *Co
268268
return resp, err
269269
}
270270

271+
// GetAccountInfo provides account level information
272+
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-account-information?tabs=shared-access-signatures.
273+
func (b *Client) GetAccountInfo(ctx context.Context, o *GetAccountInfoOptions) (GetAccountInfoResponse, error) {
274+
getAccountInfoOptions := o.format()
275+
resp, err := b.generated().GetAccountInfo(ctx, getAccountInfoOptions)
276+
return resp, err
277+
}
278+
271279
// GetSASURL is a convenience method for generating a SAS token for the currently pointed at blob.
272280
// It can only be used if the credential supplied during creation was a SharedKeyCredential.
273281
func (b *Client) GetSASURL(permissions sas.BlobPermissions, expiry time.Time, o *GetSASURLOptions) (string, error) {

sdk/storage/azblob/blob/client_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,3 +3609,22 @@ func (s *BlobUnrecordedTestsSuite) TestNoSharedKeyCredError() {
36093609
_, err = bbClient.BlobClient().GetSASURL(permissions, expiry, &opts)
36103610
_require.Equal(err, bloberror.MissingSharedKeyCredential)
36113611
}
3612+
3613+
func (s *BlobRecordedTestsSuite) TestBlobGetAccountInfo() {
3614+
_require := require.New(s.T())
3615+
testName := s.T().Name()
3616+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
3617+
_require.NoError(err)
3618+
3619+
containerName := testcommon.GenerateContainerName(testName)
3620+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3621+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
3622+
3623+
blockBlobName := testcommon.GenerateBlobName(testName)
3624+
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
3625+
3626+
// Ensure the call succeeded. Don't test for specific account properties because we can't/don't want to set account properties.
3627+
bAccInfo, err := bbClient.GetAccountInfo(context.Background(), nil)
3628+
_require.Nil(err)
3629+
_require.NotZero(bAccInfo)
3630+
}

sdk/storage/azblob/blob/models.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,14 @@ func (o *CopyFromURLOptions) format() (*generated.BlobClientCopyFromURLOptions,
565565
leaseAccessConditions, modifiedAccessConditions := exported.FormatBlobAccessConditions(o.BlobAccessConditions)
566566
return options, o.SourceModifiedAccessConditions, modifiedAccessConditions, leaseAccessConditions
567567
}
568+
569+
// ---------------------------------------------------------------------------------------------------------------------
570+
571+
// GetAccountInfoOptions provides set of options for Client.GetAccountInfo
572+
type GetAccountInfoOptions struct {
573+
// placeholder for future options
574+
}
575+
576+
func (o *GetAccountInfoOptions) format() *generated.BlobClientGetAccountInfoOptions {
577+
return nil
578+
}

sdk/storage/azblob/blob/responses.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ type SetLegalHoldResponse = generated.BlobClientSetLegalHoldResponse
100100
// CopyFromURLResponse contains the response from method BlobClient.CopyFromURL.
101101
type CopyFromURLResponse = generated.BlobClientCopyFromURLResponse
102102

103+
// GetAccountInfoResponse contains the response from method BlobClient.GetAccountInfo.
104+
type GetAccountInfoResponse = generated.BlobClientGetAccountInfoResponse
105+
103106
// AcquireLeaseResponse contains the response from method BlobClient.AcquireLease.
104107
type AcquireLeaseResponse = generated.BlobClientAcquireLeaseResponse
105108

sdk/storage/azblob/blockblob/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ func (bb *Client) GetProperties(ctx context.Context, o *blob.GetPropertiesOption
316316
return bb.BlobClient().GetProperties(ctx, o)
317317
}
318318

319+
// GetAccountInfo provides account level information
320+
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-account-information?tabs=shared-access-signatures.
321+
func (bb *Client) GetAccountInfo(ctx context.Context, o *blob.GetAccountInfoOptions) (blob.GetAccountInfoResponse, error) {
322+
return bb.BlobClient().GetAccountInfo(ctx, o)
323+
}
324+
319325
// SetHTTPHeaders changes a blob's HTTP headers.
320326
// For more information, see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties.
321327
func (bb *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders blob.HTTPHeaders, o *blob.SetHTTPHeadersOptions) (blob.SetHTTPHeadersResponse, error) {

sdk/storage/azblob/blockblob/client_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,25 @@ func (s *BlockBlobUnrecordedTestsSuite) TestLargeBlockBufferedUploadInParallel()
39003900
_require.Equal(*(committed[1].Size), largeBlockSize)
39013901
}
39023902

3903+
func (s *BlockBlobRecordedTestsSuite) TestBlockGetAccountInfo() {
3904+
_require := require.New(s.T())
3905+
testName := s.T().Name()
3906+
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
3907+
_require.NoError(err)
3908+
3909+
containerName := testcommon.GenerateContainerName(testName)
3910+
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3911+
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)
3912+
3913+
blockBlobName := testcommon.GenerateBlobName(testName)
3914+
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
3915+
3916+
// Ensure the call succeeded. Don't test for specific account properties because we can't/don't want to set account properties.
3917+
bAccInfo, err := bbClient.GetAccountInfo(context.Background(), nil)
3918+
_require.Nil(err)
3919+
_require.NotZero(bAccInfo)
3920+
}
3921+
39033922
type fakeBlockBlob struct {
39043923
totalStaged int64
39053924
}

0 commit comments

Comments
 (0)