using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using StellaOps.Concelier.Connector.Common.Http; using StellaOps.Concelier.Connector.Vndr.Adobe.Configuration; namespace StellaOps.Concelier.Connector.Vndr.Adobe; public static class AdobeServiceCollectionExtensions { public static IServiceCollection AddAdobeConnector(this IServiceCollection services, Action configure) { ArgumentNullException.ThrowIfNull(services); ArgumentNullException.ThrowIfNull(configure); services.AddOptions() .Configure(configure) .PostConfigure(static opts => opts.Validate()); services.AddSourceHttpClient(AdobeOptions.HttpClientName, static (sp, options) => { var adobeOptions = sp.GetRequiredService>().Value; options.BaseAddress = adobeOptions.IndexUri; options.UserAgent = "StellaOps.Concelier.VndrAdobe/1.0"; options.Timeout = TimeSpan.FromSeconds(20); options.AllowedHosts.Clear(); options.AllowedHosts.Add(adobeOptions.IndexUri.Host); foreach (var additional in adobeOptions.AdditionalIndexUris) { options.AllowedHosts.Add(additional.Host); } }); services.TryAddSingleton(); services.AddTransient(); return services; } }