Skip to content

Commit 1a4a511

Browse files
[Storage][DataMovement] Refactor resource provider credential callbacks (Azure#47984)
1 parent 98c4db7 commit 1a4a511

26 files changed

+273
-337
lines changed

sdk/storage/Azure.Storage.DataMovement.Blobs/CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
- Renamed `BlobStorageResourceContainerOptions.BlobDirectoryPrefix` to `BlobPrefix`
1717
- Changed `BlobContainerClient.StartUploadDirectoryAsync` to `BlobContainerClient.UploadDirectoryAsync` and added a required `waitUntil` parameter.
1818
- Changed `BlobContainerClient.StartDownloadToDirectoryAsync` to `BlobContainerClient.DownloadToDirectoryAsync` and added a required `waitUntil` parameter.
19-
- Removed `BlobsStorageResourceProvider()` empty default constructor
20-
- Changed `BlobsStorageResourceProvider.FromClient` methods to `static` method
19+
- Several refactors to `BlobsStorageResourceProvider`:
20+
- Removed nested delegates `GetStorageSharedKeyCredential`, `GetTokenCredential`, and `GetAzureSasCredential`.
21+
- Removed default constructor.
22+
- Removed constructor overload for `GetTokenCredential` entirely.
23+
- 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.
24+
- Changed `FromBlob` and `FromContainer` to async, returning a `ValueTask`, and renamed to `FromBlobAsync` and `FromContainerAsync` respectively.
25+
- Changed `FromClient` methods to `static` methods.
2126

2227
### Bugs Fixed
2328

sdk/storage/Azure.Storage.DataMovement.Blobs/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ BlobsStorageResourceProvider blobs = new(tokenCredential);
9595
To create a blob `StorageResource`, use the methods `FromBlob` or `FromContainer`.
9696

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

101101
// Block blobs are the default if no options are specified
102-
StorageResource blockBlob = blobs.FromBlob(
102+
StorageResource blockBlob = await blobs.FromBlobAsync(
103103
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-block"),
104104
new BlockBlobStorageResourceOptions());
105-
StorageResource pageBlob = blobs.FromBlob(
105+
StorageResource pageBlob = await blobs.FromBlobAsync(
106106
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-page"),
107107
new PageBlobStorageResourceOptions());
108-
StorageResource appendBlob = blobs.FromBlob(
108+
StorageResource appendBlob = await blobs.FromBlobAsync(
109109
new Uri("https://myaccount.blob.core.windows.net/container/sample-blob-append"),
110110
new AppendBlobStorageResourceOptions());
111111
```
@@ -154,7 +154,7 @@ Upload a block blob.
154154
```C# Snippet:SimpleBlobUpload
155155
TransferOperation transferOperation = await transferManager.StartTransferAsync(
156156
sourceResource: LocalFilesStorageResourceProvider.FromFile(sourceLocalPath),
157-
destinationResource: blobs.FromBlob(destinationBlobUri));
157+
destinationResource: await blobs.FromBlobAsync(destinationBlobUri));
158158
await transferOperation.WaitForCompletionAsync();
159159
```
160160

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

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

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

209209
```C# Snippet:s2sCopyBlob
210210
TransferOperation transferOperation = await transferManager.StartTransferAsync(
211-
sourceResource: blobs.FromBlob(sourceBlobUri),
212-
destinationResource: blobs.FromBlob(destinationBlobUri, new AppendBlobStorageResourceOptions()));
211+
sourceResource: await blobs.FromBlobAsync(sourceBlobUri),
212+
destinationResource: await blobs.FromBlobAsync(destinationBlobUri, new AppendBlobStorageResourceOptions()));
213213
await transferOperation.WaitForCompletionAsync();
214214
```
215215

216216
Copy a blob container.
217217

218218
```C# Snippet:s2sCopyBlobContainer
219219
TransferOperation transferOperation = await transferManager.StartTransferAsync(
220-
sourceResource: blobs.FromContainer(
220+
sourceResource: await blobs.FromContainerAsync(
221221
sourceContainerUri,
222222
new BlobStorageResourceContainerOptions()
223223
{
224224
BlobPrefix = sourceDirectoryName
225225
}),
226-
destinationResource: blobs.FromContainer(
226+
destinationResource: await blobs.FromContainerAsync(
227227
destinationContainerUri,
228228
new BlobStorageResourceContainerOptions()
229229
{

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.net6.0.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
2626
{
2727
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
2828
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
29-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
30-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
31-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
3229
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
30+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
31+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
3332
protected override string ProviderId { get { throw null; } }
34-
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
33+
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; }
3534
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
3635
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
3736
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
3837
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
39-
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
40-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
41-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
42-
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
43-
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
44-
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
38+
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; }
39+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
40+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
4541
}
4642
public partial class BlobStorageResourceContainerOptions
4743
{

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.net8.0.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
2626
{
2727
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
2828
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
29-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
30-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
31-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
3229
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
30+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
31+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
3332
protected override string ProviderId { get { throw null; } }
34-
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
33+
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; }
3534
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
3635
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
3736
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
3837
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
39-
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
40-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
41-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
42-
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
43-
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
44-
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
38+
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; }
39+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
40+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
4541
}
4642
public partial class BlobStorageResourceContainerOptions
4743
{

sdk/storage/Azure.Storage.DataMovement.Blobs/api/Azure.Storage.DataMovement.Blobs.netstandard2.0.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ public partial class BlobsStorageResourceProvider : Azure.Storage.DataMovement.S
2626
{
2727
public BlobsStorageResourceProvider(Azure.AzureSasCredential credential) { }
2828
public BlobsStorageResourceProvider(Azure.Core.TokenCredential credential) { }
29-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetAzureSasCredential getAzureSasCredentialAsync) { }
30-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetStorageSharedKeyCredential getStorageSharedKeyCredentialAsync) { }
31-
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
3229
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
30+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.AzureSasCredential>> getAzureSasCredentialAsync) { }
31+
public BlobsStorageResourceProvider(System.Func<System.Uri, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<Azure.Storage.StorageSharedKeyCredential>> getStorageSharedKeyCredentialAsync) { }
3332
protected override string ProviderId { get { throw null; } }
34-
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
33+
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; }
3534
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
3635
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
3736
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
3837
public static Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.PageBlobClient client, Azure.Storage.DataMovement.Blobs.PageBlobStorageResourceOptions options = null) { throw null; }
39-
public Azure.Storage.DataMovement.StorageResource FromContainer(System.Uri containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
40-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
41-
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
42-
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
43-
public delegate Azure.Storage.StorageSharedKeyCredential GetStorageSharedKeyCredential(System.Uri uri, bool readOnly);
44-
public delegate Azure.Core.TokenCredential GetTokenCredential(System.Uri uri, bool readOnly);
38+
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; }
39+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromDestinationAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
40+
protected override System.Threading.Tasks.ValueTask<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.TransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
4541
}
4642
public partial class BlobStorageResourceContainerOptions
4743
{

sdk/storage/Azure.Storage.DataMovement.Blobs/perf/Azure.Storage.DataMovement.Blobs.Perf/Scenarios/CopyDirectory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public override void Run(CancellationToken cancellationToken)
4444

4545
public override async Task RunAsync(CancellationToken cancellationToken)
4646
{
47-
StorageResource source = BlobResourceProvider.FromContainer(_sourceContainer.Uri);
48-
StorageResource destination = BlobResourceProvider.FromContainer(_destinationContainer.Uri);
47+
StorageResource source = await BlobResourceProvider.FromContainerAsync(_sourceContainer.Uri);
48+
StorageResource destination = await BlobResourceProvider.FromContainerAsync(_destinationContainer.Uri);
4949

5050
await RunAndVerifyTransferAsync(source, destination, cancellationToken);
5151
}

0 commit comments

Comments
 (0)