using LiteCharms.Features.S3; using LiteCharms.Features.S3.Abstractions; using static LiteCharms.Features.S3.Constants; namespace LiteCharms.Features.Extensions; public static class S3 { public static IServiceCollection AddGarageS3(this IServiceCollection services, IConfiguration configuration) { if (configuration.GetSection(BookshopBucketName) is not null) { services.AddKeyedSingleton(BookshopBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{BookshopS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopS3SettingsSection}:Region").Value, ForcePathStyle = true, })); services.AddKeyedScoped(BookshopBucketName); } if (configuration.GetSection(BookshopInvoicesBucketName) is not null) { services.AddKeyedSingleton(BookshopInvoicesBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopInvoicesBucketName}:AccessKey").Value, configuration.GetSection($"{BookshopInvoicesBucketName}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopInvoicesBucketName}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopInvoicesBucketName}:Region").Value, ForcePathStyle = true, })); services.AddKeyedScoped(BookshopInvoicesBucketName); } if (configuration.GetSection(BookshopQuotesBucketName) is not null) { services.AddKeyedSingleton(BookshopQuotesBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopQuotesBucketName}:AccessKey").Value, configuration.GetSection($"{BookshopQuotesBucketName}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopQuotesBucketName}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopQuotesBucketName}:Region").Value, ForcePathStyle = true, })); services.AddKeyedScoped(BookshopQuotesBucketName); } return services; } }