Skip to content

Commit

Permalink
Remove data protection keys from Azure blob storage when deleting ten…
Browse files Browse the repository at this point in the history
…ant (#16839)
  • Loading branch information
microposmp authored Oct 8, 2024
1 parent 0d57489 commit 8de0e71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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(
_blobOptions.ConnectionString,
_blobOptions.ContainerName,
_blobOptions.BlobName);

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

await blobClient.DeleteIfExistsAsync();
}
}
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

0 comments on commit 8de0e71

Please sign in to comment.