-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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] Blobs - ability to traverse blob hierarchy upwards. #16437
Changes from 6 commits
0fef113
da2e882
35b8b7c
94e3fa2
df5768b
6f482ec
34821ef
cee4fd6
82e2301
7092967
180fcff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4103,6 +4103,35 @@ private async Task<Response> SetTagsInternal( | |
} | ||
} | ||
#endregion | ||
|
||
#region GetBlobContainerClientCore | ||
/// <summary> | ||
/// Create a new <see cref="BlobContainerClient"/> that pointing to this <see cref="BlobBaseClient"/>'s parent container. | ||
/// The new <see cref="BlockBlobClient"/> | ||
/// uses the same request policy pipeline as the | ||
/// <see cref="BlobBaseClient"/>. | ||
/// </summary> | ||
/// <returns>A new <see cref="BlobContainerClient"/> instance.</returns> | ||
protected internal virtual BlobContainerClient GetBlobContainerClientCore() | ||
{ | ||
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(Uri) | ||
{ | ||
// erase parameters unrelated to container | ||
BlobName = null, | ||
VersionId = null, | ||
Snapshot = null, | ||
}; | ||
|
||
return new BlobContainerClient( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as other comment. |
||
blobUriBuilder.ToUri(), | ||
Pipeline, | ||
Version, | ||
ClientDiagnostics, | ||
CustomerProvidedKey, | ||
ClientSideEncryption, | ||
EncryptionScope); | ||
} | ||
#endregion | ||
} | ||
|
||
/// <summary> | ||
|
@@ -4111,6 +4140,19 @@ private async Task<Response> SetTagsInternal( | |
/// </summary> | ||
public static partial class SpecializedBlobExtensions | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="BlobContainerClient"/> that pointing to this <see cref="BlobBaseClient"/>'s parent container. | ||
/// The new <see cref="BlockBlobClient"/> | ||
/// uses the same request policy pipeline as the | ||
/// <see cref="BlobBaseClient"/>. | ||
/// </summary> | ||
/// <param name="client">The <see cref="BlobBaseClient"/>.</param> | ||
/// <returns>A new <see cref="BlobContainerClient"/> instance.</returns> | ||
public static BlobContainerClient GetBlobContainerClient(this BlobBaseClient client) | ||
{ | ||
return client.GetBlobContainerClientCore(); | ||
} | ||
|
||
/// <summary> | ||
/// Create a new <see cref="BlobBaseClient"/> object by concatenating | ||
/// <paramref name="blobName"/> to the end of the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
using Azure.Storage.Sas; | ||
using Metadata = System.Collections.Generic.IDictionary<string, string>; | ||
|
||
#pragma warning disable SA1402 // File may only contain a single type | ||
|
||
namespace Azure.Storage.Blobs | ||
{ | ||
/// <summary> | ||
|
@@ -2875,5 +2877,58 @@ await GetBlobClient(blobName).DeleteIfExistsAsync( | |
.ConfigureAwait(false); | ||
|
||
#endregion DeleteBlob | ||
|
||
#region GetBlobServiceClientCore | ||
/// <summary> | ||
/// Create a new <see cref="BlobServiceClient"/> that pointing to this <see cref="BlobContainerClient"/>'s blob service. | ||
/// The new <see cref="BlobServiceClient"/> | ||
/// uses the same request policy pipeline as the | ||
/// <see cref="BlobContainerClient"/>. | ||
/// </summary> | ||
/// <returns>A new <see cref="BlobServiceClient"/> instance.</returns> | ||
protected internal virtual BlobServiceClient GetBlobServiceClientCore() | ||
{ | ||
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(Uri) | ||
{ | ||
// erase parameters unrelated to service | ||
BlobContainerName = null, | ||
BlobName = null, | ||
VersionId = null, | ||
Snapshot = null, | ||
}; | ||
|
||
return new BlobServiceClient( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to initialize a new client each time? Or would we have a persistent Client as a private property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can cache it since properties it's made don't change. |
||
blobUriBuilder.ToUri(), | ||
null, | ||
Version, | ||
ClientDiagnostics, | ||
CustomerProvidedKey, | ||
ClientSideEncryption, | ||
EncryptionScope, | ||
Pipeline); | ||
} | ||
#endregion | ||
} | ||
|
||
namespace Specialized | ||
{ | ||
/// <summary> | ||
/// Add easy to discover methods to <see cref="BlobContainerClient"/> for | ||
/// creating <see cref="BlobServiceClient"/> instances. | ||
/// </summary> | ||
public static partial class SpecializedBlobExtensions | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="BlobServiceClient"/> that pointing to this <see cref="BlobContainerClient"/>'s blob service. | ||
/// The new <see cref="BlobServiceClient"/> | ||
/// uses the same request policy pipeline as the | ||
/// <see cref="BlobContainerClient"/>. | ||
/// </summary> | ||
/// <returns>A new <see cref="BlobServiceClient"/> instance.</returns> | ||
public static BlobServiceClient GetBlobServiceClient(this BlobContainerClient client) | ||
{ | ||
return client.GetBlobServiceClientCore(); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost wonder if we want the name
Parent
in there likeGetParentBlobContainerClient
or something to indicate you're moving up? I could go either way since this is an advanced API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was itching to do this, but wanted to wait and see if somebody speaks up. I'll make that change.