-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (48 loc) · 1.69 KB
/
Program.cs
File metadata and controls
58 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using KCert;
using KCert.Challenge;
using KCert.Services;
using System.Reflection;
// command line option for manually generating an ECDSA key
if (args.Length > 0 && args[^1] == "generate-key")
{
Console.WriteLine("Generating ACME Key");
var key = CertClient.GenerateNewKey();
Console.WriteLine(key);
return;
}
var builder = WebApplication.CreateBuilder(args);
// Add all services marked with the [Service] attribute
foreach (var t in Assembly.GetExecutingAssembly().GetTypes())
{
if (t.GetCustomAttribute<ServiceAttribute>() is not null)
{
builder.Services.AddSingleton(t);
}
else if (t.GetCustomAttribute<ChallengeAttribute>() is ChallengeAttribute attr && attr.ChallengeType != builder.Configuration.GetValue<string>("KCert:ChallengeType"))
{
builder.Services.AddSingleton(typeof(IChallengeProvider), t);
}
}
builder.Services.AddSingleton(s => s.GetRequiredService<KubernetesFactory>().GetClient());
builder.Services.AddConnections();
builder.Services.AddControllersWithViews();
builder.WebHost.ConfigureKestrel(opt =>
{
opt.ListenAnyIP(80);
opt.ListenAnyIP(8080);
});
// add background services
builder.Services.AddHostedService<RenewalService>();
builder.Services.AddHostedService<IngressMonitorService>();
builder.Services.AddHostedService<ConfigMonitorService>();
var app = builder.Build();
app.MapWhen(c => c.Connection.LocalPort == 8080, b =>
{
b.UseStaticFiles();
b.UseRouting().UseEndpoints(e => e.MapControllers());
});
app.MapWhen(c => c.Connection.LocalPort == 80 && c.Request.Path.HasValue && c.Request.Path.Value.StartsWith("/.well-known/acme-challenge"), b =>
{
b.UseRouting().UseEndpoints(e => e.MapControllers());
});
app.Run();