diff --git a/Services/Admin/Pages/Assets/Index.cshtml b/Services/Admin/Pages/Assets/Index.cshtml
index af63302..045a646 100644
--- a/Services/Admin/Pages/Assets/Index.cshtml
+++ b/Services/Admin/Pages/Assets/Index.cshtml
@@ -33,14 +33,13 @@
MinIO Not Configured
- To browse CDN files, configure MinIO credentials in appsettings.json:
- "MinIO": {
- "Endpoint": "assets.aeternalisgames.com",
- "AccessKey": "your-access-key",
- "SecretKey": "your-secret-key",
- "BucketName": "downloads",
- "UseSSL": true
-}
+ To browse CDN files, set these environment variables (Kubernetes secret):
+ MINIO_ENDPOINT=assets.aeternalisgames.com
+MINIO_ACCESS_KEY=your-access-key
+MINIO_SECRET_KEY=your-secret-key
+MINIO_BUCKET=downloads
+MINIO_USE_SSL=true
+ Or configure in appsettings.json under "MinIO" section.
}
else
diff --git a/Services/CdnBrowserService.cs b/Services/CdnBrowserService.cs
index cd3d30f..89aca0f 100644
--- a/Services/CdnBrowserService.cs
+++ b/Services/CdnBrowserService.cs
@@ -10,7 +10,6 @@ public class MinioConfig
public string SecretKey { get; set; } = "";
public string BucketName { get; set; } = "downloads";
public bool UseSSL { get; set; } = true;
- public bool AnonymousAccess { get; set; } = false;
}
public class CdnFile
@@ -32,46 +31,56 @@ public interface ICdnBrowserService
public class MinioCdnBrowserService : ICdnBrowserService
{
private readonly IMinioClient? _client;
- private readonly MinioConfig _config;
+ private readonly string _bucketName;
private readonly ILogger _logger;
+ private readonly bool _isConfigured;
- public bool IsConfigured => _client != null;
+ public bool IsConfigured => _isConfigured;
public MinioCdnBrowserService(IConfiguration configuration, ILogger logger)
{
_logger = logger;
- _config = configuration.GetSection("MinIO").Get() ?? new MinioConfig();
-
- // Check if we have credentials OR anonymous access is enabled
- var hasCredentials = !string.IsNullOrEmpty(_config.AccessKey) && !string.IsNullOrEmpty(_config.SecretKey);
- if (hasCredentials || _config.AnonymousAccess)
+ // Try environment variables first (for Kubernetes secrets), fall back to appsettings
+ var endpoint = Environment.GetEnvironmentVariable("MINIO_ENDPOINT")
+ ?? configuration["MinIO:Endpoint"]
+ ?? "";
+ var accessKey = Environment.GetEnvironmentVariable("MINIO_ACCESS_KEY")
+ ?? configuration["MinIO:AccessKey"]
+ ?? "";
+ var secretKey = Environment.GetEnvironmentVariable("MINIO_SECRET_KEY")
+ ?? configuration["MinIO:SecretKey"]
+ ?? "";
+ _bucketName = Environment.GetEnvironmentVariable("MINIO_BUCKET")
+ ?? configuration["MinIO:BucketName"]
+ ?? "downloads";
+ var useSSL = Environment.GetEnvironmentVariable("MINIO_USE_SSL")?.ToLower() != "false"
+ && (configuration.GetValue("MinIO:UseSSL") ?? true);
+
+ var hasCredentials = !string.IsNullOrEmpty(accessKey) && !string.IsNullOrEmpty(secretKey);
+ _isConfigured = hasCredentials && !string.IsNullOrEmpty(endpoint);
+
+ if (_isConfigured)
{
try
{
- var builder = new MinioClient()
- .WithEndpoint(_config.Endpoint)
- .WithSSL(_config.UseSSL);
-
- if (hasCredentials)
- {
- builder = builder.WithCredentials(_config.AccessKey, _config.SecretKey);
- }
- // For anonymous access, we don't set credentials
+ _client = new MinioClient()
+ .WithEndpoint(endpoint)
+ .WithCredentials(accessKey, secretKey)
+ .WithSSL(useSSL)
+ .Build();
- _client = builder.Build();
-
- _logger.LogInformation("MinIO client initialized for endpoint: {Endpoint} (Anonymous: {Anon})",
- _config.Endpoint, _config.AnonymousAccess && !hasCredentials);
+ _logger.LogInformation("MinIO client initialized for endpoint: {Endpoint}, bucket: {Bucket}", endpoint, _bucketName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize MinIO client");
+ _isConfigured = false;
}
}
else
{
- _logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MinIO:AccessKey/SecretKey or MinIO:AnonymousAccess=true");
+ _logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY environment variables or MinIO section in appsettings.");
}
}
@@ -92,7 +101,7 @@ public class MinioCdnBrowserService : ICdnBrowserService
prefix += "/";
var listArgs = new ListObjectsArgs()
- .WithBucket(_config.BucketName)
+ .WithBucket(_bucketName)
.WithPrefix(prefix)
.WithRecursive(false); // Only list current level
@@ -135,7 +144,7 @@ public class MinioCdnBrowserService : ICdnBrowserService
prefix += "/";
var listArgs = new ListObjectsArgs()
- .WithBucket(_config.BucketName)
+ .WithBucket(_bucketName)
.WithPrefix(prefix)
.WithRecursive(false);