From 275f29ec1121c1f93b00111feca4ef292c70994d Mon Sep 17 00:00:00 2001 From: pcjones Date: Mon, 13 Jan 2025 19:35:30 +0100 Subject: [PATCH] Make proxy port configurable --- UmlautAdaptarr/Options/GlobalOptions.cs | 7 +++++++ UmlautAdaptarr/Program.cs | 19 ++----------------- UmlautAdaptarr/Properties/launchSettings.json | 3 ++- UmlautAdaptarr/Services/HttpProxyService.cs | 11 +++++++---- docker-compose.yml | 8 +++++--- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/UmlautAdaptarr/Options/GlobalOptions.cs b/UmlautAdaptarr/Options/GlobalOptions.cs index f5c6685..ee731cc 100644 --- a/UmlautAdaptarr/Options/GlobalOptions.cs +++ b/UmlautAdaptarr/Options/GlobalOptions.cs @@ -20,5 +20,12 @@ /// public int IndexerRequestsCacheDurationInMinutes { get; set; } = 12; + /// + /// API key for requests to the UmlautAdaptarr. Optional. + public string? ApiKey { get; set; } = null; + + /// + /// Proxy port for the internal UmlautAdaptarr proxy. + public int ProxyPort { get; set; } = 5006; } } \ No newline at end of file diff --git a/UmlautAdaptarr/Program.cs b/UmlautAdaptarr/Program.cs index 1cb0fc5..1d2b3bc 100644 --- a/UmlautAdaptarr/Program.cs +++ b/UmlautAdaptarr/Program.cs @@ -8,7 +8,8 @@ using UmlautAdaptarr.Utilities; internal class Program { - private static void Main(string[] args) { + private static void Main(string[] args) + { MainAsync(args).Wait(); } @@ -22,11 +23,6 @@ internal class Program builder.Services.AddSerilog(); - - // Log all configuration values - LogConfigurationValues(configuration); - - // Add services to the container. builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() => { @@ -123,15 +119,4 @@ internal class Program //.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently .CreateLogger(); } - - private static void LogConfigurationValues(IConfiguration configuration) - { - Log.Information("Logging all configuration values at startup:"); - - foreach (var kvp in configuration.AsEnumerable()) - { - Log.Information("{Key}: {Value}", kvp.Key, kvp.Value); - } - } - } diff --git a/UmlautAdaptarr/Properties/launchSettings.json b/UmlautAdaptarr/Properties/launchSettings.json index 37160f1..1b1f811 100644 --- a/UmlautAdaptarr/Properties/launchSettings.json +++ b/UmlautAdaptarr/Properties/launchSettings.json @@ -3,7 +3,8 @@ "http": { "commandName": "Project", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "Kestrel__Endpoints__Http__Url": "http://[::]:8080" }, "_launchUrl": "optionsTODO/example.com/api?t=movie&apikey=132&imdbid=123&limit=100", "dotnetRunMessages": true, diff --git a/UmlautAdaptarr/Services/HttpProxyService.cs b/UmlautAdaptarr/Services/HttpProxyService.cs index 2017db4..884d6a1 100644 --- a/UmlautAdaptarr/Services/HttpProxyService.cs +++ b/UmlautAdaptarr/Services/HttpProxyService.cs @@ -1,6 +1,8 @@ -using System.Net; +using Microsoft.Extensions.Options; +using System.Net; using System.Net.Sockets; using System.Text; +using UmlautAdaptarr.Options; namespace UmlautAdaptarr.Services { @@ -8,15 +10,16 @@ namespace UmlautAdaptarr.Services { private TcpListener _listener; private readonly ILogger _logger; - private readonly int _proxyPort = 5006; // TODO move to appsettings.json private readonly IHttpClientFactory _clientFactory; + private readonly GlobalOptions _options; private readonly HashSet _knownHosts = []; private readonly object _hostsLock = new(); private readonly IConfiguration _configuration; private static readonly string[] newLineSeparator = ["\r\n"]; - public HttpProxyService(ILogger logger, IHttpClientFactory clientFactory, IConfiguration configuration) + public HttpProxyService(ILogger logger, IHttpClientFactory clientFactory, IConfiguration configuration, IOptions options) { + _options = options.Value; _logger = logger; _configuration = configuration; _clientFactory = clientFactory; @@ -168,7 +171,7 @@ namespace UmlautAdaptarr.Services public Task StartAsync(CancellationToken cancellationToken) { - _listener = new TcpListener(IPAddress.Any, _proxyPort); + _listener = new TcpListener(IPAddress.Any, _options.ProxyPort); _listener.Start(); Task.Run(() => HandleRequests(cancellationToken), cancellationToken); return Task.CompletedTask; diff --git a/docker-compose.yml b/docker-compose.yml index 3787c0d..ea4bf27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,6 +35,8 @@ services: ### Advanced options (with default values)) #- IpLeakTest__Enabled=false - #- SETTINGS__IndexerRequestsCacheDurationInMinutes=12 - #- Kestrel__Endpoints__Http__Url=http://[::]:8080 - + #- SETTINGS__IndexerRequestsCacheDurationInMinutes=12 # How long to cache indexer requests for. Default is 12 minutes. + #- SETTINGS__ApiKey= # API key for requests to the UmlautAdaptarr. Optional, probably only needed for seedboxes. + #- SETTINGS__ProxyPort=5006 # Proxy port for the internal UmlautAdaptarr proxy used for Prowlarr. + #- Kestrel__Endpoints__Http__Url=http://[::]:5005 # HTTP port for the UmlautAdaptarr +