3using System.Threading.Tasks;
5using Microsoft.AspNetCore.Mvc;
6using Microsoft.Extensions.Logging;
49 ILogger<ComponentInterfacingController> logger,
54 authenticationContextFactory,
63 protected override async Task<IActionResult>
ValidateRequest(CancellationToken cancellationToken)
78 if (instanceReferenceCheck ==
null)
91 ArgumentNullException.ThrowIfNull(metadata);
95 online = instanceReferenceCheck !=
null;
97 if (metadata.Online.Value == online)
100 const string OfflineWord =
"offline";
101 const string OnlineWord =
"online";
104 "Instance {instanceId} is says it's {databaseState} in the database, but it is actually {serviceState} in the service. Updating the database to reflect this...",
106 online ? OfflineWord : OnlineWord,
107 online ? OnlineWord : OfflineWord);
109 metadata.Online = online;
122 ArgumentNullException.ThrowIfNull(action);
129 if (instanceReference ==
null)
131 return await action(instanceReference);
Metadata about a server instance.
Represents an error message returned by the server.
Base Controller for API functions.
Models.Instance Instance
The Instance for the operation.
ILogger< ApiController > Logger
The ILogger for the ApiController.
ApiController for operations on IInstanceCores.
override async Task< IActionResult > ValidateRequest(CancellationToken cancellationToken)
Performs validation a request. A Task<TResult> resulting in an appropriate IActionResult on validatio...
ComponentInterfacingController(IDatabaseContext databaseContext, IAuthenticationContextFactory authenticationContextFactory, ILogger< ComponentInterfacingController > logger, IInstanceManager instanceManager, bool useInstanceRequestHeader=false)
Initializes a new instance of the ComponentInterfacingController class.
async Task< IActionResult > WithComponentInstance(Func< IInstanceCore, Task< IActionResult > > action, Models.Instance instance=null)
Run a given action with the relevant IInstance.
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.
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.