using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using StellaOps.Concelier.Connector.Common.Http; using StellaOps.Concelier.Connector.Distro.RedHat.Configuration; namespace StellaOps.Concelier.Connector.Distro.RedHat; public static class RedHatServiceCollectionExtensions { public static IServiceCollection AddRedHatConnector(this IServiceCollection services, Action configure) { ArgumentNullException.ThrowIfNull(services); ArgumentNullException.ThrowIfNull(configure); services.AddOptions() .Configure(configure) .PostConfigure(static opts => opts.Validate()); services.AddSourceHttpClient(RedHatOptions.HttpClientName, (sp, httpOptions) => { var options = sp.GetRequiredService>().Value; httpOptions.BaseAddress = options.BaseEndpoint; httpOptions.Timeout = options.FetchTimeout; httpOptions.UserAgent = options.UserAgent; httpOptions.AllowedHosts.Clear(); httpOptions.AllowedHosts.Add(options.BaseEndpoint.Host); httpOptions.DefaultRequestHeaders["Accept"] = "application/json"; }); services.AddTransient(); return services; } }