Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using System.Net;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using StellaOps.Concelier.Connector.Acsc.Configuration;
|
|
using StellaOps.Concelier.Connector.Acsc.Internal;
|
|
using StellaOps.Concelier.Connector.Common.Http;
|
|
|
|
namespace StellaOps.Concelier.Connector.Acsc;
|
|
|
|
public static class AcscServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddAcscConnector(this IServiceCollection services, Action<AcscOptions> configure)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configure);
|
|
|
|
services.AddOptions<AcscOptions>()
|
|
.Configure(configure)
|
|
.PostConfigure(static options => options.Validate());
|
|
|
|
services.AddSourceHttpClient(AcscOptions.HttpClientName, (sp, clientOptions) =>
|
|
{
|
|
var options = sp.GetRequiredService<IOptions<AcscOptions>>().Value;
|
|
clientOptions.Timeout = options.RequestTimeout;
|
|
clientOptions.UserAgent = options.UserAgent;
|
|
clientOptions.RequestVersion = options.RequestVersion;
|
|
clientOptions.VersionPolicy = options.VersionPolicy;
|
|
clientOptions.AllowAutoRedirect = true;
|
|
clientOptions.ConfigureHandler = handler =>
|
|
{
|
|
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
|
handler.AllowAutoRedirect = true;
|
|
};
|
|
|
|
clientOptions.AllowedHosts.Clear();
|
|
clientOptions.AllowedHosts.Add(options.BaseEndpoint.Host);
|
|
if (options.RelayEndpoint is not null)
|
|
{
|
|
clientOptions.AllowedHosts.Add(options.RelayEndpoint.Host);
|
|
}
|
|
|
|
clientOptions.DefaultRequestHeaders["Accept"] = string.Join(", ", new[]
|
|
{
|
|
"application/rss+xml",
|
|
"application/atom+xml;q=0.9",
|
|
"application/xml;q=0.8",
|
|
"text/xml;q=0.7",
|
|
});
|
|
});
|
|
|
|
services.AddSingleton<AcscDiagnostics>();
|
|
services.AddTransient<AcscConnector>();
|
|
|
|
return services;
|
|
}
|
|
}
|