fix(dashboard): ShowTagValues now gates the alarms hub and /browse live values
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||
using ZB.MOM.WW.MxGateway.Server.Alarms;
|
||||
using ZB.MOM.WW.MxGateway.Server.Configuration;
|
||||
using ZB.MOM.WW.MxGateway.Server.Sessions;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
@@ -11,6 +13,16 @@ namespace ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
/// expires. All access is serialised through <see cref="_gate"/> so the
|
||||
/// single backing worker only ever sees one in-flight command.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This service is also where <c>MxGateway:Dashboard:ShowTagValues</c> is
|
||||
/// applied to the Browse panel: with the flag false (the default) the
|
||||
/// formatted value never leaves this boundary — the projected
|
||||
/// <see cref="DashboardTagValue"/> carries
|
||||
/// <see cref="DashboardTagValue.RedactedValueText"/> instead. Putting the
|
||||
/// decision at the service rather than in the page keeps it to one place and
|
||||
/// keeps a value out of the render tree entirely, rather than relying on
|
||||
/// every current and future view to remember to suppress it.
|
||||
/// </remarks>
|
||||
public sealed class DashboardLiveDataService : IDashboardLiveDataService, IAsyncDisposable
|
||||
{
|
||||
private const string BackendName = "Galaxy";
|
||||
@@ -38,6 +50,15 @@ public sealed class DashboardLiveDataService : IDashboardLiveDataService, IAsync
|
||||
private readonly ILogger<DashboardLiveDataService> _logger;
|
||||
private readonly SemaphoreSlim _gate = new(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// <c>MxGateway:Dashboard:ShowTagValues</c>. False (the default)
|
||||
/// substitutes <see cref="DashboardTagValue.RedactedValueText"/> for every
|
||||
/// value this service hands the Browse panel; quality, data type, source
|
||||
/// timestamp, and any error still describe the real read, so the panel
|
||||
/// remains a diagnostic surface without being a value-disclosure one.
|
||||
/// </summary>
|
||||
private readonly bool _showTagValues;
|
||||
|
||||
// Least-recently-read-last advise set: the list holds every currently advised
|
||||
// tag ordered most- to least-recently read, the dictionary indexes into it.
|
||||
// Both are only ever touched under _gate, which already serialises all viewers.
|
||||
@@ -53,15 +74,19 @@ public sealed class DashboardLiveDataService : IDashboardLiveDataService, IAsync
|
||||
/// <summary>Initializes the live-data service.</summary>
|
||||
/// <param name="sessionManager">Gateway session manager.</param>
|
||||
/// <param name="alarmService">Gateway central alarm service.</param>
|
||||
/// <param name="options">Gateway options supplying <c>Dashboard:ShowTagValues</c>.</param>
|
||||
/// <param name="logger">Diagnostic logger.</param>
|
||||
public DashboardLiveDataService(
|
||||
ISessionManager sessionManager,
|
||||
IGatewayAlarmService alarmService,
|
||||
IOptions<GatewayOptions> options,
|
||||
ILogger<DashboardLiveDataService> logger)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
_sessionManager = sessionManager ?? throw new ArgumentNullException(nameof(sessionManager));
|
||||
_alarmService = alarmService ?? throw new ArgumentNullException(nameof(alarmService));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_showTagValues = options.Value.Dashboard.ShowTagValues;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -96,8 +121,12 @@ public sealed class DashboardLiveDataService : IDashboardLiveDataService, IAsync
|
||||
.ReadBulkAsync(serverHandle, tagAddresses.ToArray(), ReadTimeout, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// The only place the /browse live-value gate is evaluated: the page
|
||||
// renders whatever ValueText it is handed, so a second check in the
|
||||
// view could only ever disagree with this one.
|
||||
DashboardTagValue[] values = results
|
||||
.Select(DashboardTagValue.FromBulkReadResult)
|
||||
.Select(value => _showTagValues ? value : value with { ValueText = DashboardTagValue.RedactedValueText })
|
||||
.ToArray();
|
||||
return new DashboardLiveReadResult(values, null, session.SessionId, session.WorkerProcessId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user