Files
sor/Server/src/SOR.Cdn/ServiceRegistration.cs
T
b6ac58bada Switch CDN to S3-compatible Ceph RadosGW (AWSSDK.S3)
Replace custom HttpCdnClient (proprietary upload API) with S3CdnClient
backed by AWSSDK.S3 using ForcePathStyle for Ceph RadosGW compatibility.
CdnOptions gains EndpointUrl/AccessKey/SecretKey/BucketName; removes
UploadBaseUrl/ApiKey. K8s deployments and secrets template updated to
match new config keys.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-27 00:57:15 -05:00

42 lines
1.4 KiB
C#

namespace SOR.Cdn;
using Amazon.S3;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
public static class ServiceRegistration
{
/// <summary>
/// Registers <see cref="ICdnClient"/> (backed by <see cref="S3CdnClient"/>) and reads
/// configuration from the "Cdn" section.
///
/// Production: override via k8s secret env vars:
/// Cdn__PublicBaseUrl, Cdn__EndpointUrl, Cdn__AccessKey, Cdn__SecretKey, Cdn__BucketName
/// </summary>
public static IServiceCollection AddCdnClient(
this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<CdnOptions>(configuration.GetSection(CdnOptions.Section));
// Build AmazonS3Client from CdnOptions; registered as Singleton because
// AmazonS3Client manages its own connection pool.
services.AddSingleton<IAmazonS3>(sp =>
{
var opts = sp.GetRequiredService<IOptions<CdnOptions>>().Value;
var config = new AmazonS3Config
{
ServiceURL = opts.EndpointUrl,
ForcePathStyle = true, // required for Ceph RadosGW
AuthenticationRegion = "us-east-1",
};
return new AmazonS3Client(opts.AccessKey, opts.SecretKey, config);
});
services.AddSingleton<ICdnClient, S3CdnClient>();
return services;
}
}