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

Remove data protection keys from Azure blob storage when deleting tenant #16839

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Azure.Storage.Blobs;
using Microsoft.Extensions.Logging;
using OrchardCore.Environment.Shell.Removing;
using OrchardCore.Modules;

namespace OrchardCore.DataProtection.Azure;

/// <summary>
/// Represents tenant event that deletes data protection blob from a container when a tenant is deleted.
Piedone marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public class BlobModularTenantEvents : ModularTenantEvents
{
private readonly BlobOptions _blobOptions;
private readonly ILogger<BlobModularTenantEvents> _logger;

/// <summary>
/// Creates a new instance of the <see cref="BlobModularTenantEvents"/>.
/// </summary>
/// <param name="blobOptions">The <see cref="BlobOptions"/></param>
/// <param name="logger">The <see cref="ILogger"/></param>
Piedone marked this conversation as resolved.
Show resolved Hide resolved
public BlobModularTenantEvents(
BlobOptions blobOptions,
ILogger<BlobModularTenantEvents> logger)
{
_blobOptions = blobOptions;
_logger = logger;
}

/// <summary>
/// Removes the data protection blob from the container when a tenant is deleted.
/// </summary>
/// <param name="context">The <see cref="ShellRemovingContext"/></param>
/// <returns></returns>
Piedone marked this conversation as resolved.
Show resolved Hide resolved
public async override Task RemovingAsync(ShellRemovingContext context)
{
var blobClient = new BlobClient(
Piedone marked this conversation as resolved.
Show resolved Hide resolved
_blobOptions.ConnectionString,
_blobOptions.ContainerName,
_blobOptions.BlobName);

_logger.LogDebug("Deleting blob '{BlobName}' from container '{ContainerName}'.", _blobOptions.BlobName, _blobOptions.ContainerName);

await blobClient.DeleteIfExistsAsync();
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public override void ConfigureServices(IServiceCollection services)
{
_logger.LogCritical("No connection string was supplied for OrchardCore.DataProtection.Azure. Ensure that an application setting containing a valid Azure Storage connection string is available at `Modules:OrchardCore.DataProtection.Azure:ConnectionString`.");
}

services.AddSingleton<IModularTenantEvents, BlobModularTenantEvents>();
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}
}