OPC # 0001: Extract Clarity into standalone repo
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Minio;
|
||||
using Minio.DataModel.Args;
|
||||
|
||||
namespace Clarity.Server.Extensions;
|
||||
|
||||
public static class MinioExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Idempotently provisions MinIO buckets on application startup.
|
||||
/// </summary>
|
||||
public static async Task ProvisionBucketsAsync(this WebApplication app, params string[] bucketNames)
|
||||
{
|
||||
// Skip entirely if Minio isn't configured (e.g. tenant containers without Minio env var)
|
||||
var connStr = app.Configuration.GetConnectionString("minio");
|
||||
if (string.IsNullOrWhiteSpace(connStr)) return;
|
||||
|
||||
using var scope = app.Services.CreateScope();
|
||||
var minioClient = scope.ServiceProvider.GetRequiredService<IMinioClient>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
|
||||
|
||||
foreach (var bucket in bucketNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
var exists = await minioClient.BucketExistsAsync(new BucketExistsArgs().WithBucket(bucket));
|
||||
if (!exists)
|
||||
{
|
||||
await minioClient.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucket));
|
||||
logger.LogInformation("🚀 Project Clarity: Successfully provisioned MinIO bucket '{Bucket}'", bucket);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "❌ Project Clarity: Failed to provision MinIO bucket '{Bucket}'", bucket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user