3using System.Threading.Tasks;
5using Microsoft.AspNetCore.Mvc;
6using Microsoft.Extensions.Logging;
51 ILogger<ComponentInterfacingController> logger,
57 authenticationContext,
67 protected override async ValueTask<IActionResult?>
ValidateRequest(CancellationToken cancellationToken)
83 if (instanceReferenceCheck ==
null)
96 ArgumentNullException.ThrowIfNull(metadata);
100 online = instanceReferenceCheck !=
null;
102 if (metadata.Require(x => x.Online) == online)
105 const string OfflineWord =
"offline";
106 const string OnlineWord =
"online";
109 "Instance {instanceId} is says it's {databaseState} in the database, but it is actually {serviceState} in the service. Updating the database to reflect this...",
111 online ? OfflineWord : OnlineWord,
112 online ? OnlineWord : OfflineWord);
114 metadata.Online = online;
127 ArgumentNullException.ThrowIfNull(action);
129 instance ??=
Instance ??
throw new InvalidOperationException(
"ComponentInterfacingController has no Instance!");
134 if (instanceReference ==
null)
136 return await action(instanceReference);
Metadata about a server instance.
Represents an error message returned by the server.
Base Controller for API functions.
ILogger< ApiController > Logger
The ILogger for the ApiController.
ApiController for operations on IInstanceCores.
async ValueTask< IActionResult?> WithComponentInstanceNullable(Func< IInstanceCore, ValueTask< IActionResult?> > action, Models.Instance? instance=null)
Run a given action with the relevant IInstance.
ComponentInterfacingController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, ILogger< ComponentInterfacingController > logger, IInstanceManager instanceManager, IApiHeadersProvider apiHeaders, bool useInstanceRequestHeader)
Initializes a new instance of the ComponentInterfacingController class.
override async ValueTask< IActionResult?> ValidateRequest(CancellationToken cancellationToken)
Performs validation a request.A ValueTask<TResult> resulting in an appropriate IActionResult on valid...
readonly bool useInstanceRequestHeader
If the Api.ApiHeaders.InstanceId header should be checked and used to perform validation for every re...
IInstanceOperations InstanceOperations
Access the IInstanceOperations instance.
readonly IInstanceManager instanceManager
The IInstanceManager for the ComponentInterfacingController.
async ValueTask< IActionResult > WithComponentInstance(Func< IInstanceCore, ValueTask< IActionResult > > action, Models.Instance? instance=null)
Run a given action with the relevant IInstance.
bool ValidateInstanceOnlineStatus(Api.Models.Instance metadata)
Corrects discrepencies between the Api.Models.Instance.Online status of IInstances in the database vs...
Backend abstract implementation of IDatabaseContext.
Task Save(CancellationToken cancellationToken)
Saves changes made to the IDatabaseContext.A Task representing the running operation.
InstancePermissionSet? InstancePermissionSet
The User's effective Models.InstancePermissionSet if applicable.
Helpers for manipulating the Serilog.Context.LogContext.
const string InstanceReferenceContextProperty
The Serilog.Context.LogContext property name for Components.IInstanceReference.Uids.
For interacting with the instance services.
IInstanceReference? GetInstanceReference(Api.Models.Instance metadata)
Get the IInstanceReference associated with given metadata .
Operations that can be performed on a given Models.Instance.
For creating and accessing authentication contexts.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.