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 all 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,39 @@
using Azure.Storage.Blobs;
using Microsoft.Extensions.Logging;
using OrchardCore.Environment.Shell.Removing;
using OrchardCore.Modules;

namespace OrchardCore.DataProtection.Azure;

/// <summary>
/// A tenant event that deletes data protection blobs from a container when a tenant is deleted.
/// </summary>
public class BlobModularTenantEvents : ModularTenantEvents
{
private readonly BlobOptions _blobOptions;
private readonly ILogger<BlobModularTenantEvents> _logger;

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>
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 @@ -39,6 +39,8 @@ public override void ConfigureServices(IServiceCollection services)
options.ContainerName,
options.BlobName);
});

services.AddScoped<IModularTenantEvents, BlobModularTenantEvents>();
}
else
{
Expand Down