diff --git a/Wabbajack.Server/ApiKeyAuthorizationHandler.cs b/Wabbajack.Server/ApiKeyAuthorizationHandler.cs index ad4835fb..de142d06 100644 --- a/Wabbajack.Server/ApiKeyAuthorizationHandler.cs +++ b/Wabbajack.Server/ApiKeyAuthorizationHandler.cs @@ -9,7 +9,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Wabbajack.DTOs.JsonConverters; +using Wabbajack.Paths; +using Wabbajack.Paths.IO; using Wabbajack.Server.DataModels; +using Wabbajack.Server.DTOs; namespace Wabbajack.BuildServer; @@ -27,6 +30,9 @@ public class ApiKeyAuthenticationHandler : AuthenticationHandler> _tarKeys; + private readonly Metrics _metricsStore; + private readonly TarLog _tarLog; public ApiKeyAuthenticationHandler( IOptionsMonitor options, @@ -35,8 +41,13 @@ public class ApiKeyAuthenticationHandler : AuthenticationHandler> _tarKeys; + private readonly AppSettings _settings; + + public TarLog(AppSettings settings) + { + _settings = settings; + Load(); + } + + private void Load() + { + if (_settings.TarKeyFile.ToAbsolutePath().FileExists()) + { + _tarKeys = Task.Run(async () => await _settings.TarKeyFile.ToAbsolutePath() + .ReadAllLinesAsync() + .Select(line => line.Trim()) + .ToHashSetAsync()); + } + else + { + _tarKeys = Task.Run(async () => new HashSet()); + } + } + + public async Task Contains(string metricsKey) + { + return (await _tarKeys).Contains(metricsKey); + } + + +} \ No newline at end of file