Skip to content

Commit

Permalink
[Storage] [DataMovement] [API-Change] Changed BlobsStorageResourcePro…
Browse files Browse the repository at this point in the history
…vider.FromBlob() & BlobsStorageResourceProvider.FromContainer() to take a Uri over string (Azure#46318)

* initial commit

* Fixed changelog
  • Loading branch information
nickliu-msft authored Sep 26, 2024
1 parent 0bf8ab8 commit bb02d72
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 48 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/Azure.Storage.DataMovement.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Features Added

### Breaking Changes
- Changed `FromContainer(string containerUri, BlobStorageResourceContainerOptions options = default)` to `FromContainer(Uri containerUri, BlobStorageResourceContainerOptions options = default)`
- Changed `FromBlob(string blobUri, BlobStorageResourceOptions options = default)` to `FromBlob(Uri blobUri, BlobStorageResourceOptions options = default)`

### Bugs Fixed
- Fixed bug where using OAuth would not preserve source properties to destination properties.
Expand Down
8 changes: 4 additions & 4 deletions sdk/storage/Azure.Storage.DataMovement.Blobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ To create a blob `StorageResource`, use the methods `FromBlob` or `FromContainer

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

// Block blobs are the default if no options are specified
StorageResource blockBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-block",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-block"),
new BlockBlobStorageResourceOptions());
StorageResource pageBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-page",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-page"),
new PageBlobStorageResourceOptions());
StorageResource appendBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-append",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-append"),
new AppendBlobStorageResourceOptions());
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorag
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
protected override string ProviderId { get { throw null; } }
public Azure.Storage.DataMovement.StorageResource FromBlob(string blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
public 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(string containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions 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.DataTransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.DataTransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorag
public BlobsStorageResourceProvider(Azure.Storage.DataMovement.Blobs.BlobsStorageResourceProvider.GetTokenCredential getTokenCredentialAsync) { }
public BlobsStorageResourceProvider(Azure.Storage.StorageSharedKeyCredential credential) { }
protected override string ProviderId { get { throw null; } }
public Azure.Storage.DataMovement.StorageResource FromBlob(string blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromBlob(System.Uri blobUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.BlobContainerClient client, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.AppendBlobClient client, Azure.Storage.DataMovement.Blobs.AppendBlobStorageResourceOptions options = null) { throw null; }
public Azure.Storage.DataMovement.StorageResource FromClient(Azure.Storage.Blobs.Specialized.BlockBlobClient client, Azure.Storage.DataMovement.Blobs.BlockBlobStorageResourceOptions options = null) { throw null; }
public 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(string containerUri, Azure.Storage.DataMovement.Blobs.BlobStorageResourceContainerOptions 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.DataTransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
protected override System.Threading.Tasks.Task<Azure.Storage.DataMovement.StorageResource> FromSourceAsync(Azure.Storage.DataMovement.DataTransferProperties properties, System.Threading.CancellationToken cancellationToken) { throw null; }
public delegate Azure.AzureSasCredential GetAzureSasCredential(System.Uri uri, bool readOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public async Task ResourceConstructionDemonstration()
// Construct simple blob resources for data movement
#region Snippet:ResourceConstruction_Blobs
StorageResource container = blobs.FromContainer(
"http://myaccount.blob.core.windows.net/container");
new Uri("http://myaccount.blob.core.windows.net/container"));

// Block blobs are the default if no options are specified
StorageResource blockBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-block",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-block"),
new BlockBlobStorageResourceOptions());
StorageResource pageBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-page",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-page"),
new PageBlobStorageResourceOptions());
StorageResource appendBlob = blobs.FromBlob(
"http://myaccount.blob.core.windows.net/container/sample-blob-append",
new Uri("http://myaccount.blob.core.windows.net/container/sample-blob-append"),
new AppendBlobStorageResourceOptions());
#endregion
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task UploadSingle_ConnectionStringAsync()
LocalFilesStorageResourceProvider files = new();

// Get a reference to a destination blobs
string destinationBlobUri = container.GetBlockBlobClient("sample-blob").Uri.ToString();
Uri destinationBlobUri = container.GetBlockBlobClient("sample-blob").Uri;
TransferManager transferManager = new TransferManager(new TransferManagerOptions());

// Create simple transfer single blob upload job
Expand Down Expand Up @@ -255,7 +255,7 @@ public async Task DownloadSingle_SharedKeyAuthAsync()
{
// Get a reference to a source blobs and upload sample content to download
BlockBlobClient sourceBlobClient = container.GetBlockBlobClient("sample-blob");
string sourceBlobUri = sourceBlobClient.Uri.ToString();
Uri sourceBlobUri = sourceBlobClient.Uri;
BlockBlobClient sourceBlob2 = container.GetBlockBlobClient("sample-blob2");

using (FileStream stream = File.Open(originalPath, FileMode.Open))
Expand Down Expand Up @@ -352,7 +352,7 @@ public async Task UploadDirectory_SasAsync()

// Make a service request to verify we've successfully authenticated
await blobContainerClient.CreateIfNotExistsAsync();
string blobContainerUri = blobContainerClient.Uri.ToString();
Uri blobContainerUri = blobContainerClient.Uri;

// Prepare for upload
try
Expand Down Expand Up @@ -615,7 +615,7 @@ public async Task DownloadDirectory_EventHandler_ActiveDirectoryAuthAsync()

// Create a client that can authenticate with a connection string
BlobContainerClient blobContainerClient = service.GetBlobContainerClient(containerName);
string blobContainerUri = blobContainerClient.Uri.ToString();
Uri blobContainerUri = blobContainerClient.Uri;

// Make a service request to verify we've successfully authenticated
await blobContainerClient.CreateIfNotExistsAsync();
Expand Down Expand Up @@ -710,7 +710,7 @@ public async Task CopySingle_ConnectionStringAsync()
{
// Get a reference to a destination blobs
BlockBlobClient sourceBlockBlobClient = container.GetBlockBlobClient("sample-blob");
string sourceBlobUri = sourceBlockBlobClient.Uri.ToString();
Uri sourceBlobUri = sourceBlockBlobClient.Uri;

using (FileStream stream = File.Open(originalPath, FileMode.Open))
{
Expand All @@ -719,7 +719,7 @@ public async Task CopySingle_ConnectionStringAsync()
}

AppendBlobClient destinationAppendBlobClient = container.GetAppendBlobClient("sample-blob2");
string destinationBlobUri = destinationAppendBlobClient.Uri.ToString();
Uri destinationBlobUri = destinationAppendBlobClient.Uri;

// Upload file data
TransferManager transferManager = new TransferManager(default);
Expand Down Expand Up @@ -777,8 +777,8 @@ public async Task CopyDirectory()
// Create a client that can authenticate with a connection string
BlobServiceClient service = new BlobServiceClient(serviceUri, credential);
BlobContainerClient container = service.GetBlobContainerClient(containerName);
string sourceContainerUri = container.Uri.ToString();
string destinationContainerUri = container.Uri.ToString();
Uri sourceContainerUri = container.Uri;
Uri destinationContainerUri = container.Uri;

// Make a service request to verify we've successfully authenticated
await container.CreateIfNotExistsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ internal async Task<StorageResource> FromDestinationInternalHookAsync(
/// <returns>
/// The configured storage resource.
/// </returns>
public StorageResource FromContainer(string containerUri, BlobStorageResourceContainerOptions options = default)
public StorageResource FromContainer(Uri containerUri, BlobStorageResourceContainerOptions options = default)
{
BlobContainerClient client = _credentialType switch
{
CredentialType.None => new BlobContainerClient(new Uri(containerUri)),
CredentialType.SharedKey => new BlobContainerClient(new Uri(containerUri), _getStorageSharedKeyCredential(new Uri(containerUri), false)),
CredentialType.Token => new BlobContainerClient(new Uri(containerUri), _getTokenCredential(new Uri(containerUri), false)),
CredentialType.Sas => new BlobContainerClient(new Uri(containerUri), _getAzureSasCredential(new Uri(containerUri), false)),
CredentialType.None => new BlobContainerClient(containerUri),
CredentialType.SharedKey => new BlobContainerClient(containerUri, _getStorageSharedKeyCredential(containerUri, false)),
CredentialType.Token => new BlobContainerClient(containerUri, _getTokenCredential(containerUri, false)),
CredentialType.Sas => new BlobContainerClient(containerUri, _getAzureSasCredential(containerUri, false)),
_ => throw BadCredentialTypeException(_credentialType),
};
return new BlobStorageResourceContainer(client, options);
Expand Down Expand Up @@ -347,16 +347,16 @@ public StorageResource FromContainer(string containerUri, BlobStorageResourceCon
/// <returns>
/// The configured storage resource.
/// </returns>
public StorageResource FromBlob(string blobUri, BlobStorageResourceOptions options = default)
public StorageResource FromBlob(Uri blobUri, BlobStorageResourceOptions options = default)
{
if (options is BlockBlobStorageResourceOptions)
{
BlockBlobClient blockClient = _credentialType switch
{
CredentialType.None => new BlockBlobClient(new Uri(blobUri)),
CredentialType.SharedKey => new BlockBlobClient(new Uri(blobUri), _getStorageSharedKeyCredential(new Uri(blobUri), false)),
CredentialType.Token => new BlockBlobClient(new Uri(blobUri), _getTokenCredential(new Uri(blobUri), false)),
CredentialType.Sas => new BlockBlobClient(new Uri(blobUri), _getAzureSasCredential(new Uri(blobUri), false)),
CredentialType.None => new BlockBlobClient(blobUri),
CredentialType.SharedKey => new BlockBlobClient(blobUri, _getStorageSharedKeyCredential(blobUri, false)),
CredentialType.Token => new BlockBlobClient(blobUri, _getTokenCredential(blobUri, false)),
CredentialType.Sas => new BlockBlobClient(blobUri, _getAzureSasCredential(blobUri, false)),
_ => throw BadCredentialTypeException(_credentialType),
};
return new BlockBlobStorageResource(blockClient, options as BlockBlobStorageResourceOptions);
Expand All @@ -365,10 +365,10 @@ public StorageResource FromBlob(string blobUri, BlobStorageResourceOptions optio
{
PageBlobClient pageClient = _credentialType switch
{
CredentialType.None => new PageBlobClient(new Uri(blobUri)),
CredentialType.SharedKey => new PageBlobClient(new Uri(blobUri), _getStorageSharedKeyCredential(new Uri(blobUri), false)),
CredentialType.Token => new PageBlobClient(new Uri(blobUri), _getTokenCredential(new Uri(blobUri), false)),
CredentialType.Sas => new PageBlobClient(new Uri(blobUri), _getAzureSasCredential(new Uri(blobUri), false)),
CredentialType.None => new PageBlobClient(blobUri),
CredentialType.SharedKey => new PageBlobClient(blobUri, _getStorageSharedKeyCredential(blobUri, false)),
CredentialType.Token => new PageBlobClient(blobUri, _getTokenCredential(blobUri, false)),
CredentialType.Sas => new PageBlobClient(blobUri, _getAzureSasCredential(blobUri, false)),
_ => throw BadCredentialTypeException(_credentialType),
};
return new PageBlobStorageResource(pageClient, options as PageBlobStorageResourceOptions);
Expand All @@ -377,20 +377,20 @@ public StorageResource FromBlob(string blobUri, BlobStorageResourceOptions optio
{
AppendBlobClient appendClient = _credentialType switch
{
CredentialType.None => new AppendBlobClient(new Uri(blobUri)),
CredentialType.SharedKey => new AppendBlobClient(new Uri(blobUri), _getStorageSharedKeyCredential(new Uri(blobUri), false)),
CredentialType.Token => new AppendBlobClient(new Uri(blobUri), _getTokenCredential(new Uri(blobUri), false)),
CredentialType.Sas => new AppendBlobClient(new Uri(blobUri), _getAzureSasCredential(new Uri(blobUri), false)),
CredentialType.None => new AppendBlobClient(blobUri),
CredentialType.SharedKey => new AppendBlobClient(blobUri, _getStorageSharedKeyCredential(blobUri, false)),
CredentialType.Token => new AppendBlobClient(blobUri, _getTokenCredential(blobUri, false)),
CredentialType.Sas => new AppendBlobClient(blobUri, _getAzureSasCredential(blobUri, false)),
_ => throw BadCredentialTypeException(_credentialType),
};
return new AppendBlobStorageResource(appendClient, options as AppendBlobStorageResourceOptions);
}
BlockBlobClient client = _credentialType switch
{
CredentialType.None => new BlockBlobClient(new Uri(blobUri)),
CredentialType.SharedKey => new BlockBlobClient(new Uri(blobUri), _getStorageSharedKeyCredential(new Uri(blobUri), false)),
CredentialType.Token => new BlockBlobClient(new Uri(blobUri), _getTokenCredential(new Uri(blobUri), false)),
CredentialType.Sas => new BlockBlobClient(new Uri(blobUri), _getAzureSasCredential(new Uri(blobUri), false)),
CredentialType.None => new BlockBlobClient(blobUri),
CredentialType.SharedKey => new BlockBlobClient(blobUri, _getStorageSharedKeyCredential(blobUri, false)),
CredentialType.Token => new BlockBlobClient(blobUri, _getTokenCredential(blobUri, false)),
CredentialType.Sas => new BlockBlobClient(blobUri, _getAzureSasCredential(blobUri, false)),
_ => throw BadCredentialTypeException(_credentialType),
};
return new BlockBlobStorageResource(client, options as BlockBlobStorageResourceOptions);
Expand Down
Loading

0 comments on commit bb02d72

Please sign in to comment.