From 16eedf4153d82d26afc9ff1294b4a27fdcbb5d97 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 3 Aug 2020 03:16:29 -0500 Subject: [PATCH] Deducing if to perform update check from update url configuration --- BTCPayServer/Configuration/BTCPayServerOptions.cs | 4 +--- BTCPayServer/Configuration/DefaultConfiguration.cs | 3 +-- BTCPayServer/Controllers/AccountController.cs | 2 +- BTCPayServer/Controllers/GreenField/UsersController.cs | 2 +- BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs | 3 +++ BTCPayServer/Properties/launchSettings.json | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/BTCPayServer/Configuration/BTCPayServerOptions.cs b/BTCPayServer/Configuration/BTCPayServerOptions.cs index 8665be4cd..3cd189a7b 100644 --- a/BTCPayServer/Configuration/BTCPayServerOptions.cs +++ b/BTCPayServer/Configuration/BTCPayServerOptions.cs @@ -176,8 +176,7 @@ 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")); + UpdateUrl = conf.GetOrDefault("updateurl", null); var sshSettings = ParseSSHConfiguration(conf); if ((!string.IsNullOrEmpty(sshSettings.Password) || !string.IsNullOrEmpty(sshSettings.KeyFile)) && !string.IsNullOrEmpty(sshSettings.Server)) @@ -303,7 +302,6 @@ 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 6b86adcaa..d16245d9a 100644 --- a/BTCPayServer/Configuration/DefaultConfiguration.cs +++ b/BTCPayServer/Configuration/DefaultConfiguration.cs @@ -38,8 +38,7 @@ 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("--updateurl", $"Url used for once a day new release version check. Check performed only if value is not empty (default: empty)", 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/Controllers/AccountController.cs b/BTCPayServer/Controllers/AccountController.cs index cac9f0e36..6d1b8d3c0 100644 --- a/BTCPayServer/Controllers/AccountController.cs +++ b/BTCPayServer/Controllers/AccountController.cs @@ -444,7 +444,7 @@ namespace BTCPayServer.Controllers settings.FirstRun = false; await _SettingsRepository.UpdateSetting(settings); - await _SettingsRepository.FirstAdminRegistered(policies, _Options.UpdateCheck, _Options.DisableRegistration); + await _SettingsRepository.FirstAdminRegistered(policies, _Options.UpdateUrl != null, _Options.DisableRegistration); RegisteredAdmin = true; } diff --git a/BTCPayServer/Controllers/GreenField/UsersController.cs b/BTCPayServer/Controllers/GreenField/UsersController.cs index 8a3dbb9cb..350b7cf02 100644 --- a/BTCPayServer/Controllers/GreenField/UsersController.cs +++ b/BTCPayServer/Controllers/GreenField/UsersController.cs @@ -148,7 +148,7 @@ namespace BTCPayServer.Controllers.GreenField await _userManager.AddToRoleAsync(user, Roles.ServerAdmin); if (!anyAdmin) { - await _settingsRepository.FirstAdminRegistered(policies, _options.UpdateCheck, _options.DisableRegistration); + await _settingsRepository.FirstAdminRegistered(policies, _options.UpdateUrl != null, _options.DisableRegistration); } } _eventAggregator.Publish(new UserRegisteredEvent() { RequestUri = Request.GetAbsoluteRootUri(), User = user, Admin = request.IsAdministrator is true }); diff --git a/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs b/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs index 1ea989c1d..c7dd75637 100644 --- a/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs +++ b/BTCPayServer/HostedServices/NewVersionCheckerHostedService.cs @@ -94,6 +94,9 @@ namespace BTCPayServer.HostedServices private static readonly Regex _releaseVersionTag = new Regex("^(v[1-9]+(\\.[0-9]+)*(-[0-9]+)?)$"); public async Task Fetch(CancellationToken cancellation) { + if (_updateurl == null) + return null; + using (var resp = await _httpClient.GetAsync(_updateurl, cancellation)) { var strResp = await resp.Content.ReadAsStringAsync(); diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index c2a8d00a4..15805eab9 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -20,7 +20,6 @@ "BTCPAY_DEBUGLOG": "debug.log", "BTCPAY_TORRCFILE": "../BTCPayServer.Tests/TestData/Tor/torrc", "BTCPAY_SOCKSENDPOINT": "localhost:9050", - "BTCPAY_UPDATECHECK": "false", "BTCPAY_UPDATEURL": "" }, "applicationUrl": "http://127.0.0.1:14142/"