2024-05-16 16:52:33 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Wabbajack.CLI.Builder;
|
|
|
|
using Wabbajack.DTOs.Logins;
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
|
|
|
public class SetNexusApiKey
|
|
|
|
{
|
2024-05-28 16:45:03 +00:00
|
|
|
private readonly EncryptedJsonTokenProvider<NexusOAuthState> _tokenProvider;
|
2024-05-16 16:52:33 +00:00
|
|
|
private readonly ILogger<SetNexusApiKey> _logger;
|
|
|
|
|
2024-05-28 16:45:03 +00:00
|
|
|
public SetNexusApiKey(EncryptedJsonTokenProvider<NexusOAuthState> tokenProvider, ILogger<SetNexusApiKey> logger)
|
2024-05-16 16:52:33 +00:00
|
|
|
{
|
|
|
|
_tokenProvider = tokenProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-05-28 16:45:03 +00:00
|
|
|
public static VerbDefinition Definition = new("set-nexus-api-key",
|
2024-05-16 16:52:33 +00:00
|
|
|
"Sets the Nexus API key to the specified value",
|
2024-05-16 19:50:49 +00:00
|
|
|
[
|
2024-05-16 16:52:33 +00:00
|
|
|
new OptionDefinition(typeof(string), "k", "key", "The Nexus API key")
|
2024-05-16 19:50:49 +00:00
|
|
|
]);
|
2024-05-16 16:52:33 +00:00
|
|
|
|
|
|
|
public async Task<int> Run(string key)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(key))
|
|
|
|
{
|
|
|
|
_logger.LogInformation("Not setting Nexus API key, that looks like an empty string to me.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-28 16:45:03 +00:00
|
|
|
await _tokenProvider.SetToken(new() { ApiKey = key });
|
2024-05-16 16:52:33 +00:00
|
|
|
_logger.LogInformation("Set Nexus API Key to {key}", key);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|