zcbot/windows-node/Zcbot.WindowsNode/NodeModels.cs

52 lines
1.8 KiB
C#

using System.Text.Json.Serialization;
namespace Zcbot.WindowsNode;
internal sealed record NodeConfig(
Uri ServerUrl,
Guid NodeId,
Guid InstallId,
string NodeName,
string NodeToken,
int HeartbeatSeconds,
IReadOnlyList<string> Capabilities);
internal sealed record StoredNodeConfig(
string ServerUrl,
Guid NodeId,
Guid InstallId,
string NodeName,
string ProtectedNodeToken,
int HeartbeatSeconds,
IReadOnlyList<string> Capabilities);
internal sealed record EnrollRequest(
[property: JsonPropertyName("enrollment_code")] string EnrollmentCode,
[property: JsonPropertyName("node_name")] string NodeName,
[property: JsonPropertyName("install_id")] Guid InstallId,
[property: JsonPropertyName("node_version")] string NodeVersion,
[property: JsonPropertyName("os_version")] string OsVersion,
[property: JsonPropertyName("capabilities")] IReadOnlyList<string> Capabilities);
internal sealed record EnrollResponse(
[property: JsonPropertyName("node_id")] Guid NodeId,
[property: JsonPropertyName("node_token")] string NodeToken,
[property: JsonPropertyName("heartbeat_seconds")] int HeartbeatSeconds,
[property: JsonPropertyName("max_concurrency")] int MaxConcurrency);
internal sealed record NodePaths(string RootDirectory, string ConfigPath, string JobsDirectory)
{
internal static NodePaths ForCurrentMachine()
{
var root = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"Zcbot", "WindowsNode");
return new NodePaths(
root, Path.Combine(root, "node.json"), Path.Combine(root, "jobs"));
}
}
internal sealed class NodeConfigurationException(string message) : Exception(message);
internal sealed class NodeEndpointException(string message) : Exception(message);