- fix: auth renew and null fix
This commit is contained in:
@@ -2,16 +2,17 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Shared.Configurations.Migrations;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Shared.ConfigMigrations;
|
||||
|
||||
public class ProfileMigrationV2(string oldName, string newName)
|
||||
: BaseConfigurationMigration<ProfileAuthCredentialsV2[], AuthTokenCredentials[]>(oldName, newName)
|
||||
: BaseConfigurationMigration<ProfileAuthCredentials[], string[]>(oldName, newName)
|
||||
{
|
||||
protected override async Task<AuthTokenCredentials[]> Migrate(IServiceProvider serviceProvider, ProfileAuthCredentialsV2[] oldValue, ILoadingHandler loadingHandler)
|
||||
protected override async Task<string[]> Migrate(IServiceProvider serviceProvider, ProfileAuthCredentials[] oldValue, ILoadingHandler loadingHandler)
|
||||
{
|
||||
loadingHandler.SetLoadingMessage("Migrating Profile V2 -> V3");
|
||||
var list = new List<AuthTokenCredentials>();
|
||||
loadingHandler.SetLoadingMessage("Migrating Profile V2 -> V4");
|
||||
var list = new List<string>();
|
||||
var authService = serviceProvider.GetRequiredService<AuthService>();
|
||||
var logger = serviceProvider.GetRequiredService<DebugService>().GetLogger("ProfileMigrationV2");
|
||||
foreach (var oldCredentials in oldValue)
|
||||
@@ -19,8 +20,8 @@ public class ProfileMigrationV2(string oldName, string newName)
|
||||
try
|
||||
{
|
||||
loadingHandler.SetLoadingMessage($"Migrating {oldCredentials.Login}");
|
||||
var newCred = await authService.Auth(oldCredentials.Login, oldCredentials.Password, oldCredentials.AuthServer);
|
||||
list.Add(newCred);
|
||||
await authService.Auth(oldCredentials.Login, oldCredentials.Password, oldCredentials.AuthServer);
|
||||
list.Add(CryptographicStore.Encrypt(oldCredentials, CryptographicStore.GetComputerKey()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -34,7 +35,13 @@ public class ProfileMigrationV2(string oldName, string newName)
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ProfileAuthCredentialsV2(
|
||||
string Login,
|
||||
string Password,
|
||||
string AuthServer);
|
||||
public class ProfileMigrationV3V4(string oldName, string newName)
|
||||
: BaseConfigurationMigration<AuthTokenCredentials[], string[]>(oldName, newName)
|
||||
{
|
||||
protected override Task<string[]> Migrate(IServiceProvider serviceProvider, AuthTokenCredentials[] oldValue, ILoadingHandler loadingHandler)
|
||||
{
|
||||
Console.WriteLine("Removing profile v3 because no password is provided");
|
||||
return Task.FromResult(Array.Empty<string>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user