From c18167889d15bcb1c99b6bf67751c1dd182e4a6c Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sat, 1 Aug 2020 09:10:05 -0500 Subject: [PATCH] Adding update related options and using them in HostedService --- BTCPayServer/Configuration/BTCPayServerOptions.cs | 4 ++++ BTCPayServer/Configuration/DefaultConfiguration.cs | 2 ++ .../HostedServices/NewVersionCheckerHostedService.cs | 11 +++++++---- BTCPayServer/Properties/launchSettings.json | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Configuration/BTCPayServerOptions.cs b/BTCPayServer/Configuration/BTCPayServerOptions.cs index 2eae346b7..8665be4cd 100644 --- a/BTCPayServer/Configuration/BTCPayServerOptions.cs +++ b/BTCPayServer/Configuration/BTCPayServerOptions.cs @@ -176,6 +176,8 @@ namespace BTCPayServer.Configuration SocksEndpoint = endpoint; } + UpdateCheck = conf.GetOrDefault("updatecheck", false); + UpdateUrl = conf.GetOrDefault("updateurl", new Uri("https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest")); var sshSettings = ParseSSHConfiguration(conf); if ((!string.IsNullOrEmpty(sshSettings.Password) || !string.IsNullOrEmpty(sshSettings.KeyFile)) && !string.IsNullOrEmpty(sshSettings.Server)) @@ -301,5 +303,7 @@ namespace BTCPayServer.Configuration set; } public string TorrcFile { get; set; } + public bool UpdateCheck { get; set; } + public Uri UpdateUrl { get; set; } } } diff --git a/BTCPayServer/Configuration/DefaultConfiguration.cs b/BTCPayServer/Configuration/DefaultConfiguration.cs index e24a31bd2..6b86adcaa 100644 --- a/BTCPayServer/Configuration/DefaultConfiguration.cs +++ b/BTCPayServer/Configuration/DefaultConfiguration.cs @@ -38,6 +38,8 @@ namespace BTCPayServer.Configuration app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue); app.Option("--torrcfile", "Path to torrc file containing hidden services directories (default: empty)", CommandOptionType.SingleValue); app.Option("--socksendpoint", "Socks endpoint to connect to onion urls (default: empty)", CommandOptionType.SingleValue); + app.Option("--updatecheck", $"Enabling once a day check for new releases (default: false)", CommandOptionType.SingleValue); + app.Option("--updateurl", $"Url location used for updatecheck (default: https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest)", CommandOptionType.SingleValue); app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue); app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue); app.Option("--disable-registration", "Disables new user registrations (default:true)", CommandOptionType.SingleValue); diff --git a/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs b/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs index 5103789ec..1ea989c1d 100644 --- a/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs +++ b/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using BTCPayServer.Configuration; using BTCPayServer.Logging; using BTCPayServer.Services; using BTCPayServer.Services.Notifications; @@ -80,18 +81,20 @@ namespace BTCPayServer.HostedServices public class GithubVersionFetcher : IVersionFetcher { private readonly HttpClient _httpClient; - public GithubVersionFetcher(IHttpClientFactory httpClientFactory) + private readonly Uri _updateurl; + public GithubVersionFetcher(IHttpClientFactory httpClientFactory, BTCPayServerOptions options) { _httpClient = httpClientFactory.CreateClient(nameof(GithubVersionFetcher)); _httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); _httpClient.DefaultRequestHeaders.Add("User-Agent", "BTCPayServer/NewVersionChecker"); + + _updateurl = options.UpdateUrl; } private static readonly Regex _releaseVersionTag = new Regex("^(v[1-9]+(\\.[0-9]+)*(-[0-9]+)?)$"); public async Task Fetch(CancellationToken cancellation) { - const string url = "https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest"; - using (var resp = await _httpClient.GetAsync(url, cancellation)) + using (var resp = await _httpClient.GetAsync(_updateurl, cancellation)) { var strResp = await resp.Content.ReadAsStringAsync(); if (resp.IsSuccessStatusCode) @@ -105,7 +108,7 @@ namespace BTCPayServer.HostedServices else { Logs.Events.LogWarning($"Unsuccessful status code returned during new version check. " + - $"Url: {url}, HTTP Code: {resp.StatusCode}, Response Body: {strResp}"); + $"Url: {_updateurl}, HTTP Code: {resp.StatusCode}, Response Body: {strResp}"); } } diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index 79d84c25c..c2a8d00a4 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -19,7 +19,9 @@ "BTCPAY_POSTGRES": "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver", "BTCPAY_DEBUGLOG": "debug.log", "BTCPAY_TORRCFILE": "../BTCPayServer.Tests/TestData/Tor/torrc", - "BTCPAY_SOCKSENDPOINT": "localhost:9050" + "BTCPAY_SOCKSENDPOINT": "localhost:9050", + "BTCPAY_UPDATECHECK": "false", + "BTCPAY_UPDATEURL": "" }, "applicationUrl": "http://127.0.0.1:14142/" },