1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-16 21:31:45 +02:00
Files
.config
.run
.workdir
Agent
Common
Docker
Server
Phantom.Server
AgentTokenFile.cs
CertificateFiles.cs
Phantom.Server.csproj
Program.cs
Variables.cs
WebConfigurator.cs
Phantom.Server.Database
Phantom.Server.Database.Postgres
Phantom.Server.Rpc
Phantom.Server.Services
Phantom.Server.Web
Phantom.Server.Web.Bootstrap
Phantom.Server.Web.Components
Utils
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
PhantomPanel.sln
global.json
Minecraft-Phantom-Panel/Server/Phantom.Server/AgentTokenFile.cs

38 lines
1.0 KiB
C#

using Phantom.Common.Data.Agent;
using Phantom.Common.Logging;
using Serilog;
namespace Phantom.Server;
static class AgentTokenFile {
private static ILogger Logger { get; } = PhantomLogger.Create(typeof(AgentTokenFile));
private const string TokenFileName = "agent.token";
public static async Task<AgentAuthToken?> CreateOrLoad(string folderPath) {
string filePath = Path.Combine(folderPath, TokenFileName);
if (File.Exists(filePath)) {
try {
var token = await AgentAuthToken.ReadFromFile(filePath);
Logger.Information("Loaded existing agent token file.");
return token;
} catch (Exception e) {
Logger.Fatal("Error reading agent token file: {Message}", e.Message);
return null;
}
}
Logger.Information("Creating agent token file: {FilePath}", filePath);
try {
var agentToken = AgentAuthToken.Generate();
await agentToken.WriteToFile(filePath);
return agentToken;
} catch (Exception e) {
Logger.Fatal("Error creating agent token file: {Message}", e.Message);
return null;
}
}
}