-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove data protection keys from Azure blob storage when deleting ten…
…ant (#16839)
- Loading branch information
1 parent
0d57489
commit 8de0e71
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/OrchardCore.Modules/OrchardCore.DataProtection.Azure/BlobModularTenantEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters