25 lines
749 B
C#
25 lines
749 B
C#
using Microsoft.Extensions.Options;
|
|
using MxGateway.Server.Configuration;
|
|
|
|
namespace MxGateway.Server.Security.Authentication;
|
|
|
|
public sealed class AuthStoreMigrationHostedService(
|
|
IOptions<GatewayOptions> options,
|
|
IAuthStoreMigrator migrator) : IHostedService
|
|
{
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
AuthenticationOptions authentication = options.Value.Authentication;
|
|
|
|
if (authentication.Mode == AuthenticationMode.ApiKey && authentication.RunMigrationsOnStartup)
|
|
{
|
|
await migrator.MigrateAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|