Integrate Configurator External Service (#1190)

This commit is contained in:
Andrew Camilleri
2020-01-21 10:27:10 +01:00
committed by Nicolas Dorier
parent 8e6f43cd3a
commit 1bfe9dda97
8 changed files with 79 additions and 9 deletions

1
.gitignore vendored
View File

@@ -293,3 +293,4 @@ BTCPayServer/wwwroot/bundles/*
!BTCPayServer/wwwroot/bundles/.gitignore !BTCPayServer/wwwroot/bundles/.gitignore
.vscode .vscode
BTCPayServer/testpwd

View File

@@ -141,6 +141,7 @@ namespace BTCPayServer.Configuration
ExternalServices.Load(net.CryptoCode, conf); ExternalServices.Load(net.CryptoCode, conf);
} }
ExternalServices.LoadNonCryptoServices(conf);
Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray())); Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));
var services = conf.GetOrDefault<string>("externalservices", null); var services = conf.GetOrDefault<string>("externalservices", null);

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Controllers; using BTCPayServer.Controllers;
@@ -77,7 +78,7 @@ namespace BTCPayServer.Configuration
} }
} }
if (serviceType == ExternalServiceTypes.Charge || serviceType == ExternalServiceTypes.RTL || serviceType == ExternalServiceTypes.Spark) if (new []{ExternalServiceTypes.Charge, ExternalServiceTypes.RTL, ExternalServiceTypes.Spark, ExternalServiceTypes.Configurator}.Contains(serviceType))
{ {
// Read access key from cookie file // Read access key from cookie file
if (connectionString.CookieFilePath != null) if (connectionString.CookieFilePath != null)

View File

@@ -41,11 +41,20 @@ namespace BTCPayServer.Configuration
$"lightning charge server: 'type=charge;server=https://charge.example.com;cookiefilepath=/root/.charge/.cookie'" + Environment.NewLine + $"lightning charge server: 'type=charge;server=https://charge.example.com;cookiefilepath=/root/.charge/.cookie'" + Environment.NewLine +
"Error: {1}", "Error: {1}",
"C-Lightning (Charge server)"); "C-Lightning (Charge server)");
}
public void LoadNonCryptoServices(IConfiguration configuration)
{
Load(configuration, null, "configurator", ExternalServiceTypes.Configurator, "Invalid setting {0}, " + Environment.NewLine +
$"configurator: 'passwordfile=/etc/configurator/password'" + Environment.NewLine +
"Error: {1}",
"Configurator");
} }
void Load(IConfiguration configuration, string cryptoCode, string serviceName, ExternalServiceTypes type, string errorMessage, string displayName) void Load(IConfiguration configuration, string cryptoCode, string serviceName, ExternalServiceTypes type, string errorMessage, string displayName)
{ {
var setting = $"{cryptoCode}.external.{serviceName}"; var setting = $"{(!string.IsNullOrEmpty(cryptoCode)? $"{cryptoCode}.": string.Empty)}external.{serviceName}";
var connStr = configuration.GetOrDefault<string>(setting, string.Empty); var connStr = configuration.GetOrDefault<string>(setting, string.Empty);
if (connStr.Length != 0) if (connStr.Length != 0)
{ {
@@ -65,8 +74,11 @@ namespace BTCPayServer.Configuration
public ExternalService GetService(string serviceName, string cryptoCode) public ExternalService GetService(string serviceName, string cryptoCode)
{ {
return this.FirstOrDefault(o => o.CryptoCode.Equals(cryptoCode, StringComparison.OrdinalIgnoreCase) && return this.FirstOrDefault(o =>
o.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase)); (cryptoCode == null && o.CryptoCode == null) ||
(o.CryptoCode != null && o.CryptoCode.Equals(cryptoCode, StringComparison.OrdinalIgnoreCase))
&&
o.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase));
} }
} }
@@ -88,6 +100,7 @@ namespace BTCPayServer.Configuration
RTL, RTL,
Charge, Charge,
P2P, P2P,
RPC RPC,
Configurator
} }
} }

View File

@@ -528,10 +528,12 @@ namespace BTCPayServer.Controllers
return null; return null;
} }
[Route("server/services/{serviceName}/{cryptoCode}")]
[Route("server/services/{serviceName}/{cryptoCode?}")]
public async Task<IActionResult> Service(string serviceName, string cryptoCode, bool showQR = false, uint? nonce = null) public async Task<IActionResult> Service(string serviceName, string cryptoCode, bool showQR = false, uint? nonce = null)
{ {
if (!_dashBoard.IsFullySynched(cryptoCode, out _)) if (!string.IsNullOrEmpty(cryptoCode) && !_dashBoard.IsFullySynched(cryptoCode, out _))
{ {
TempData[WellKnownTempData.ErrorMessage] = $"{cryptoCode} is not fully synched"; TempData[WellKnownTempData.ErrorMessage] = $"{cryptoCode} is not fully synched";
return RedirectToAction(nameof(Services)); return RedirectToAction(nameof(Services));
@@ -542,6 +544,7 @@ namespace BTCPayServer.Controllers
try try
{ {
if (service.Type == ExternalServiceTypes.P2P) if (service.Type == ExternalServiceTypes.P2P)
{ {
return View("P2PService", new LightningWalletServices() return View("P2PService", new LightningWalletServices()
@@ -595,6 +598,14 @@ namespace BTCPayServer.Controllers
case ExternalServiceTypes.LNDGRPC: case ExternalServiceTypes.LNDGRPC:
case ExternalServiceTypes.LNDRest: case ExternalServiceTypes.LNDRest:
return LndServices(service, connectionString, nonce); return LndServices(service, connectionString, nonce);
case ExternalServiceTypes.Configurator:
return View("ConfiguratorService",
new LightningWalletServices()
{
ShowQR = showQR,
WalletName = service.ServiceName,
ServiceLink = $"{connectionString.Server}?password={connectionString.AccessKey}"
});
default: default:
throw new NotSupportedException(service.Type.ToString()); throw new NotSupportedException(service.Type.ToString());
} }

View File

@@ -40,6 +40,7 @@
"BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "../BTCPayServer.Tests/TestData/LndSeedBackup/walletunlock.json", "BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "../BTCPayServer.Tests/TestData/LndSeedBackup/walletunlock.json",
"BTCPAY_BTCEXTERNALSPARK": "server=/spark/btc/;cookiefile=fake", "BTCPAY_BTCEXTERNALSPARK": "server=/spark/btc/;cookiefile=fake",
"BTCPAY_BTCEXTERNALCHARGE": "server=https://127.0.0.1:53280/mycharge/btc/;cookiefilepath=fake", "BTCPAY_BTCEXTERNALCHARGE": "server=https://127.0.0.1:53280/mycharge/btc/;cookiefilepath=fake",
"BTCPAY_EXTERNALCONFIGURATOR": "passwordfile=testpwd;server=/configurator",
"BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/", "BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/",
"BTCPAY_ALLOW-ADMIN-REGISTRATION": "true", "BTCPAY_ALLOW-ADMIN-REGISTRATION": "true",
"BTCPAY_DISABLE-REGISTRATION": "false", "BTCPAY_DISABLE-REGISTRATION": "false",

View File

@@ -0,0 +1,33 @@
@model LightningWalletServices
@{
ViewData.SetActivePageAndTitle(ServerNavPages.Services);
}
<h4>BTCPay Server Configurator</h4>
<partial name="_StatusMessage" />
<div class="row">
<div class="col-md-6">
<div asp-validation-summary="All" class="text-danger"></div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<p>
<span>This page exposes information to use the configured BTCPay Server Configurator to modify this setup.</span>
</p>
</div>
<a href="@Model.ServiceLink" target="_blank" class="form-group">
<label>Service</label>
<input asp-for="ServiceLink" readonly class="form-control" />
</a>
</div>
</div>
@section Scripts {
@await Html.PartialAsync("_ValidationScriptsPartial")
}

View File

@@ -29,7 +29,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var s in Model.ExternalServices) @foreach (var s in Model.ExternalServices.Where(service => !string.IsNullOrEmpty(service.CryptoCode)))
{ {
<tr> <tr>
<td>@s.CryptoCode</td> <td>@s.CryptoCode</td>
@@ -52,7 +52,7 @@
</div> </div>
</div> </div>
@if (Model.OtherExternalServices.Count != 0) @if (Model.OtherExternalServices.Count != 0 || Model.ExternalServices.Any(service => string.IsNullOrEmpty(service.CryptoCode)))
{ {
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
@@ -69,6 +69,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var s in Model.ExternalServices.Where(service => string.IsNullOrEmpty(service.CryptoCode)))
{
<tr>
<td>@s.DisplayName</td>
<td style="text-align: right">
<a asp-action="Service" asp-route-serviceName="@s.ServiceName">See information</a>
</td>
</tr>
}
@foreach (var s in Model.OtherExternalServices) @foreach (var s in Model.OtherExternalServices)
{ {
<tr> <tr>