Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to be able to CanGenerateSas and GenerateSas from clients generated GetClient #17232

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.8.0-beta.1 (Unreleased)

- Fixed bug where BlobContainerClient.GetBlobClient(), BlobContainerClient.GetParentServiceClient(), BlobServiceClient.GetBlobContainerClient(), BlobBaseClient.WithClientSideEncryptionOptions(), BlobBaseClient.GetParentBlobContainerClient(), BlobBaseClient.WithSnapshot() and BlobBaseClient.WithVersion() created clients that could not generate a SAS from clients that could generate a SAS

## 12.7.0 (2020-11-10)
- Includes all features from 12.7.0-preview.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public BlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredential c
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(string path, Azure.Storage.Blobs.Models.BlobUploadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(string path, bool overwrite = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContentInfo>> UploadAsync(string path, System.Threading.CancellationToken cancellationToken) { throw null; }
protected internal virtual Azure.Storage.Blobs.BlobClient WithClientSideEncryptionOptionsCore(Azure.Storage.ClientSideEncryptionOptions clientSideEncryptionOptions) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithSnapshot(string snapshot) { throw null; }
public new Azure.Storage.Blobs.BlobClient WithVersion(string versionId) { throw null; }
}
Expand Down Expand Up @@ -93,6 +94,7 @@ public BlobContainerClient(System.Uri blobContainerUri, Azure.Storage.StorageSha
public virtual Azure.Response<Azure.Storage.Blobs.Models.BlobContainerAccessPolicy> GetAccessPolicy(Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Blobs.Models.BlobContainerAccessPolicy>> GetAccessPolicyAsync(Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
protected internal virtual Azure.Storage.Blobs.Specialized.AppendBlobClient GetAppendBlobClientCore(string blobName) { throw null; }
protected internal virtual Azure.Storage.Blobs.Specialized.BlobBaseClient GetBlobBaseClientCore(string blobName) { throw null; }
public virtual Azure.Storage.Blobs.BlobClient GetBlobClient(string blobName) { throw null; }
protected internal virtual Azure.Storage.Blobs.Specialized.BlobLeaseClient GetBlobLeaseClientCore(string leaseId) { throw null; }
public virtual Azure.Pageable<Azure.Storage.Blobs.Models.BlobItem> GetBlobs(Azure.Storage.Blobs.Models.BlobTraits traits = Azure.Storage.Blobs.Models.BlobTraits.None, Azure.Storage.Blobs.Models.BlobStates states = Azure.Storage.Blobs.Models.BlobStates.None, string prefix = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
7 changes: 7 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,24 @@ public AppendBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptio
/// <param name="version">
/// The version of the service to use when sending requests.
/// </param>
/// <param name="storageSharedKeyCredential">
/// The shared key credential used to sign requests.
/// </param>
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
/// <param name="encryptionScope">Encryption scope.</param>
internal AppendBlobClient(
Uri blobUri,
HttpPipeline pipeline,
StorageSharedKeyCredential storageSharedKeyCredential,
BlobClientOptions.ServiceVersion version,
ClientDiagnostics clientDiagnostics,
CustomerProvidedKey? customerProvidedKey,
string encryptionScope)
: base(
blobUri,
pipeline,
storageSharedKeyCredential,
version,
clientDiagnostics,
customerProvidedKey,
Expand Down Expand Up @@ -244,6 +249,7 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options)
return new AppendBlobClient(
blobUriBuilder.ToUri(),
Pipeline,
SharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down Expand Up @@ -272,6 +278,7 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options)
return new AppendBlobClient(
blobUriBuilder.ToUri(),
Pipeline,
SharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down
49 changes: 30 additions & 19 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ public virtual string Name
}

/// <summary>
/// The <see cref="StorageSharedKeyCredential"/> used to authenticate and generate SAS
/// The <see cref="StorageSharedKeyCredential"/> used to authenticate and generate SAS.
/// </summary>
private StorageSharedKeyCredential _storageSharedKeyCredential;
private readonly StorageSharedKeyCredential _storageSharedKeyCredential;

/// <summary>
/// Gets the The <see cref="StorageSharedKeyCredential"/> used to authenticate and generate SAS.
/// </summary>
internal virtual StorageSharedKeyCredential SharedKeyCredential => _storageSharedKeyCredential;

/// <summary>
/// Determines whether the client is able to generate a SAS.
Expand Down Expand Up @@ -388,21 +393,38 @@ internal BlobBaseClient(
/// <param name="version">
/// The version of the service to use when sending requests.
/// </param>
/// <param name="storageSharedKeyCredential">
/// The shared key credential used to sign requests.
/// </param>
/// <param name="clientDiagnostics">Client diagnostics.</param>
/// <param name="customerProvidedKey">Customer provided key.</param>
/// <param name="clientSideEncryption">Client-side encryption options.</param>
/// <param name="encryptionScope">Encryption scope.</param>
internal BlobBaseClient(
Uri blobUri,
HttpPipeline pipeline,
StorageSharedKeyCredential storageSharedKeyCredential,
BlobClientOptions.ServiceVersion version,
ClientDiagnostics clientDiagnostics,
CustomerProvidedKey? customerProvidedKey,
ClientSideEncryptionOptions clientSideEncryption,
string encryptionScope)
{
_uri = blobUri;
if (!string.IsNullOrEmpty(blobUri.Query))
{
UriQueryParamsCollection queryParamsCollection = new UriQueryParamsCollection(blobUri.Query);
if (queryParamsCollection.ContainsKey(Constants.SnapshotParameterName))
{
_snapshot = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.SnapshotParameterName);
}
if (queryParamsCollection.ContainsKey(Constants.VersionIdParameterName))
{
_blobVersionId = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.VersionIdParameterName);
}
}
_pipeline = pipeline;
_storageSharedKeyCredential = storageSharedKeyCredential;
_version = version;
_clientDiagnostics = clientDiagnostics;
_customerProvidedKey = customerProvidedKey;
Expand Down Expand Up @@ -448,6 +470,7 @@ protected virtual BlobBaseClient WithSnapshotCore(string snapshot)
return new BlobBaseClient(
blobUriBuilder.ToUri(),
Pipeline,
_storageSharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down Expand Up @@ -487,6 +510,7 @@ private protected virtual BlobBaseClient WithVersionCore(string versionId)
return new BlobBaseClient(
blobUriBuilder.ToUri(),
Pipeline,
_storageSharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down Expand Up @@ -1363,7 +1387,7 @@ internal async Task<Response> StagedDownloadAsync(
bool async = true,
CancellationToken cancellationToken = default)
{
var client = new BlobBaseClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, ClientSideEncryption, EncryptionScope);
var client = new BlobBaseClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, ClientSideEncryption, EncryptionScope);

PartitionedDownloader downloader = new PartitionedDownloader(client, transferOptions);

Expand Down Expand Up @@ -4273,6 +4297,7 @@ protected internal virtual BlobContainerClient GetParentBlobContainerClientCore(
_parentBlobContainerClient = new BlobContainerClient(
blobUriBuilder.ToUri(),
Pipeline,
_storageSharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down Expand Up @@ -4317,14 +4342,7 @@ public static BlobContainerClient GetParentBlobContainerClient(this BlobBaseClie
public static BlobBaseClient GetBlobBaseClient(
this BlobContainerClient client,
string blobName) =>
new BlobBaseClient(
client.Uri.AppendToPath(blobName),
client.Pipeline,
client.Version,
client.ClientDiagnostics,
client.CustomerProvidedKey,
client.ClientSideEncryption,
client.EncryptionScope);
client.GetBlobBaseClientCore(blobName);

/// <summary>
/// Creates a new instance of the <see cref="BlobClient"/> class, maintaining all the same
Expand All @@ -4334,13 +4352,6 @@ public static BlobBaseClient GetBlobBaseClient(
/// <param name="clientSideEncryptionOptions">New encryption options. Setting this to <code>default</code> will clear client-side encryption.</param>
/// <returns>New instance with provided options and same internals otherwise.</returns>
public static BlobClient WithClientSideEncryptionOptions(this BlobClient client, ClientSideEncryptionOptions clientSideEncryptionOptions)
=> new BlobClient(
client.Uri,
client.Pipeline,
client.Version,
client.ClientDiagnostics,
client.CustomerProvidedKey,
clientSideEncryptionOptions,
client.EncryptionScope);
=> client.WithClientSideEncryptionOptionsCore(clientSideEncryptionOptions);
}
}
31 changes: 28 additions & 3 deletions sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions opt
/// <param name="pipeline">
/// The transport pipeline used to send every request.
/// </param>
/// <param name="storageSharedKeyCredential">
/// The shared key credential used to sign requests.
/// </param>
/// <param name="version">
/// The version of the service to use when sending requests.
/// </param>
Expand All @@ -176,12 +179,13 @@ public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions opt
internal BlobClient(
Uri blobUri,
HttpPipeline pipeline,
StorageSharedKeyCredential storageSharedKeyCredential,
BlobClientOptions.ServiceVersion version,
ClientDiagnostics clientDiagnostics,
CustomerProvidedKey? customerProvidedKey,
ClientSideEncryptionOptions clientSideEncryption,
string encryptionScope)
: base(blobUri, pipeline, version, clientDiagnostics, customerProvidedKey, clientSideEncryption, encryptionScope)
: base(blobUri, pipeline, storageSharedKeyCredential, version, clientDiagnostics, customerProvidedKey, clientSideEncryption, encryptionScope)
{
}
#endregion ctors
Expand Down Expand Up @@ -209,6 +213,7 @@ internal BlobClient(
return new BlobClient(
blobUriBuilder.ToUri(),
Pipeline,
SharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
Expand Down Expand Up @@ -238,13 +243,33 @@ internal BlobClient(
return new BlobClient(
blobUriBuilder.ToUri(),
Pipeline,
SharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
ClientSideEncryption,
EncryptionScope);
}

/// <summary>
/// Creates a new instance of the <see cref="BlobClient"/> class, maintaining all the same
/// internals but specifying new <see cref="ClientSideEncryptionOptions"/>.
/// </summary>
/// <param name="clientSideEncryptionOptions">New encryption options. Setting this to <code>default</code> will clear client-side encryption.</param>
/// <returns>New instance with provided options and same internals otherwise.</returns>
protected internal virtual BlobClient WithClientSideEncryptionOptionsCore(ClientSideEncryptionOptions clientSideEncryptionOptions)
{
return new BlobClient(
Uri,
Pipeline,
SharedKeyCredential,
Version,
ClientDiagnostics,
CustomerProvidedKey,
clientSideEncryptionOptions,
EncryptionScope);
}

#region Upload
/// <summary>
/// The <see cref="Upload(Stream)"/> operation creates a new block blob
Expand Down Expand Up @@ -1231,7 +1256,7 @@ internal async Task<Response<BlobContentInfo>> StagedUploadInternal(
.ClientSideEncryptInternal(content, options.Metadata, async, cancellationToken).ConfigureAwait(false);
}

var client = new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope);
var client = new BlockBlobClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope);

var uploader = GetPartitionedUploader(
transferOptions: options?.TransferOptions ?? default,
Expand Down Expand Up @@ -1316,7 +1341,7 @@ internal PartitionedUploader<BlobUploadOptions, BlobContentInfo> GetPartitionedU
StorageTransferOptions transferOptions,
ArrayPool<byte> arrayPool = null,
string operationName = null)
=> new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope)
=> new BlockBlobClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope)
.GetPartitionedUploader(transferOptions, arrayPool, operationName);
}
}
Loading