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

[Storage][DataMovement] Refactor resource provider credential callbacks #47984

Merged
merged 12 commits into from
Jan 27, 2025
9 changes: 7 additions & 2 deletions sdk/storage/Azure.Storage.DataMovement.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
- Renamed `BlobStorageResourceContainerOptions.BlobDirectoryPrefix` to `BlobPrefix`
- Changed `BlobContainerClient.StartUploadDirectoryAsync` to `BlobContainerClient.UploadDirectoryAsync` and added a required `waitUntil` parameter.
- Changed `BlobContainerClient.StartDownloadToDirectoryAsync` to `BlobContainerClient.DownloadToDirectoryAsync` and added a required `waitUntil` parameter.
- Removed `BlobsStorageResourceProvider()` empty default constructor
- Changed `BlobsStorageResourceProvider.FromClient` methods to `static` method
- Several refactors to `BlobsStorageResourceProvider`:
- Removed nested delegates `GetStorageSharedKeyCredential`, `GetTokenCredential`, and `GetAzureSasCredential`.
- Removed default constructor.
- Removed constructor overload for `GetTokenCredential` entirely.
- Changed constructor overloads for `GetStorageSharedKeyCredential` and `GetAzureSasCredential` to use `Func`. These callbacks are also now async, returning a `ValueTask`, and the `readOnly` parameter was removed.
- Changed `FromBlob` and `FromContainer` to async, returning a `ValueTask`, and renamed to `FromBlobAsync` and `FromContainerAsync` respectively.
- Changed `FromClient` methods to `static` methods.

### Bugs Fixed

Expand Down
24 changes: 12 additions & 12 deletions sdk/storage/Azure.Storage.DataMovement.Blobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ BlobsStorageResourceProvider blobs = new(tokenCredential);
To create a blob `StorageResource`, use the methods `FromBlob` or `FromContainer`.

```C# Snippet:ResourceConstruction_Blobs
StorageResource container = blobs.FromContainer(
StorageResource container = await blobs.FromContainerAsync(
new Uri("https://myaccount.blob.core.windows.net/container"));

// Block blobs are the default if no options are specified
StorageResource blockBlob = blobs.FromBlob(
StorageResource blockBlob = await blobs.FromBlobAsync(
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-block"),
new BlockBlobStorageResourceOptions());
StorageResource pageBlob = blobs.FromBlob(
StorageResource pageBlob = await blobs.FromBlobAsync(
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-page"),
new PageBlobStorageResourceOptions());
StorageResource appendBlob = blobs.FromBlob(
StorageResource appendBlob = await blobs.FromBlobAsync(
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-append"),
new AppendBlobStorageResourceOptions());
```
Expand Down Expand Up @@ -154,7 +154,7 @@ Upload a block blob.
```C# Snippet:SimpleBlobUpload
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: LocalFilesStorageResourceProvider.FromFile(sourceLocalPath),
destinationResource: blobs.FromBlob(destinationBlobUri));
destinationResource: await blobs.FromBlobAsync(destinationBlobUri));
await transferOperation.WaitForCompletionAsync();
```

Expand All @@ -163,7 +163,7 @@ Upload a directory as a specific blob type.
```C# Snippet:SimpleDirectoryUpload
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: LocalFilesStorageResourceProvider.FromDirectory(sourcePath),
destinationResource: blobs.FromContainer(
destinationResource: await blobs.FromContainerAsync(
blobContainerUri,
new BlobStorageResourceContainerOptions()
{
Expand All @@ -181,7 +181,7 @@ Download a blob.

```C# Snippet:SimpleBlockBlobDownload
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: blobs.FromBlob(sourceBlobUri),
sourceResource: await blobs.FromBlobAsync(sourceBlobUri),
destinationResource: LocalFilesStorageResourceProvider.FromFile(downloadPath));
await transferOperation.WaitForCompletionAsync();
```
Expand All @@ -190,7 +190,7 @@ Download a container which may contain a mix of blob types.

```C# Snippet:SimpleDirectoryDownload_Blob
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: blobs.FromContainer(
sourceResource: await blobs.FromContainerAsync(
blobContainerUri,
new BlobStorageResourceContainerOptions()
{
Expand All @@ -208,22 +208,22 @@ Copy a single blob. Note the destination blob is an append blob, regardless of t

```C# Snippet:s2sCopyBlob
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: blobs.FromBlob(sourceBlobUri),
destinationResource: blobs.FromBlob(destinationBlobUri, new AppendBlobStorageResourceOptions()));
sourceResource: await blobs.FromBlobAsync(sourceBlobUri),
destinationResource: await blobs.FromBlobAsync(destinationBlobUri, new AppendBlobStorageResourceOptions()));
await transferOperation.WaitForCompletionAsync();
```

Copy a blob container.

```C# Snippet:s2sCopyBlobContainer
TransferOperation transferOperation = await transferManager.StartTransferAsync(
sourceResource: blobs.FromContainer(
sourceResource: await blobs.FromContainerAsync(
sourceContainerUri,
new BlobStorageResourceContainerOptions()
{
BlobPrefix = sourceDirectoryName
}),
destinationResource: blobs.FromContainer(
destinationResource: await blobs.FromContainerAsync(
destinationContainerUri,
new BlobStorageResourceContainerOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
{
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
protected override string ProviderId { get { throw null; } }
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromBlobAsync(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromContainerAsync(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public partial class BlobStorageResourceContainerOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
{
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
protected override string ProviderId { get { throw null; } }
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromBlobAsync(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromContainerAsync(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public partial class BlobStorageResourceContainerOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
{
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
protected override string ProviderId { get { throw null; } }
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromBlobAsync(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
public System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromContainerAsync(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public partial class BlobStorageResourceContainerOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public override void Run(CancellationToken cancellationToken)

public override async Task RunAsync(CancellationToken cancellationToken)
{
StorageResource source = BlobResourceProvider.FromContainer(_sourceContainer.Uri);
StorageResource destination = BlobResourceProvider.FromContainer(_destinationContainer.Uri);
StorageResource source = await BlobResourceProvider.FromContainerAsync(_sourceContainer.Uri);
StorageResource destination = await BlobResourceProvider.FromContainerAsync(_destinationContainer.Uri);

await RunAndVerifyTransferAsync(source, destination, cancellationToken);
}
Expand Down
Loading
Loading