Implemented "roundtrip" status checking. Added node ssl field.
This commit is contained in:
@@ -5,6 +5,12 @@ public class AppConfiguration
|
||||
public DockerData Docker { get; set; } = new();
|
||||
public StorageData Storage { get; set; } = new();
|
||||
public SecurityData Security { get; set; } = new();
|
||||
public RemoteData Remote { get; set; } = new();
|
||||
|
||||
public class RemoteData
|
||||
{
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public class DockerData
|
||||
{
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonlightServers.Daemon.Services;
|
||||
using MoonlightServers.DaemonShared.Http.Responses.Sys;
|
||||
|
||||
namespace MoonlightServers.Daemon.Http.Controllers.Sys;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/system/status")]
|
||||
public class SystemStatusController : Controller
|
||||
{
|
||||
private readonly RemoteService RemoteService;
|
||||
|
||||
public SystemStatusController(RemoteService remoteService)
|
||||
{
|
||||
RemoteService = remoteService;
|
||||
}
|
||||
|
||||
public async Task<SystemStatusResponse> Get()
|
||||
{
|
||||
SystemStatusResponse response;
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
try
|
||||
{
|
||||
await RemoteService.GetStatus();
|
||||
|
||||
sw.Stop();
|
||||
|
||||
response = new()
|
||||
{
|
||||
TripSuccess = true,
|
||||
TripTime = sw.Elapsed,
|
||||
Version = "2.1.0" // TODO: Set global
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sw.Stop();
|
||||
|
||||
response = new()
|
||||
{
|
||||
TripError = e.Message,
|
||||
TripTime = sw.Elapsed,
|
||||
TripSuccess = false,
|
||||
Version = "2.1.0" // TODO: Set global
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
40
MoonlightServers.Daemon/Services/RemoteService.cs
Normal file
40
MoonlightServers.Daemon/Services/RemoteService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.Daemon.Configuration;
|
||||
|
||||
namespace MoonlightServers.Daemon.Services;
|
||||
|
||||
[Singleton]
|
||||
public class RemoteService
|
||||
{
|
||||
private readonly AppConfiguration Configuration;
|
||||
|
||||
public RemoteService(AppConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public Task<HttpApiClient> CreateHttpClient()
|
||||
{
|
||||
var formattedUrl = Configuration.Remote.Url.EndsWith('/')
|
||||
? Configuration.Remote.Url
|
||||
: Configuration.Remote.Url + "/";
|
||||
|
||||
var httpClient = new HttpClient()
|
||||
{
|
||||
BaseAddress = new Uri(formattedUrl)
|
||||
};
|
||||
|
||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Configuration.Security.Token}");
|
||||
|
||||
var apiClient = new HttpApiClient(httpClient);
|
||||
|
||||
return Task.FromResult(apiClient);
|
||||
}
|
||||
|
||||
public async Task GetStatus()
|
||||
{
|
||||
using var apiClient = await CreateHttpClient();
|
||||
await apiClient.Get("api/servers/remote/node/trip");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user