Merge remote-tracking branch 'origin/main'

# Conflicts:
#	Wabbajack.CLI/Verbs/SetNexusApiKey.cs
This commit is contained in:
halgari 2024-05-30 17:04:17 -06:00
commit 749baf1bdf
10 changed files with 17 additions and 16 deletions

View File

@ -1,5 +1,8 @@
### Changelog ### Changelog
#### Version - 3.6.1.1 - TBD
* Fixed `set-nexus-api-key` CLI command
#### Version - 3.6.1.0 - 5/26/2024 #### Version - 3.6.1.0 - 5/26/2024
* Fixed a race condition on renewing Nexus Mods OAuth2 tokens * Fixed a race condition on renewing Nexus Mods OAuth2 tokens
* Added `set-nexus-api-key` CLI command * Added `set-nexus-api-key` CLI command

View File

@ -94,7 +94,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2478.35" /> <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2478.35" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="Orc.FileAssociation" Version="5.0.0-alpha0061" /> <PackageReference Include="Orc.FileAssociation" Version="5.0.0" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" /> <PackageReference Include="PInvoke.User32" Version="0.7.124" />
<PackageReference Include="ReactiveUI" Version="19.5.1" /> <PackageReference Include="ReactiveUI" Version="19.5.1" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.1" /> <PackageReference Include="ReactiveUI.Fody" Version="19.5.1" />

View File

@ -1,13 +1,7 @@
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.NamingConventionBinder;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Wabbajack.CLI.Builder; using Wabbajack.CLI.Builder;
using Wabbajack.DTOs.Logins; using Wabbajack.DTOs.Logins;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated; using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.CLI.Verbs; namespace Wabbajack.CLI.Verbs;
@ -23,7 +17,7 @@ public class SetNexusApiKey
_logger = logger; _logger = logger;
} }
public static VerbDefinition Definition = new VerbDefinition("set-nexus-api-key", public static VerbDefinition Definition = new("set-nexus-api-key",
"Sets the Nexus API key to the specified value", "Sets the Nexus API key to the specified value",
[ [
new OptionDefinition(typeof(string), "k", "key", "The Nexus API key") new OptionDefinition(typeof(string), "k", "key", "The Nexus API key")
@ -38,7 +32,7 @@ public class SetNexusApiKey
} }
else else
{ {
await _tokenProvider.SetToken(new NexusOAuthState { ApiKey = key }); await _tokenProvider.SetToken(new() { ApiKey = key });
_logger.LogInformation("Set Nexus API Key to {key}", key); _logger.LogInformation("Set Nexus API Key to {key}", key);
return 0; return 0;
} }

View File

@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.5" /> <PackageReference Include="NLog" Version="5.2.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.2" /> <PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> <PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" /> <PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
</ItemGroup> </ItemGroup>

View File

@ -148,8 +148,9 @@ public class DownloadDispatcher
return result; return result;
} }
catch (HttpException) catch (HttpException ex)
{ {
_logger.LogError($"Failed verifying {a.State.PrimaryKeyString}: {ex}");
await _verificationCache.Put(a.State, false); await _verificationCache.Put(a.State, false);
return false; return false;
} }

View File

@ -217,8 +217,9 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
return fileInfo.info.FileId == state.FileID; return fileInfo.info.FileId == state.FileID;
} }
catch (HttpException) catch (HttpException ex)
{ {
_logger.LogError($"HttpException: {ex} on {archive.Name}");
return false; return false;
} }
} }

View File

@ -14,7 +14,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" /> <PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shipwreck.Phash" Version="0.5.0" /> <PackageReference Include="Shipwreck.Phash" Version="0.5.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.2" /> <PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="xunit" Version="2.6.1" /> <PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -3,6 +3,6 @@ using Wabbajack.Networking.Http.Interfaces;
namespace Wabbajack.Networking.NexusApi; namespace Wabbajack.Networking.NexusApi;
public interface AuthInfo : ITokenProvider<NexusOAuthState> public interface IAuthInfo : ITokenProvider<NexusOAuthState>
{ {
} }

View File

@ -188,7 +188,6 @@ public class NexusApi
protected virtual async ValueTask<HttpRequestMessage> GenerateMessage(HttpMethod method, string uri, protected virtual async ValueTask<HttpRequestMessage> GenerateMessage(HttpMethod method, string uri,
params object?[] parameters) params object?[] parameters)
{ {
using var _ = await _authLock.WaitAsync();
var msg = new HttpRequestMessage(); var msg = new HttpRequestMessage();
msg.Method = method; msg.Method = method;
@ -232,6 +231,7 @@ public class NexusApi
private async ValueTask<(bool IsApiKey, string code)> GetAuthInfo() private async ValueTask<(bool IsApiKey, string code)> GetAuthInfo()
{ {
using var _ = await _authLock.WaitAsync();
if (AuthInfo.HaveToken()) if (AuthInfo.HaveToken())
{ {
var info = await AuthInfo.Get(); var info = await AuthInfo.Get();
@ -272,6 +272,8 @@ public class NexusApi
var response = await _client.PostAsync($"https://users.nexusmods.com/oauth/token", content, cancel); var response = await _client.PostAsync($"https://users.nexusmods.com/oauth/token", content, cancel);
var responseString = await response.Content.ReadAsStringAsync(cancel); var responseString = await response.Content.ReadAsStringAsync(cancel);
var newJwt = JsonSerializer.Deserialize<JwtTokenReply>(responseString); var newJwt = JsonSerializer.Deserialize<JwtTokenReply>(responseString);
if (newJwt != null)
newJwt.ReceivedAt = DateTime.UtcNow.ToFileTimeUtc();
state.OAuth = newJwt; state.OAuth = newJwt;
await AuthInfo.SetToken(state); await AuthInfo.SetToken(state);

View File

@ -5,7 +5,7 @@ using Wabbajack.Networking.NexusApi;
namespace Wabbajack.Services.OSIntegrated.TokenProviders; namespace Wabbajack.Services.OSIntegrated.TokenProviders;
public class NexusApiTokenProvider : EncryptedJsonTokenProvider<NexusOAuthState>, AuthInfo public class NexusApiTokenProvider : EncryptedJsonTokenProvider<NexusOAuthState>, IAuthInfo
{ {
public NexusApiTokenProvider(ILogger<NexusApiTokenProvider> logger, DTOSerializer dtos) : base(logger, dtos, public NexusApiTokenProvider(ILogger<NexusApiTokenProvider> logger, DTOSerializer dtos) : base(logger, dtos,
"nexus-oauth-info") "nexus-oauth-info")