From 01aa3850da3f0db33d659e5095566ac3365b24e3 Mon Sep 17 00:00:00 2001 From: Sourav Gupta <98318303+souravgupta-msft@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:35:19 +0530 Subject: [PATCH 1/4] Updating to STG91(2023-11-03) (#22137) --- .../azblob/internal/generated/autorest.md | 4 +- .../azblob/internal/generated/constants.go | 2 +- .../generated/zz_appendblob_client.go | 8 ++-- .../internal/generated/zz_blob_client.go | 48 +++++++++---------- .../internal/generated/zz_blockblob_client.go | 12 ++--- .../internal/generated/zz_container_client.go | 36 +++++++------- .../internal/generated/zz_pageblob_client.go | 18 +++---- .../internal/generated/zz_service_client.go | 16 +++---- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/sdk/storage/azblob/internal/generated/autorest.md b/sdk/storage/azblob/internal/generated/autorest.md index 25deeec35872..92dc7e2d31e5 100644 --- a/sdk/storage/azblob/internal/generated/autorest.md +++ b/sdk/storage/azblob/internal/generated/autorest.md @@ -22,7 +22,7 @@ export-clients: true use: "@autorest/go@4.0.0-preview.61" ``` -### Updating service version to 2023-08-03 +### Updating service version to 2023-11-03 ```yaml directive: - from: @@ -36,7 +36,7 @@ directive: transform: >- return $. replaceAll(`[]string{"2021-12-02"}`, `[]string{ServiceVersion}`). - replaceAll(`2021-12-02`, `2023-08-03`); + replaceAll(`2021-12-02`, `2023-11-03`); ``` ### Undo breaking change with BlobName diff --git a/sdk/storage/azblob/internal/generated/constants.go b/sdk/storage/azblob/internal/generated/constants.go index 8c13c44116b6..8f2bbbb7cb81 100644 --- a/sdk/storage/azblob/internal/generated/constants.go +++ b/sdk/storage/azblob/internal/generated/constants.go @@ -6,4 +6,4 @@ package generated -const ServiceVersion = "2023-08-03" +const ServiceVersion = "2023-11-03" diff --git a/sdk/storage/azblob/internal/generated/zz_appendblob_client.go b/sdk/storage/azblob/internal/generated/zz_appendblob_client.go index dbfe069e6f1d..797318611c37 100644 --- a/sdk/storage/azblob/internal/generated/zz_appendblob_client.go +++ b/sdk/storage/azblob/internal/generated/zz_appendblob_client.go @@ -32,7 +32,7 @@ type AppendBlobClient struct { // AppendBlob. Append Block is supported only on version 2015-02-21 version or later. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - body - Initial data // - options - AppendBlobClientAppendBlockOptions contains the optional parameters for the AppendBlobClient.AppendBlock method. @@ -201,7 +201,7 @@ func (client *AppendBlobClient) appendBlockHandleResponse(resp *http.Response) ( // created with x-ms-blob-type set to AppendBlob. Append Block is supported only on version 2015-02-21 version or later. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - sourceURL - Specify a URL to the copy source. // - contentLength - The length of the request. // - options - AppendBlobClientAppendBlockFromURLOptions contains the optional parameters for the AppendBlobClient.AppendBlockFromURL @@ -387,7 +387,7 @@ func (client *AppendBlobClient) appendBlockFromURLHandleResponse(resp *http.Resp // Create - The Create Append Blob operation creates a new append blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - options - AppendBlobClientCreateOptions contains the optional parameters for the AppendBlobClient.Create method. // - BlobHTTPHeaders - BlobHTTPHeaders contains a group of parameters for the BlobClient.SetHTTPHeaders method. @@ -560,7 +560,7 @@ func (client *AppendBlobClient) createHandleResponse(resp *http.Response) (Appen // or later. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - AppendBlobClientSealOptions contains the optional parameters for the AppendBlobClient.Seal method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. diff --git a/sdk/storage/azblob/internal/generated/zz_blob_client.go b/sdk/storage/azblob/internal/generated/zz_blob_client.go index caaa3dfed7c4..fe568a96c7ac 100644 --- a/sdk/storage/azblob/internal/generated/zz_blob_client.go +++ b/sdk/storage/azblob/internal/generated/zz_blob_client.go @@ -32,7 +32,7 @@ type BlobClient struct { // blob with zero length and full metadata. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - copyID - The copy identifier provided in the x-ms-copy-id header of the original Copy Blob operation. // - options - BlobClientAbortCopyFromURLOptions contains the optional parameters for the BlobClient.AbortCopyFromURL method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -104,7 +104,7 @@ func (client *BlobClient) abortCopyFromURLHandleResponse(resp *http.Response) (B // AcquireLease - [Update] The Lease Blob operation establishes and manages a lock on a blob for write and delete operations // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - duration - Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite // lease can be between 15 and 60 seconds. A lease duration cannot be changed using // renew or change. @@ -206,7 +206,7 @@ func (client *BlobClient) acquireLeaseHandleResponse(resp *http.Response) (BlobC // BreakLease - [Update] The Lease Blob operation establishes and manages a lock on a blob for write and delete operations // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientBreakLeaseOptions contains the optional parameters for the BlobClient.BreakLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. func (client *BlobClient) BreakLease(ctx context.Context, options *BlobClientBreakLeaseOptions, modifiedAccessConditions *ModifiedAccessConditions) (BlobClientBreakLeaseResponse, error) { @@ -309,7 +309,7 @@ func (client *BlobClient) breakLeaseHandleResponse(resp *http.Response) (BlobCli // ChangeLease - [Update] The Lease Blob operation establishes and manages a lock on a blob for write and delete operations // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - proposedLeaseID - Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed // lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID @@ -411,7 +411,7 @@ func (client *BlobClient) changeLeaseHandleResponse(resp *http.Response) (BlobCl // until the copy is complete. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - copySource - Specifies the name of the source page blob snapshot. This value is a URL of up to 2 KB in length that specifies // a page blob snapshot. The value should be URL-encoded as it would appear in a request // URI. The source blob must either be public or must be authenticated via a shared access signature. @@ -585,7 +585,7 @@ func (client *BlobClient) copyFromURLHandleResponse(resp *http.Response) (BlobCl // CreateSnapshot - The Create Snapshot operation creates a read-only snapshot of a blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientCreateSnapshotOptions contains the optional parameters for the BlobClient.CreateSnapshot method. // - CPKInfo - CPKInfo contains a group of parameters for the BlobClient.Download method. // - CPKScopeInfo - CPKScopeInfo contains a group of parameters for the BlobClient.SetMetadata method. @@ -724,7 +724,7 @@ func (client *BlobClient) createSnapshotHandleResponse(resp *http.Response) (Blo // return an HTTP status code of 404 (ResourceNotFound). // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientDeleteOptions contains the optional parameters for the BlobClient.Delete method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -820,7 +820,7 @@ func (client *BlobClient) deleteHandleResponse(resp *http.Response) (BlobClientD // DeleteImmutabilityPolicy - The Delete Immutability Policy operation deletes the immutability policy on the blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientDeleteImmutabilityPolicyOptions contains the optional parameters for the BlobClient.DeleteImmutabilityPolicy // method. func (client *BlobClient) DeleteImmutabilityPolicy(ctx context.Context, options *BlobClientDeleteImmutabilityPolicyOptions) (BlobClientDeleteImmutabilityPolicyResponse, error) { @@ -887,7 +887,7 @@ func (client *BlobClient) deleteImmutabilityPolicyHandleResponse(resp *http.Resp // can also call Download to read a snapshot. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientDownloadOptions contains the optional parameters for the BlobClient.Download method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - CPKInfo - CPKInfo contains a group of parameters for the BlobClient.Download method. @@ -1195,7 +1195,7 @@ func (client *BlobClient) downloadHandleResponse(resp *http.Response) (BlobClien // GetAccountInfo - Returns the sku name and account kind // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientGetAccountInfoOptions contains the optional parameters for the BlobClient.GetAccountInfo method. func (client *BlobClient) GetAccountInfo(ctx context.Context, options *BlobClientGetAccountInfoOptions) (BlobClientGetAccountInfoResponse, error) { var err error @@ -1262,7 +1262,7 @@ func (client *BlobClient) getAccountInfoHandleResponse(resp *http.Response) (Blo // for the blob. It does not return the content of the blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientGetPropertiesOptions contains the optional parameters for the BlobClient.GetProperties method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - CPKInfo - CPKInfo contains a group of parameters for the BlobClient.Download method. @@ -1580,7 +1580,7 @@ func (client *BlobClient) getPropertiesHandleResponse(resp *http.Response) (Blob // GetTags - The Get Tags operation enables users to get the tags associated with a blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientGetTagsOptions contains the optional parameters for the BlobClient.GetTags method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -1662,7 +1662,7 @@ func (client *BlobClient) getTagsHandleResponse(resp *http.Response) (BlobClient // Query - The Query operation enables users to select/project on blob data by providing simple query expressions. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientQueryOptions contains the optional parameters for the BlobClient.Query method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - CPKInfo - CPKInfo contains a group of parameters for the BlobClient.Download method. @@ -1896,7 +1896,7 @@ func (client *BlobClient) queryHandleResponse(resp *http.Response) (BlobClientQu // ReleaseLease - [Update] The Lease Blob operation establishes and manages a lock on a blob for write and delete operations // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - options - BlobClientReleaseLeaseOptions contains the optional parameters for the BlobClient.ReleaseLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -1990,7 +1990,7 @@ func (client *BlobClient) releaseLeaseHandleResponse(resp *http.Response) (BlobC // RenewLease - [Update] The Lease Blob operation establishes and manages a lock on a blob for write and delete operations // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - options - BlobClientRenewLeaseOptions contains the optional parameters for the BlobClient.RenewLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -2087,7 +2087,7 @@ func (client *BlobClient) renewLeaseHandleResponse(resp *http.Response) (BlobCli // SetExpiry - Sets the time a blob will expire and be deleted. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - expiryOptions - Required. Indicates mode of the expiry time // - options - BlobClientSetExpiryOptions contains the optional parameters for the BlobClient.SetExpiry method. func (client *BlobClient) SetExpiry(ctx context.Context, expiryOptions ExpiryOptions, options *BlobClientSetExpiryOptions) (BlobClientSetExpiryResponse, error) { @@ -2167,7 +2167,7 @@ func (client *BlobClient) setExpiryHandleResponse(resp *http.Response) (BlobClie // SetHTTPHeaders - The Set HTTP Headers operation sets system properties on the blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientSetHTTPHeadersOptions contains the optional parameters for the BlobClient.SetHTTPHeaders method. // - BlobHTTPHeaders - BlobHTTPHeaders contains a group of parameters for the BlobClient.SetHTTPHeaders method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -2288,7 +2288,7 @@ func (client *BlobClient) setHTTPHeadersHandleResponse(resp *http.Response) (Blo // SetImmutabilityPolicy - The Set Immutability Policy operation sets the immutability policy on the blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientSetImmutabilityPolicyOptions contains the optional parameters for the BlobClient.SetImmutabilityPolicy // method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -2374,7 +2374,7 @@ func (client *BlobClient) setImmutabilityPolicyHandleResponse(resp *http.Respons // SetLegalHold - The Set Legal Hold operation sets a legal hold on the blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - legalHold - Specified if a legal hold should be set on the blob. // - options - BlobClientSetLegalHoldOptions contains the optional parameters for the BlobClient.SetLegalHold method. func (client *BlobClient) SetLegalHold(ctx context.Context, legalHold bool, options *BlobClientSetLegalHoldOptions) (BlobClientSetLegalHoldResponse, error) { @@ -2449,7 +2449,7 @@ func (client *BlobClient) setLegalHoldHandleResponse(resp *http.Response) (BlobC // pairs // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientSetMetadataOptions contains the optional parameters for the BlobClient.SetMetadata method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - CPKInfo - CPKInfo contains a group of parameters for the BlobClient.Download method. @@ -2581,7 +2581,7 @@ func (client *BlobClient) setMetadataHandleResponse(resp *http.Response) (BlobCl // SetTags - The Set Tags operation enables users to set tags on a blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - tags - Blob tags // - options - BlobClientSetTagsOptions contains the optional parameters for the BlobClient.SetTags method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -2670,7 +2670,7 @@ func (client *BlobClient) setTagsHandleResponse(resp *http.Response) (BlobClient // storage type. This operation does not update the blob's ETag. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - tier - Indicates the tier to be set on the blob. // - options - BlobClientSetTierOptions contains the optional parameters for the BlobClient.SetTier method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -2747,7 +2747,7 @@ func (client *BlobClient) setTierHandleResponse(resp *http.Response) (BlobClient // StartCopyFromURL - The Start Copy From URL operation copies a blob or an internet resource to a new blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - copySource - Specifies the name of the source page blob snapshot. This value is a URL of up to 2 KB in length that specifies // a page blob snapshot. The value should be URL-encoded as it would appear in a request // URI. The source blob must either be public or must be authenticated via a shared access signature. @@ -2899,7 +2899,7 @@ func (client *BlobClient) startCopyFromURLHandleResponse(resp *http.Response) (B // Undelete - Undelete a blob that was previously soft deleted // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - BlobClientUndeleteOptions contains the optional parameters for the BlobClient.Undelete method. func (client *BlobClient) Undelete(ctx context.Context, options *BlobClientUndeleteOptions) (BlobClientUndeleteResponse, error) { var err error diff --git a/sdk/storage/azblob/internal/generated/zz_blockblob_client.go b/sdk/storage/azblob/internal/generated/zz_blockblob_client.go index bfd7f5eac7de..b6115b50a656 100644 --- a/sdk/storage/azblob/internal/generated/zz_blockblob_client.go +++ b/sdk/storage/azblob/internal/generated/zz_blockblob_client.go @@ -36,7 +36,7 @@ type BlockBlobClient struct { // belong to. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - blocks - Blob Blocks. // - options - BlockBlobClientCommitBlockListOptions contains the optional parameters for the BlockBlobClient.CommitBlockList // method. @@ -227,7 +227,7 @@ func (client *BlockBlobClient) commitBlockListHandleResponse(resp *http.Response // GetBlockList - The Get Block List operation retrieves the list of blocks that have been uploaded as part of a block blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - listType - Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together. // - options - BlockBlobClientGetBlockListOptions contains the optional parameters for the BlockBlobClient.GetBlockList method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -332,7 +332,7 @@ func (client *BlockBlobClient) getBlockListHandleResponse(resp *http.Response) ( // Block from URL API in conjunction with Put Block List. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - copySource - Specifies the name of the source page blob snapshot. This value is a URL of up to 2 KB in length that specifies // a page blob snapshot. The value should be URL-encoded as it would appear in a request @@ -535,7 +535,7 @@ func (client *BlockBlobClient) putBlobFromURLHandleResponse(resp *http.Response) // StageBlock - The Stage Block operation creates a new block to be committed as part of a blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - blockID - A valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal // to 64 bytes in size. For a given blob, the length of the value specified for the blockid // parameter must be the same size for each block. @@ -662,7 +662,7 @@ func (client *BlockBlobClient) stageBlockHandleResponse(resp *http.Response) (Bl // are read from a URL. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - blockID - A valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal // to 64 bytes in size. For a given blob, the length of the value specified for the blockid // parameter must be the same size for each block. @@ -810,7 +810,7 @@ func (client *BlockBlobClient) stageBlockFromURLHandleResponse(resp *http.Respon // the content of a block blob, use the Put Block List operation. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - body - Initial data // - options - BlockBlobClientUploadOptions contains the optional parameters for the BlockBlobClient.Upload method. diff --git a/sdk/storage/azblob/internal/generated/zz_container_client.go b/sdk/storage/azblob/internal/generated/zz_container_client.go index ce1ff6fdd75e..dbc2a293ec67 100644 --- a/sdk/storage/azblob/internal/generated/zz_container_client.go +++ b/sdk/storage/azblob/internal/generated/zz_container_client.go @@ -34,7 +34,7 @@ type ContainerClient struct { // to 60 seconds, or can be infinite // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - duration - Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite // lease can be between 15 and 60 seconds. A lease duration cannot be changed using // renew or change. @@ -129,7 +129,7 @@ func (client *ContainerClient) acquireLeaseHandleResponse(resp *http.Response) ( // to 60 seconds, or can be infinite // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientBreakLeaseOptions contains the optional parameters for the ContainerClient.BreakLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. func (client *ContainerClient) BreakLease(ctx context.Context, options *ContainerClientBreakLeaseOptions, modifiedAccessConditions *ModifiedAccessConditions) (ContainerClientBreakLeaseResponse, error) { @@ -225,7 +225,7 @@ func (client *ContainerClient) breakLeaseHandleResponse(resp *http.Response) (Co // to 60 seconds, or can be infinite // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - proposedLeaseID - Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed // lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID @@ -319,7 +319,7 @@ func (client *ContainerClient) changeLeaseHandleResponse(resp *http.Response) (C // fails // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientCreateOptions contains the optional parameters for the ContainerClient.Create method. // - ContainerCPKScopeInfo - ContainerCPKScopeInfo contains a group of parameters for the ContainerClient.Create method. func (client *ContainerClient) Create(ctx context.Context, options *ContainerClientCreateOptions, containerCPKScopeInfo *ContainerCPKScopeInfo) (ContainerClientCreateResponse, error) { @@ -412,7 +412,7 @@ func (client *ContainerClient) createHandleResponse(resp *http.Response) (Contai // deleted during garbage collection // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientDeleteOptions contains the optional parameters for the ContainerClient.Delete method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -489,7 +489,7 @@ func (client *ContainerClient) deleteHandleResponse(resp *http.Response) (Contai // Filter blobs searches within the given container. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - where - Filters the results to return only to return only blobs whose tags match the specified expression. // - options - ContainerClientFilterBlobsOptions contains the optional parameters for the ContainerClient.FilterBlobs method. func (client *ContainerClient) FilterBlobs(ctx context.Context, where string, options *ContainerClientFilterBlobsOptions) (ContainerClientFilterBlobsResponse, error) { @@ -570,7 +570,7 @@ func (client *ContainerClient) filterBlobsHandleResponse(resp *http.Response) (C // be accessed publicly. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientGetAccessPolicyOptions contains the optional parameters for the ContainerClient.GetAccessPolicy // method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -657,7 +657,7 @@ func (client *ContainerClient) getAccessPolicyHandleResponse(resp *http.Response // GetAccountInfo - Returns the sku name and account kind // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientGetAccountInfoOptions contains the optional parameters for the ContainerClient.GetAccountInfo // method. func (client *ContainerClient) GetAccountInfo(ctx context.Context, options *ContainerClientGetAccountInfoOptions) (ContainerClientGetAccountInfoResponse, error) { @@ -725,7 +725,7 @@ func (client *ContainerClient) getAccountInfoHandleResponse(resp *http.Response) // does not include the container's list of blobs // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientGetPropertiesOptions contains the optional parameters for the ContainerClient.GetProperties method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. func (client *ContainerClient) GetProperties(ctx context.Context, options *ContainerClientGetPropertiesOptions, leaseAccessConditions *LeaseAccessConditions) (ContainerClientGetPropertiesResponse, error) { @@ -854,7 +854,7 @@ func (client *ContainerClient) getPropertiesHandleResponse(resp *http.Response) // NewListBlobFlatSegmentPager - [Update] The List Blobs operation returns a list of the blobs under the specified container // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientListBlobFlatSegmentOptions contains the optional parameters for the ContainerClient.NewListBlobFlatSegmentPager // method. // @@ -921,7 +921,7 @@ func (client *ContainerClient) ListBlobFlatSegmentHandleResponse(resp *http.Resp // NewListBlobHierarchySegmentPager - [Update] The List Blobs operation returns a list of the blobs under the specified container // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - delimiter - When the request includes this parameter, the operation returns a BlobPrefix element in the response body that // acts as a placeholder for all blobs whose names begin with the same substring up to the // appearance of the delimiter character. The delimiter may be a single character or a string. @@ -1014,7 +1014,7 @@ func (client *ContainerClient) ListBlobHierarchySegmentHandleResponse(resp *http // to 60 seconds, or can be infinite // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - options - ContainerClientReleaseLeaseOptions contains the optional parameters for the ContainerClient.ReleaseLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -1100,7 +1100,7 @@ func (client *ContainerClient) releaseLeaseHandleResponse(resp *http.Response) ( // Rename - Renames an existing container. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - sourceContainerName - Required. Specifies the name of the container to rename. // - options - ContainerClientRenameOptions contains the optional parameters for the ContainerClient.Rename method. func (client *ContainerClient) Rename(ctx context.Context, sourceContainerName string, options *ContainerClientRenameOptions) (ContainerClientRenameResponse, error) { @@ -1172,7 +1172,7 @@ func (client *ContainerClient) renameHandleResponse(resp *http.Response) (Contai // to 60 seconds, or can be infinite // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - leaseID - Specifies the current lease ID on the resource. // - options - ContainerClientRenewLeaseOptions contains the optional parameters for the ContainerClient.RenewLease method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -1261,7 +1261,7 @@ func (client *ContainerClient) renewLeaseHandleResponse(resp *http.Response) (Co // Restore - Restores a previously-deleted container. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientRestoreOptions contains the optional parameters for the ContainerClient.Restore method. func (client *ContainerClient) Restore(ctx context.Context, options *ContainerClientRestoreOptions) (ContainerClientRestoreResponse, error) { var err error @@ -1334,7 +1334,7 @@ func (client *ContainerClient) restoreHandleResponse(resp *http.Response) (Conta // may be accessed publicly. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - containerACL - the acls for the container // - options - ContainerClientSetAccessPolicyOptions contains the optional parameters for the ContainerClient.SetAccessPolicy // method. @@ -1433,7 +1433,7 @@ func (client *ContainerClient) setAccessPolicyHandleResponse(resp *http.Response // SetMetadata - operation sets one or more user-defined name-value pairs for the specified container. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ContainerClientSetMetadataOptions contains the optional parameters for the ContainerClient.SetMetadata method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. // - ModifiedAccessConditions - ModifiedAccessConditions contains a group of parameters for the ContainerClient.Delete method. @@ -1524,7 +1524,7 @@ func (client *ContainerClient) setMetadataHandleResponse(resp *http.Response) (C // SubmitBatch - The Batch operation allows multiple API calls to be embedded into a single HTTP request. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - multipartContentType - Required. The value of this header must be multipart/mixed with a batch boundary. Example header // value: multipart/mixed; boundary=batch_ diff --git a/sdk/storage/azblob/internal/generated/zz_pageblob_client.go b/sdk/storage/azblob/internal/generated/zz_pageblob_client.go index bfa9883f5ce7..cb6a19f7a335 100644 --- a/sdk/storage/azblob/internal/generated/zz_pageblob_client.go +++ b/sdk/storage/azblob/internal/generated/zz_pageblob_client.go @@ -30,7 +30,7 @@ type PageBlobClient struct { // ClearPages - The Clear Pages operation clears a set of pages from a page blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - options - PageBlobClientClearPagesOptions contains the optional parameters for the PageBlobClient.ClearPages method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -181,7 +181,7 @@ func (client *PageBlobClient) clearPagesHandleResponse(resp *http.Response) (Pag // 2016-05-31. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - copySource - Specifies the name of the source page blob snapshot. This value is a URL of up to 2 KB in length that specifies // a page blob snapshot. The value should be URL-encoded as it would appear in a request // URI. The source blob must either be public or must be authenticated via a shared access signature. @@ -283,7 +283,7 @@ func (client *PageBlobClient) copyIncrementalHandleResponse(resp *http.Response) // Create - The Create operation creates a new page blob. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - blobContentLength - This header specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned // to a 512-byte boundary. @@ -464,7 +464,7 @@ func (client *PageBlobClient) createHandleResponse(resp *http.Response) (PageBlo // NewGetPageRangesPager - The Get Page Ranges operation returns the list of valid page ranges for a page blob or snapshot // of a page blob // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - PageBlobClientGetPageRangesOptions contains the optional parameters for the PageBlobClient.NewGetPageRangesPager // method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -585,7 +585,7 @@ func (client *PageBlobClient) GetPageRangesHandleResponse(resp *http.Response) ( // NewGetPageRangesDiffPager - The Get Page Ranges Diff operation returns the list of valid page ranges for a page blob that // were changed between target blob and previous snapshot. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - PageBlobClientGetPageRangesDiffOptions contains the optional parameters for the PageBlobClient.NewGetPageRangesDiffPager // method. // - LeaseAccessConditions - LeaseAccessConditions contains a group of parameters for the ContainerClient.GetProperties method. @@ -712,7 +712,7 @@ func (client *PageBlobClient) GetPageRangesDiffHandleResponse(resp *http.Respons // Resize - Resize the Blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - blobContentLength - This header specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned // to a 512-byte boundary. // - options - PageBlobClientResizeOptions contains the optional parameters for the PageBlobClient.Resize method. @@ -831,7 +831,7 @@ func (client *PageBlobClient) resizeHandleResponse(resp *http.Response) (PageBlo // UpdateSequenceNumber - Update the sequence number of the blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - sequenceNumberAction - Required if the x-ms-blob-sequence-number header is set for the request. This property applies to // page blobs only. This property indicates how the service should modify the blob's sequence number // - options - PageBlobClientUpdateSequenceNumberOptions contains the optional parameters for the PageBlobClient.UpdateSequenceNumber @@ -940,7 +940,7 @@ func (client *PageBlobClient) updateSequenceNumberHandleResponse(resp *http.Resp // UploadPages - The Upload Pages operation writes a range of pages to a page blob // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - body - Initial data // - options - PageBlobClientUploadPagesOptions contains the optional parameters for the PageBlobClient.UploadPages method. @@ -1111,7 +1111,7 @@ func (client *PageBlobClient) uploadPagesHandleResponse(resp *http.Response) (Pa // a URL // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - sourceURL - Specify a URL to the copy source. // - sourceRange - Bytes of source data in the specified range. The length of this range should match the ContentLength header // and x-ms-range/Range destination range header. diff --git a/sdk/storage/azblob/internal/generated/zz_service_client.go b/sdk/storage/azblob/internal/generated/zz_service_client.go index 9a73b7301b17..c792fbf094bf 100644 --- a/sdk/storage/azblob/internal/generated/zz_service_client.go +++ b/sdk/storage/azblob/internal/generated/zz_service_client.go @@ -33,7 +33,7 @@ type ServiceClient struct { // be scoped within the expression to a single container. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - where - Filters the results to return only to return only blobs whose tags match the specified expression. // - options - ServiceClientFilterBlobsOptions contains the optional parameters for the ServiceClient.FilterBlobs method. func (client *ServiceClient) FilterBlobs(ctx context.Context, where string, options *ServiceClientFilterBlobsOptions) (ServiceClientFilterBlobsResponse, error) { @@ -112,7 +112,7 @@ func (client *ServiceClient) filterBlobsHandleResponse(resp *http.Response) (Ser // GetAccountInfo - Returns the sku name and account kind // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ServiceClientGetAccountInfoOptions contains the optional parameters for the ServiceClient.GetAccountInfo method. func (client *ServiceClient) GetAccountInfo(ctx context.Context, options *ServiceClientGetAccountInfoOptions) (ServiceClientGetAccountInfoResponse, error) { var err error @@ -186,7 +186,7 @@ func (client *ServiceClient) getAccountInfoHandleResponse(resp *http.Response) ( // CORS (Cross-Origin Resource Sharing) rules. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ServiceClientGetPropertiesOptions contains the optional parameters for the ServiceClient.GetProperties method. func (client *ServiceClient) GetProperties(ctx context.Context, options *ServiceClientGetPropertiesOptions) (ServiceClientGetPropertiesResponse, error) { var err error @@ -249,7 +249,7 @@ func (client *ServiceClient) getPropertiesHandleResponse(resp *http.Response) (S // location endpoint when read-access geo-redundant replication is enabled for the storage account. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ServiceClientGetStatisticsOptions contains the optional parameters for the ServiceClient.GetStatistics method. func (client *ServiceClient) GetStatistics(ctx context.Context, options *ServiceClientGetStatisticsOptions) (ServiceClientGetStatisticsResponse, error) { var err error @@ -319,7 +319,7 @@ func (client *ServiceClient) getStatisticsHandleResponse(resp *http.Response) (S // bearer token authentication. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - keyInfo - Key information // - options - ServiceClientGetUserDelegationKeyOptions contains the optional parameters for the ServiceClient.GetUserDelegationKey // method. @@ -393,7 +393,7 @@ func (client *ServiceClient) getUserDelegationKeyHandleResponse(resp *http.Respo // NewListContainersSegmentPager - The List Containers Segment operation returns a list of the containers under the specified // account // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - options - ServiceClientListContainersSegmentOptions contains the optional parameters for the ServiceClient.NewListContainersSegmentPager // method. // @@ -451,7 +451,7 @@ func (client *ServiceClient) ListContainersSegmentHandleResponse(resp *http.Resp // and CORS (Cross-Origin Resource Sharing) rules // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - storageServiceProperties - The StorageService properties. // - options - ServiceClientSetPropertiesOptions contains the optional parameters for the ServiceClient.SetProperties method. func (client *ServiceClient) SetProperties(ctx context.Context, storageServiceProperties StorageServiceProperties, options *ServiceClientSetPropertiesOptions) (ServiceClientSetPropertiesResponse, error) { @@ -514,7 +514,7 @@ func (client *ServiceClient) setPropertiesHandleResponse(resp *http.Response) (S // SubmitBatch - The Batch operation allows multiple API calls to be embedded into a single HTTP request. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2023-08-03 +// Generated from API version 2023-11-03 // - contentLength - The length of the request. // - multipartContentType - Required. The value of this header must be multipart/mixed with a batch boundary. Example header // value: multipart/mixed; boundary=batch_ From 233b276fc17f31017f692f85455345ea0f134c16 Mon Sep 17 00:00:00 2001 From: Sourav Gupta <98318303+souravgupta-msft@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:09:04 +0530 Subject: [PATCH 2/4] azblob: Add support for AAD audience (#22169) --- sdk/storage/azblob/CHANGELOG.md | 3 + sdk/storage/azblob/appendblob/client.go | 3 +- sdk/storage/azblob/appendblob/client_test.go | 68 +++++++++++ sdk/storage/azblob/assets.json | 2 +- sdk/storage/azblob/blob/client.go | 17 ++- sdk/storage/azblob/blob/client_test.go | 64 +++++++++++ sdk/storage/azblob/blockblob/client.go | 3 +- sdk/storage/azblob/blockblob/client_test.go | 76 +++++++++++++ sdk/storage/azblob/client.go | 19 +--- sdk/storage/azblob/client_test.go | 107 ++++++++++++++++++ sdk/storage/azblob/container/client.go | 17 ++- sdk/storage/azblob/container/client_test.go | 52 +++++++++ sdk/storage/azblob/internal/base/clients.go | 29 ++++- .../internal/shared/challenge_policy.go | 6 +- .../internal/shared/challenge_policy_test.go | 4 +- sdk/storage/azblob/pageblob/client.go | 3 +- sdk/storage/azblob/pageblob/client_test.go | 68 +++++++++++ sdk/storage/azblob/service/client.go | 17 ++- sdk/storage/azblob/service/client_test.go | 76 +++++++++++++ 19 files changed, 589 insertions(+), 45 deletions(-) diff --git a/sdk/storage/azblob/CHANGELOG.md b/sdk/storage/azblob/CHANGELOG.md index 77698e093e25..0d363352c48c 100644 --- a/sdk/storage/azblob/CHANGELOG.md +++ b/sdk/storage/azblob/CHANGELOG.md @@ -4,6 +4,9 @@ ### Features Added +* Updated service version to `2023-11-03`. +* Added support for Audience when OAuth is used. + ### Breaking Changes ### Bugs Fixed diff --git a/sdk/storage/azblob/appendblob/client.go b/sdk/storage/azblob/appendblob/client.go index 2229b7d85e7f..ef8e2e85a068 100644 --- a/sdk/storage/azblob/appendblob/client.go +++ b/sdk/storage/azblob/appendblob/client.go @@ -35,7 +35,8 @@ type Client base.CompositeClient[generated.BlobClient, generated.AppendBlobClien // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} diff --git a/sdk/storage/azblob/appendblob/client_test.go b/sdk/storage/azblob/appendblob/client_test.go index 865b57d0e743..25ba1642f759 100644 --- a/sdk/storage/azblob/appendblob/client_test.go +++ b/sdk/storage/azblob/appendblob/client_test.go @@ -3578,3 +3578,71 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockSetTier() { _, err = abClient.SetTier(context.Background(), blob.AccessTierHot, nil) _require.ErrorContains(err, "operation will not work on this blob type. SetTier only works for page blob in premium storage account and block blob in blob storage account") } + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &appendblob.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + abClientAudience, err := appendblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = abClientAudience.Create(context.Background(), nil) + _require.NoError(err) + + _, err = abClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &appendblob.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + abClientAudience, err := appendblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = abClientAudience.Create(context.Background(), nil) + _require.NoError(err) + + _, err = abClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/assets.json b/sdk/storage/azblob/assets.json index 80d6183c5b52..a2a2f83f8d49 100644 --- a/sdk/storage/azblob/assets.json +++ b/sdk/storage/azblob/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/storage/azblob", - "Tag": "go/storage/azblob_0040e8284c" + "Tag": "go/storage/azblob_ceb9b7d6b4" } diff --git a/sdk/storage/azblob/blob/client.go b/sdk/storage/azblob/blob/client.go index d2421ddd916a..23955a828f72 100644 --- a/sdk/storage/azblob/blob/client.go +++ b/sdk/storage/azblob/blob/client.go @@ -36,7 +36,8 @@ type Client base.Client[generated.BlobClient] // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} @@ -44,7 +45,7 @@ func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptio if err != nil { return nil, err } - return (*Client)(base.NewBlobClient(blobURL, azClient, &cred)), nil + return (*Client)(base.NewBlobClient(blobURL, azClient, &cred, (*base.ClientOptions)(conOptions))), nil } // NewClientWithNoCredential creates an instance of Client with the specified values. @@ -58,7 +59,7 @@ func NewClientWithNoCredential(blobURL string, options *ClientOptions) (*Client, if err != nil { return nil, err } - return (*Client)(base.NewBlobClient(blobURL, azClient, nil)), nil + return (*Client)(base.NewBlobClient(blobURL, azClient, nil, (*base.ClientOptions)(conOptions))), nil } // NewClientWithSharedKeyCredential creates an instance of Client with the specified values. @@ -74,7 +75,7 @@ func NewClientWithSharedKeyCredential(blobURL string, cred *SharedKeyCredential, if err != nil { return nil, err } - return (*Client)(base.NewBlobClient(blobURL, azClient, cred)), nil + return (*Client)(base.NewBlobClient(blobURL, azClient, cred, (*base.ClientOptions)(conOptions))), nil } // NewClientFromConnectionString creates an instance of Client with the specified values. @@ -112,6 +113,10 @@ func (b *Client) credential() any { return base.Credential((*base.Client[generated.BlobClient])(b)) } +func (b *Client) getClientOptions() *base.ClientOptions { + return base.GetClientOptions((*base.Client[generated.BlobClient])(b)) +} + // URL returns the URL endpoint used by the Client object. func (b *Client) URL() string { return b.generated().Endpoint() @@ -126,7 +131,7 @@ func (b *Client) WithSnapshot(snapshot string) (*Client, error) { } p.Snapshot = snapshot - return (*Client)(base.NewBlobClient(p.String(), b.generated().InternalClient(), b.credential())), nil + return (*Client)(base.NewBlobClient(p.String(), b.generated().InternalClient(), b.credential(), b.getClientOptions())), nil } // WithVersionID creates a new AppendBlobURL object identical to the source but with the specified version id. @@ -138,7 +143,7 @@ func (b *Client) WithVersionID(versionID string) (*Client, error) { } p.VersionID = versionID - return (*Client)(base.NewBlobClient(p.String(), b.generated().InternalClient(), b.credential())), nil + return (*Client)(base.NewBlobClient(p.String(), b.generated().InternalClient(), b.credential(), b.getClientOptions())), nil } // Delete marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. diff --git a/sdk/storage/azblob/blob/client_test.go b/sdk/storage/azblob/blob/client_test.go index d8d43666a303..b70626f948ec 100644 --- a/sdk/storage/azblob/blob/client_test.go +++ b/sdk/storage/azblob/blob/client_test.go @@ -3681,3 +3681,67 @@ func (s *BlobRecordedTestsSuite) TestBlobGetAccountInfo() { _require.NoError(err) _require.NotZero(bAccInfo) } + +func (s *BlobRecordedTestsSuite) TestBlobClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + testcommon.CreateNewBlockBlob(context.Background(), _require, blobName, containerClient) + + options := &blob.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + blobClientAudience, err := blob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = blobClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} + +func (s *BlobRecordedTestsSuite) TestBlobClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + testcommon.CreateNewBlockBlob(context.Background(), _require, blobName, containerClient) + + options := &blob.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + blobClientAudience, err := blob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = blobClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/blockblob/client.go b/sdk/storage/azblob/blockblob/client.go index e3167b7747d8..b69c4d490d6d 100644 --- a/sdk/storage/azblob/blockblob/client.go +++ b/sdk/storage/azblob/blockblob/client.go @@ -45,7 +45,8 @@ type Client base.CompositeClient[generated.BlobClient, generated.BlockBlobClient // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} diff --git a/sdk/storage/azblob/blockblob/client_test.go b/sdk/storage/azblob/blockblob/client_test.go index e7d3841ab3a0..e8960f52fb3e 100644 --- a/sdk/storage/azblob/blockblob/client_test.go +++ b/sdk/storage/azblob/blockblob/client_test.go @@ -5869,3 +5869,79 @@ func TestServiceVersion(t *testing.T) { _, err = client.Upload(context.Background(), streaming.NopCloser(r), nil) require.NoError(t, err) } + +func (s *BlockBlobRecordedTestsSuite) TestBlockBlobClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &blockblob.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + bbClientAudience, err := blockblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + contentSize := 4 * 1024 // 4 KB + r, _ := testcommon.GetDataAndReader(testName, contentSize) + rsc := streaming.NopCloser(r) + + _, err = bbClientAudience.Upload(context.Background(), rsc, nil) + _require.NoError(err) + + _, err = bbClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} + +func (s *BlockBlobRecordedTestsSuite) TestBlockBlobClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &blockblob.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + bbClientAudience, err := blockblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + contentSize := 4 * 1024 // 4 KB + r, _ := testcommon.GetDataAndReader(testName, contentSize) + rsc := streaming.NopCloser(r) + + _, err = bbClientAudience.Upload(context.Background(), rsc, nil) + _require.NoError(err) + + _, err = bbClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/client.go b/sdk/storage/azblob/client.go index 5c4b719c4ba6..c511d8a79f20 100644 --- a/sdk/storage/azblob/client.go +++ b/sdk/storage/azblob/client.go @@ -31,11 +31,7 @@ type Client struct { // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - var clientOptions *service.ClientOptions - if options != nil { - clientOptions = &service.ClientOptions{ClientOptions: options.ClientOptions} - } - svcClient, err := service.NewClient(serviceURL, cred, clientOptions) + svcClient, err := service.NewClient(serviceURL, cred, (*service.ClientOptions)(options)) if err != nil { return nil, err } @@ -50,11 +46,7 @@ func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOp // - serviceURL - the URL of the storage account e.g. https://.blob.core.windows.net/? // - options - client options; pass nil to accept the default values func NewClientWithNoCredential(serviceURL string, options *ClientOptions) (*Client, error) { - var clientOptions *service.ClientOptions - if options != nil { - clientOptions = &service.ClientOptions{ClientOptions: options.ClientOptions} - } - svcClient, err := service.NewClientWithNoCredential(serviceURL, clientOptions) + svcClient, err := service.NewClientWithNoCredential(serviceURL, (*service.ClientOptions)(options)) if err != nil { return nil, err } @@ -83,15 +75,12 @@ func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredenti // - connectionString - a connection string for the desired storage account // - options - client options; pass nil to accept the default values func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error) { - if options == nil { - options = &ClientOptions{} - } - containerClient, err := service.NewClientFromConnectionString(connectionString, (*service.ClientOptions)(options)) + svcClient, err := service.NewClientFromConnectionString(connectionString, (*service.ClientOptions)(options)) if err != nil { return nil, err } return &Client{ - svc: containerClient, + svc: svcClient, }, nil } diff --git a/sdk/storage/azblob/client_test.go b/sdk/storage/azblob/client_test.go index 2bcf3400527d..6625d5f039c5 100644 --- a/sdk/storage/azblob/client_test.go +++ b/sdk/storage/azblob/client_test.go @@ -12,6 +12,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "hash/crc64" "io" "os" @@ -80,6 +81,36 @@ func (s *AZBlobUnrecordedTestsSuite) AfterTest(suite string, test string) { } +func (s *AZBlobRecordedTestsSuite) TestAzBlobClientSharedKey() { + _require := require.New(s.T()) + + cred, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault) + _require.NoError(err) + + svcURL := "https://" + cred.AccountName() + ".blob.core.windows.net/" + azClient, err := azblob.NewClientWithSharedKeyCredential(svcURL, cred, nil) + _require.NoError(err) + _require.NotNil(azClient) + _require.Equal(azClient.URL(), svcURL) +} + +func (s *AZBlobRecordedTestsSuite) TestAzBlobClientConnectionString() { + _require := require.New(s.T()) + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + connString, err := testcommon.GetGenericConnectionString(testcommon.TestAccountDefault) + _require.NoError(err) + _require.NotNil(connString) + + svcURL := "https://" + accountName + ".blob.core.windows.net/" + azClient, err := azblob.NewClientFromConnectionString(*connString, nil) + _require.NoError(err) + _require.NotNil(azClient) + _require.Equal(azClient.URL(), svcURL) +} + // create a test file func generateFile(fileName string, fileSize int) []byte { // generate random data @@ -756,3 +787,79 @@ func (s *AZBlobUnrecordedTestsSuite) TestDoBatchTransferWithError() { mmf.isClosed = true time.Sleep(time.Second * 5) } + +func (s *AZBlobRecordedTestsSuite) TestAzBlobClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + options := &azblob.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + azClientAudience, err := azblob.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + _, err = azClientAudience.CreateContainer(context.Background(), containerName, nil) + _require.NoError(err) + + defer func() { + _, err = azClientAudience.DeleteContainer(context.Background(), containerName, nil) + _require.NoError(err) + }() + + pager := azClientAudience.NewListContainersPager(&azblob.ListContainersOptions{ + Prefix: &containerName, + }) + for pager.More() { + resp, err := pager.NextPage(context.Background()) + _require.NoError(err) + _require.Equal(len(resp.ContainerItems), 1) + _require.NotNil(resp.ContainerItems[0].Name) + _require.Equal(*resp.ContainerItems[0].Name, containerName) + } +} + +func (s *AZBlobRecordedTestsSuite) TestAzBlobClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + options := &azblob.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + azClientAudience, err := azblob.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + _, err = azClientAudience.CreateContainer(context.Background(), containerName, nil) + _require.NoError(err) + + defer func() { + _, err = azClientAudience.DeleteContainer(context.Background(), containerName, nil) + _require.NoError(err) + }() + + pager := azClientAudience.NewListContainersPager(&azblob.ListContainersOptions{ + Prefix: &containerName, + }) + for pager.More() { + resp, err := pager.NextPage(context.Background()) + _require.NoError(err) + _require.Equal(len(resp.ContainerItems), 1) + _require.NotNil(resp.ContainerItems[0].Name) + _require.Equal(*resp.ContainerItems[0].Name, containerName) + } +} diff --git a/sdk/storage/azblob/container/client.go b/sdk/storage/azblob/container/client.go index 3058b5d49c00..0086a81920dd 100644 --- a/sdk/storage/azblob/container/client.go +++ b/sdk/storage/azblob/container/client.go @@ -42,7 +42,8 @@ type Client base.Client[generated.ContainerClient] // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(containerURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} @@ -50,7 +51,7 @@ func NewClient(containerURL string, cred azcore.TokenCredential, options *Client if err != nil { return nil, err } - return (*Client)(base.NewContainerClient(containerURL, azClient, &cred)), nil + return (*Client)(base.NewContainerClient(containerURL, azClient, &cred, (*base.ClientOptions)(conOptions))), nil } // NewClientWithNoCredential creates an instance of Client with the specified values. @@ -64,7 +65,7 @@ func NewClientWithNoCredential(containerURL string, options *ClientOptions) (*Cl if err != nil { return nil, err } - return (*Client)(base.NewContainerClient(containerURL, azClient, nil)), nil + return (*Client)(base.NewContainerClient(containerURL, azClient, nil, (*base.ClientOptions)(conOptions))), nil } // NewClientWithSharedKeyCredential creates an instance of Client with the specified values. @@ -80,7 +81,7 @@ func NewClientWithSharedKeyCredential(containerURL string, cred *SharedKeyCreden if err != nil { return nil, err } - return (*Client)(base.NewContainerClient(containerURL, azClient, cred)), nil + return (*Client)(base.NewContainerClient(containerURL, azClient, cred, (*base.ClientOptions)(conOptions))), nil } // NewClientFromConnectionString creates an instance of Client with the specified values. @@ -122,6 +123,10 @@ func getGeneratedBlobClient(b *blob.Client) *generated.BlobClient { return base.InnerClient((*base.Client[generated.BlobClient])(b)) } +func (c *Client) getClientOptions() *base.ClientOptions { + return base.GetClientOptions((*base.Client[generated.ContainerClient])(c)) +} + // URL returns the URL endpoint used by the Client object. func (c *Client) URL() string { return c.generated().Endpoint() @@ -133,7 +138,7 @@ func (c *Client) URL() string { func (c *Client) NewBlobClient(blobName string) *blob.Client { blobName = url.PathEscape(blobName) blobURL := runtime.JoinPaths(c.URL(), blobName) - return (*blob.Client)(base.NewBlobClient(blobURL, c.generated().InternalClient().WithClientName(shared.BlobClient), c.credential())) + return (*blob.Client)(base.NewBlobClient(blobURL, c.generated().InternalClient().WithClientName(shared.BlobClient), c.credential(), c.getClientOptions())) } // NewAppendBlobClient creates a new appendblob.Client object by concatenating blobName to the end of @@ -366,7 +371,7 @@ func (c *Client) NewBatchBuilder() (*BatchBuilder, error) { switch cred := c.credential().(type) { case *azcore.TokenCredential: - authPolicy = shared.NewStorageChallengePolicy(*cred) + authPolicy = shared.NewStorageChallengePolicy(*cred, base.GetAudience(c.getClientOptions())) case *SharedKeyCredential: authPolicy = exported.NewSharedKeyCredPolicy(cred) case nil: diff --git a/sdk/storage/azblob/container/client_test.go b/sdk/storage/azblob/container/client_test.go index a0e089d60ae0..35fb22bf894b 100644 --- a/sdk/storage/azblob/container/client_test.go +++ b/sdk/storage/azblob/container/client_test.go @@ -3459,3 +3459,55 @@ func (s *ContainerUnrecordedTestsSuite) TestContainerSASUsingAccessPolicy() { _, err = bbClient.Delete(context.Background(), nil) _require.NoError(err) } + +func (s *ContainerRecordedTestsSuite) TestContainerClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + options := &container.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + containerClientAudience, err := container.NewClient("https://"+accountName+".blob.core.windows.net/"+containerName, cred, options) + _require.NoError(err) + + _, err = containerClientAudience.Create(context.Background(), nil) + _require.NoError(err) + defer testcommon.DeleteContainer(context.Background(), _require, containerClientAudience) + + _, err = containerClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} + +func (s *ContainerRecordedTestsSuite) TestContainerClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + options := &container.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + containerClientAudience, err := container.NewClient("https://"+accountName+".blob.core.windows.net/"+containerName, cred, options) + _require.NoError(err) + + _, err = containerClientAudience.Create(context.Background(), nil) + _require.NoError(err) + defer testcommon.DeleteContainer(context.Background(), _require, containerClientAudience) + + _, err = containerClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/internal/base/clients.go b/sdk/storage/azblob/internal/base/clients.go index c95f19254a71..e71f8643c2e1 100644 --- a/sdk/storage/azblob/internal/base/clients.go +++ b/sdk/storage/azblob/internal/base/clients.go @@ -10,16 +10,24 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/exported" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/generated" + "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/shared" + "strings" ) // ClientOptions contains the optional parameters when creating a Client. type ClientOptions struct { azcore.ClientOptions + + // Audience to use when requesting tokens for Azure Active Directory authentication. + // Only has an effect when credential is of type TokenCredential. The value could be + // https://storage.azure.com/ (default) or https://.blob.core.windows.net. + Audience *string } type Client[T any] struct { inner *T credential any + options *ClientOptions } func InnerClient[T any](client *Client[T]) *T { @@ -39,28 +47,43 @@ func Credential[T any](client *Client[T]) any { return client.credential } +func GetClientOptions[T any](client *Client[T]) *ClientOptions { + return client.options +} + +func GetAudience(clOpts *ClientOptions) string { + if clOpts == nil || clOpts.Audience == nil { + return shared.TokenScope + } else { + return strings.TrimRight(*clOpts.Audience, "/") + "/.default" + } +} + func NewClient[T any](inner *T) *Client[T] { return &Client[T]{inner: inner} } -func NewServiceClient(containerURL string, azClient *azcore.Client, credential any) *Client[generated.ServiceClient] { +func NewServiceClient(containerURL string, azClient *azcore.Client, credential any, options *ClientOptions) *Client[generated.ServiceClient] { return &Client[generated.ServiceClient]{ inner: generated.NewServiceClient(containerURL, azClient), credential: credential, + options: options, } } -func NewContainerClient(containerURL string, azClient *azcore.Client, credential any) *Client[generated.ContainerClient] { +func NewContainerClient(containerURL string, azClient *azcore.Client, credential any, options *ClientOptions) *Client[generated.ContainerClient] { return &Client[generated.ContainerClient]{ inner: generated.NewContainerClient(containerURL, azClient), credential: credential, + options: options, } } -func NewBlobClient(blobURL string, azClient *azcore.Client, credential any) *Client[generated.BlobClient] { +func NewBlobClient(blobURL string, azClient *azcore.Client, credential any, options *ClientOptions) *Client[generated.BlobClient] { return &Client[generated.BlobClient]{ inner: generated.NewBlobClient(blobURL, azClient), credential: credential, + options: options, } } diff --git a/sdk/storage/azblob/internal/shared/challenge_policy.go b/sdk/storage/azblob/internal/shared/challenge_policy.go index e7c8e9213d80..1c81b9db9b86 100644 --- a/sdk/storage/azblob/internal/shared/challenge_policy.go +++ b/sdk/storage/azblob/internal/shared/challenge_policy.go @@ -20,9 +20,9 @@ type storageAuthorizer struct { tenantID string } -func NewStorageChallengePolicy(cred azcore.TokenCredential) policy.Policy { - s := storageAuthorizer{scopes: []string{TokenScope}} - return runtime.NewBearerTokenPolicy(cred, []string{TokenScope}, &policy.BearerTokenOptions{ +func NewStorageChallengePolicy(cred azcore.TokenCredential, audience string) policy.Policy { + s := storageAuthorizer{scopes: []string{audience}} + return runtime.NewBearerTokenPolicy(cred, []string{audience}, &policy.BearerTokenOptions{ AuthorizationHandler: policy.AuthorizationHandler{ OnRequest: s.onRequest, OnChallenge: s.onChallenge, diff --git a/sdk/storage/azblob/internal/shared/challenge_policy_test.go b/sdk/storage/azblob/internal/shared/challenge_policy_test.go index f666947ef9c7..b6d16853d3c8 100644 --- a/sdk/storage/azblob/internal/shared/challenge_policy_test.go +++ b/sdk/storage/azblob/internal/shared/challenge_policy_test.go @@ -39,7 +39,7 @@ func TestChallengePolicyStorage(t *testing.T) { require.Equal(t, []string{storageScope}, tro.Scopes) return azcore.AccessToken{Token: accessToken, ExpiresOn: time.Now().Add(time.Hour)}, nil }) - p := NewStorageChallengePolicy(cred) + p := NewStorageChallengePolicy(cred, storageScope) pl := runtime.NewPipeline("", "", runtime.PipelineOptions{PerRetry: []policy.Policy{p}}, &policy.ClientOptions{Transport: srv}, @@ -77,7 +77,7 @@ func TestChallengePolicyDisk(t *testing.T) { attemptedAuthentication = true return azcore.AccessToken{}, nil }) - p := NewStorageChallengePolicy(cred) + p := NewStorageChallengePolicy(cred, "https://storage.azure.com/.default") pl := runtime.NewPipeline("", "", runtime.PipelineOptions{PerRetry: []policy.Policy{p}}, &policy.ClientOptions{Transport: srv}, diff --git a/sdk/storage/azblob/pageblob/client.go b/sdk/storage/azblob/pageblob/client.go index 14e90a1fd66e..1d62487c9104 100644 --- a/sdk/storage/azblob/pageblob/client.go +++ b/sdk/storage/azblob/pageblob/client.go @@ -36,7 +36,8 @@ type Client base.CompositeClient[generated.BlobClient, generated.PageBlobClient] // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} diff --git a/sdk/storage/azblob/pageblob/client_test.go b/sdk/storage/azblob/pageblob/client_test.go index 3a0b250bcde0..ce36b5a6e1b7 100644 --- a/sdk/storage/azblob/pageblob/client_test.go +++ b/sdk/storage/azblob/pageblob/client_test.go @@ -4929,3 +4929,71 @@ func (s *PageBlobRecordedTestsSuite) TestPageGetAccountInfo() { _require.NoError(err) _require.NotZero(bAccInfo) } + +func (s *PageBlobRecordedTestsSuite) TestPageBlobClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &pageblob.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + pbClientAudience, err := pageblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = pbClientAudience.Create(context.Background(), pageblob.PageBytes*10, nil) + _require.NoError(err) + + _, err = pbClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} + +func (s *PageBlobRecordedTestsSuite) TestPageBlobClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + blobName := testcommon.GenerateBlobName(testName) + blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) + + options := &pageblob.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + pbClientAudience, err := pageblob.NewClient(blobURL, cred, options) + _require.NoError(err) + + _, err = pbClientAudience.Create(context.Background(), pageblob.PageBytes*10, nil) + _require.NoError(err) + + _, err = pbClientAudience.GetProperties(context.Background(), nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/service/client.go b/sdk/storage/azblob/service/client.go index 461775347eeb..bcd10a4be864 100644 --- a/sdk/storage/azblob/service/client.go +++ b/sdk/storage/azblob/service/client.go @@ -40,7 +40,8 @@ type Client base.Client[generated.ServiceClient] // - cred - an Azure AD credential, typically obtained via the azidentity module // - options - client options; pass nil to accept the default values func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) { - authPolicy := shared.NewStorageChallengePolicy(cred) + audience := base.GetAudience((*base.ClientOptions)(options)) + authPolicy := shared.NewStorageChallengePolicy(cred, audience) conOptions := shared.GetClientOptions(options) plOpts := runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}} @@ -48,7 +49,7 @@ func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOp if err != nil { return nil, err } - return (*Client)(base.NewServiceClient(serviceURL, azClient, &cred)), nil + return (*Client)(base.NewServiceClient(serviceURL, azClient, &cred, (*base.ClientOptions)(conOptions))), nil } // NewClientWithNoCredential creates an instance of Client with the specified values. @@ -62,7 +63,7 @@ func NewClientWithNoCredential(serviceURL string, options *ClientOptions) (*Clie if err != nil { return nil, err } - return (*Client)(base.NewServiceClient(serviceURL, azClient, nil)), nil + return (*Client)(base.NewServiceClient(serviceURL, azClient, nil, (*base.ClientOptions)(conOptions))), nil } // NewClientWithSharedKeyCredential creates an instance of Client with the specified values. @@ -79,7 +80,7 @@ func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredenti return nil, err } - return (*Client)(base.NewServiceClient(serviceURL, azClient, cred)), nil + return (*Client)(base.NewServiceClient(serviceURL, azClient, cred, (*base.ClientOptions)(conOptions))), nil } // NewClientFromConnectionString creates an instance of Client with the specified values. @@ -136,6 +137,10 @@ func getGeneratedBlobClient(b *blob.Client) *generated.BlobClient { return base.InnerClient((*base.Client[generated.BlobClient])(b)) } +func (s *Client) getClientOptions() *base.ClientOptions { + return base.GetClientOptions((*base.Client[generated.ServiceClient])(s)) +} + // URL returns the URL endpoint used by the Client object. func (s *Client) URL() string { return s.generated().Endpoint() @@ -145,7 +150,7 @@ func (s *Client) URL() string { // this Client's URL. The new container.Client uses the same request policy pipeline as the Client. func (s *Client) NewContainerClient(containerName string) *container.Client { containerURL := runtime.JoinPaths(s.generated().Endpoint(), containerName) - return (*container.Client)(base.NewContainerClient(containerURL, s.generated().InternalClient().WithClientName(shared.ContainerClient), s.credential())) + return (*container.Client)(base.NewContainerClient(containerURL, s.generated().InternalClient().WithClientName(shared.ContainerClient), s.credential(), s.getClientOptions())) } // CreateContainer is a lifecycle method to creates a new container under the specified account. @@ -315,7 +320,7 @@ func (s *Client) NewBatchBuilder() (*BatchBuilder, error) { switch cred := s.credential().(type) { case *azcore.TokenCredential: - authPolicy = shared.NewStorageChallengePolicy(*cred) + authPolicy = shared.NewStorageChallengePolicy(*cred, base.GetAudience(s.getClientOptions())) case *SharedKeyCredential: authPolicy = exported.NewSharedKeyCredPolicy(cred) case nil: diff --git a/sdk/storage/azblob/service/client_test.go b/sdk/storage/azblob/service/client_test.go index 78c7b6c0ff88..21607acad17a 100644 --- a/sdk/storage/azblob/service/client_test.go +++ b/sdk/storage/azblob/service/client_test.go @@ -1809,3 +1809,79 @@ func (s *ServiceUnrecordedTestsSuite) TestServiceBlobBatchErrors() { _, err = svcClient.SubmitBatch(context.Background(), nil, nil) _require.Error(err) } + +func (s *ServiceRecordedTestsSuite) TestServiceClientDefaultAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + options := &service.ClientOptions{ + Audience: to.Ptr("https://storage.azure.com/"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + svcClientAudience, err := service.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + _, err = svcClientAudience.CreateContainer(context.Background(), containerName, nil) + _require.NoError(err) + + defer func() { + _, err = svcClientAudience.DeleteContainer(context.Background(), containerName, nil) + _require.NoError(err) + }() + + pager := svcClientAudience.NewListContainersPager(&service.ListContainersOptions{ + Prefix: &containerName, + }) + for pager.More() { + resp, err := pager.NextPage(context.Background()) + _require.NoError(err) + _require.Equal(len(resp.ContainerItems), 1) + _require.NotNil(resp.ContainerItems[0].Name) + _require.Equal(*resp.ContainerItems[0].Name, containerName) + } +} + +func (s *ServiceRecordedTestsSuite) TestServiceClientCustomAudience() { + _require := require.New(s.T()) + testName := s.T().Name() + + accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDefault) + _require.Greater(len(accountName), 0) + + cred, err := testcommon.GetGenericTokenCredential() + _require.NoError(err) + + options := &service.ClientOptions{ + Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + } + testcommon.SetClientOptions(s.T(), &options.ClientOptions) + svcClientAudience, err := service.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + _, err = svcClientAudience.CreateContainer(context.Background(), containerName, nil) + _require.NoError(err) + + defer func() { + _, err = svcClientAudience.DeleteContainer(context.Background(), containerName, nil) + _require.NoError(err) + }() + + pager := svcClientAudience.NewListContainersPager(&service.ListContainersOptions{ + Prefix: &containerName, + }) + for pager.More() { + resp, err := pager.NextPage(context.Background()) + _require.NoError(err) + _require.Equal(len(resp.ContainerItems), 1) + _require.NotNil(resp.ContainerItems[0].Name) + _require.Equal(*resp.ContainerItems[0].Name, containerName) + } +} From 034f89d61aa8b935dcaa133c1f3729c3fb76e0a0 Mon Sep 17 00:00:00 2001 From: Sourav Gupta <98318303+souravgupta-msft@users.noreply.github.com> Date: Thu, 28 Dec 2023 13:16:28 +0530 Subject: [PATCH 3/4] Updating readme (#22180) --- sdk/storage/azblob/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/storage/azblob/README.md b/sdk/storage/azblob/README.md index 905fb2675c68..1f51959fa3d6 100644 --- a/sdk/storage/azblob/README.md +++ b/sdk/storage/azblob/README.md @@ -1,6 +1,6 @@ # Azure Blob Storage module for Go -> Service Version: 2023-08-03 +> Service Version: 2023-11-03 Azure Blob Storage is Microsoft's object storage solution for the cloud. Blob Storage is optimized for storing massive amounts of unstructured data - data that does not adhere to a particular data model or From 76c6795c47128ff666689de3eae243ef120640d1 Mon Sep 17 00:00:00 2001 From: Sourav Gupta <98318303+souravgupta-msft@users.noreply.github.com> Date: Wed, 3 Jan 2024 13:09:58 +0530 Subject: [PATCH 4/4] Updating type of audience field (#22199) --- sdk/storage/azblob/appendblob/client_test.go | 4 ++-- sdk/storage/azblob/blob/client_test.go | 4 ++-- sdk/storage/azblob/blockblob/client_test.go | 4 ++-- sdk/storage/azblob/client_test.go | 5 ++--- sdk/storage/azblob/container/client_test.go | 4 ++-- sdk/storage/azblob/internal/base/clients.go | 6 +++--- sdk/storage/azblob/pageblob/client_test.go | 4 ++-- sdk/storage/azblob/service/client_test.go | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/sdk/storage/azblob/appendblob/client_test.go b/sdk/storage/azblob/appendblob/client_test.go index 25ba1642f759..ddcbb17e0280 100644 --- a/sdk/storage/azblob/appendblob/client_test.go +++ b/sdk/storage/azblob/appendblob/client_test.go @@ -3600,7 +3600,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobClientDefaultAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &appendblob.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) abClientAudience, err := appendblob.NewClient(blobURL, cred, options) @@ -3634,7 +3634,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobClientCustomAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &appendblob.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) abClientAudience, err := appendblob.NewClient(blobURL, cred, options) diff --git a/sdk/storage/azblob/blob/client_test.go b/sdk/storage/azblob/blob/client_test.go index b70626f948ec..61b90f213bd0 100644 --- a/sdk/storage/azblob/blob/client_test.go +++ b/sdk/storage/azblob/blob/client_test.go @@ -3704,7 +3704,7 @@ func (s *BlobRecordedTestsSuite) TestBlobClientDefaultAudience() { testcommon.CreateNewBlockBlob(context.Background(), _require, blobName, containerClient) options := &blob.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) blobClientAudience, err := blob.NewClient(blobURL, cred, options) @@ -3736,7 +3736,7 @@ func (s *BlobRecordedTestsSuite) TestBlobClientCustomAudience() { testcommon.CreateNewBlockBlob(context.Background(), _require, blobName, containerClient) options := &blob.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) blobClientAudience, err := blob.NewClient(blobURL, cred, options) diff --git a/sdk/storage/azblob/blockblob/client_test.go b/sdk/storage/azblob/blockblob/client_test.go index e8960f52fb3e..4de1cf4e8d94 100644 --- a/sdk/storage/azblob/blockblob/client_test.go +++ b/sdk/storage/azblob/blockblob/client_test.go @@ -5891,7 +5891,7 @@ func (s *BlockBlobRecordedTestsSuite) TestBlockBlobClientDefaultAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &blockblob.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) bbClientAudience, err := blockblob.NewClient(blobURL, cred, options) @@ -5929,7 +5929,7 @@ func (s *BlockBlobRecordedTestsSuite) TestBlockBlobClientCustomAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &blockblob.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) bbClientAudience, err := blockblob.NewClient(blobURL, cred, options) diff --git a/sdk/storage/azblob/client_test.go b/sdk/storage/azblob/client_test.go index 6625d5f039c5..5fd3563e1011 100644 --- a/sdk/storage/azblob/client_test.go +++ b/sdk/storage/azblob/client_test.go @@ -12,7 +12,6 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "hash/crc64" "io" "os" @@ -799,7 +798,7 @@ func (s *AZBlobRecordedTestsSuite) TestAzBlobClientDefaultAudience() { _require.NoError(err) options := &azblob.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) azClientAudience, err := azblob.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) @@ -837,7 +836,7 @@ func (s *AZBlobRecordedTestsSuite) TestAzBlobClientCustomAudience() { _require.NoError(err) options := &azblob.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) azClientAudience, err := azblob.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) diff --git a/sdk/storage/azblob/container/client_test.go b/sdk/storage/azblob/container/client_test.go index 35fb22bf894b..26a4b98e1a31 100644 --- a/sdk/storage/azblob/container/client_test.go +++ b/sdk/storage/azblob/container/client_test.go @@ -3472,7 +3472,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerClientDefaultAudience() { containerName := testcommon.GenerateContainerName(testName) options := &container.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) containerClientAudience, err := container.NewClient("https://"+accountName+".blob.core.windows.net/"+containerName, cred, options) @@ -3498,7 +3498,7 @@ func (s *ContainerRecordedTestsSuite) TestContainerClientCustomAudience() { containerName := testcommon.GenerateContainerName(testName) options := &container.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) containerClientAudience, err := container.NewClient("https://"+accountName+".blob.core.windows.net/"+containerName, cred, options) diff --git a/sdk/storage/azblob/internal/base/clients.go b/sdk/storage/azblob/internal/base/clients.go index e71f8643c2e1..073de855b617 100644 --- a/sdk/storage/azblob/internal/base/clients.go +++ b/sdk/storage/azblob/internal/base/clients.go @@ -21,7 +21,7 @@ type ClientOptions struct { // Audience to use when requesting tokens for Azure Active Directory authentication. // Only has an effect when credential is of type TokenCredential. The value could be // https://storage.azure.com/ (default) or https://.blob.core.windows.net. - Audience *string + Audience string } type Client[T any] struct { @@ -52,10 +52,10 @@ func GetClientOptions[T any](client *Client[T]) *ClientOptions { } func GetAudience(clOpts *ClientOptions) string { - if clOpts == nil || clOpts.Audience == nil { + if clOpts == nil || len(strings.TrimSpace(clOpts.Audience)) == 0 { return shared.TokenScope } else { - return strings.TrimRight(*clOpts.Audience, "/") + "/.default" + return strings.TrimRight(clOpts.Audience, "/") + "/.default" } } diff --git a/sdk/storage/azblob/pageblob/client_test.go b/sdk/storage/azblob/pageblob/client_test.go index ce36b5a6e1b7..6712f19be6dc 100644 --- a/sdk/storage/azblob/pageblob/client_test.go +++ b/sdk/storage/azblob/pageblob/client_test.go @@ -4951,7 +4951,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlobClientDefaultAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &pageblob.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) pbClientAudience, err := pageblob.NewClient(blobURL, cred, options) @@ -4985,7 +4985,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlobClientCustomAudience() { blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", accountName, containerName, blobName) options := &pageblob.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) pbClientAudience, err := pageblob.NewClient(blobURL, cred, options) diff --git a/sdk/storage/azblob/service/client_test.go b/sdk/storage/azblob/service/client_test.go index 21607acad17a..0449197a4013 100644 --- a/sdk/storage/azblob/service/client_test.go +++ b/sdk/storage/azblob/service/client_test.go @@ -1821,7 +1821,7 @@ func (s *ServiceRecordedTestsSuite) TestServiceClientDefaultAudience() { _require.NoError(err) options := &service.ClientOptions{ - Audience: to.Ptr("https://storage.azure.com/"), + Audience: "https://storage.azure.com/", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) svcClientAudience, err := service.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options) @@ -1859,7 +1859,7 @@ func (s *ServiceRecordedTestsSuite) TestServiceClientCustomAudience() { _require.NoError(err) options := &service.ClientOptions{ - Audience: to.Ptr("https://" + accountName + ".blob.core.windows.net"), + Audience: "https://" + accountName + ".blob.core.windows.net", } testcommon.SetClientOptions(s.T(), &options.ClientOptions) svcClientAudience, err := service.NewClient("https://"+accountName+".blob.core.windows.net/", cred, options)