Webpanel channels

This commit is contained in:
Jordan Brown
2021-01-29 22:37:27 -05:00
parent 8681d70dac
commit 25cdecbe37
4 changed files with 45 additions and 2 deletions
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Tgstation.Server.Host.Configuration
{
@@ -22,6 +22,8 @@ namespace Tgstation.Server.Host.Configuration
/// </summary>
public bool AllowAnyOrigin { get; set; }
public string Channel { get; set; }
/// <summary>
/// Origins allowed for CORS requests
/// </summary>
@@ -1,10 +1,14 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using System;
using System.Globalization;
using System.Net.Mime;
using Tgstation.Server.Api;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Core;
namespace Tgstation.Server.Host.Controllers
@@ -20,13 +24,20 @@ namespace Tgstation.Server.Host.Controllers
/// </summary>
readonly IWebHostEnvironment hostEnvironment;
/// <summary>
/// The <see cref="ControlPanelConfiguration"/> for the <see cref="ControlPanelController"/>.
/// </summary>
readonly ControlPanelConfiguration controlPanelConfiguration;
/// <summary>
/// Initializes a new instance of the <see cref="ControlPanelController"/> <see langword="class"/>.
/// </summary>
/// <param name="hostEnvironment">The value of <see cref="hostEnvironment"/>.</param>
public ControlPanelController(IWebHostEnvironment hostEnvironment)
/// <param name="controlPanelConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="controlPanelConfiguration"/>.</param>
public ControlPanelController(IWebHostEnvironment hostEnvironment, IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions)
{
this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
controlPanelConfiguration = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
}
/// <summary>
@@ -54,5 +65,29 @@ namespace Tgstation.Server.Host.Controllers
return File("index.html", MediaTypeNames.Text.Html);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[Route("channel.json")]
[HttpGet]
public JsonResult GetChannelJson()
{
var controlPanelChannel = controlPanelConfiguration.Channel;
if (controlPanelChannel == "local")
controlPanelChannel = "/";
controlPanelChannel = controlPanelChannel
.Replace("${Major}", ApiHeaders.Version.Major.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
.Replace("${Minor}", ApiHeaders.Version.Minor.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)
.Replace("${Patch}", ApiHeaders.Version.Build.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal);
return Json(new
{
FormatVersion = 1,
Channel = controlPanelChannel,
});
}
}
}
@@ -36,6 +36,11 @@ namespace Tgstation.Server.Host.Properties
/// </summary>
public string RawHostWatchdogVersion { get; }
/// <summary>
/// The compile time default
/// </summary>
public string DefaultControlPanelChannel { get; }
/// <summary>
/// Initializes a new instance of the <see cref="MasterVersionsAttribute"/> <see langword="class"/>.
/// </summary>
@@ -28,6 +28,7 @@ Logging:
Microsoft: Warning
ControlPanel:
Enable: false
Channel: https://tgstation.github.io/tgstation-server-webpanel/api/${Major}.${Minor}.${Patch}
AllowAnyOrigin: false
AllowedOrigins: []
Updates: