using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Services; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Extensions; public static class S3 { public static IServiceCollection AddGarageS3(this IServiceCollection services, IConfiguration configuration) { if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(GeneralBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{GeneralS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{GeneralS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{GeneralS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase), })); services.AddKeyedScoped(GeneralBucketName); } if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(EvidenceS3SettingsSection, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{EvidenceS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{EvidenceS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{EvidenceS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase), })); services.AddKeyedScoped(EvidenceS3SettingsSection); } if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(ContractS3SettingsSection, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{ContractS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{ContractS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{ContractS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase), })); services.AddKeyedScoped(ContractS3SettingsSection); } return services; } }