-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathProgram.cs
74 lines (68 loc) · 2.99 KB
/
Program.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using aggregator;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace aggregator_host
{
public static class Program
{
private static bool InDocker
=> Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true";
public static async System.Threading.Tasks.Task Main(string[] args)
{
if (InDocker)
{
Console.WriteLine($@"Aggregator {RequestHelper.AggregatorVersion} started in Docker mode.
{RuntimeInformation.FrameworkDescription}
{RuntimeInformation.OSDescription} ({RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant()})
");
Telemetry.InitializeTelemetry();
Telemetry.TrackEvent("Docker Host Start");
var host = CreatePlainHostBuilder(args).Build();
//HACK https://stackoverflow.com/a/56079178
var repo = (IApiKeyRepository)host.Services.GetService(typeof(IApiKeyRepository));
await repo.LoadAsync();
await host.RunAsync();
Telemetry.TrackEvent("Docker Host End");
Telemetry.Shutdown();
}
else
{
Console.WriteLine("Unsupported run mode, exiting.");
}
}
public static IHostBuilder CreatePlainHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.AddEnvironmentVariables()
.AddCommandLine(args);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureWebHost(config =>
{
config
.ConfigureKestrel(serverOptions =>
{
/* Sample PowerShell to generate a self-signed certificate
* $cert = New-SelfSignedCertificate -KeyLength 2048 -KeyAlgorithm RSA -Type SSLServerAuthentication -FriendlyName "Aggregator" -NotAfter 2025-12-31 -Subject "localhost" -TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=127.0.0.1&IPAddress=::1")
* $certPass = Read-Host -Prompt "Cert pass" -AsSecureString
* Export-PfxCertificate -FilePath "aggregator-localhost.pfx" -Cert $cert -Password $certPass
*/
serverOptions.ConfigureHttpsDefaults(listenOptions =>
{
listenOptions.SslProtocols = SslProtocols.Tls12;
});
})
;
})
;
}
}