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

62 lines
1.9 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,
string WorkspacesDirectory)
{
internal static NodePaths ForCurrentMachine()
{
var root = NodeDataRootSettings.Resolve().RootDirectory;
return new NodePaths(
root,
Path.Combine(root, "node.json"),
Path.Combine(root, "jobs"),
Path.Combine(root, "workspaces"));
}
}
internal sealed class NodeConfigurationException(string message) : Exception(message);
internal sealed class NodeEndpointException(string message) : Exception(message);
internal sealed record WorkspaceBinding(
Guid WorkspaceId,
Guid? SourceJobId,
string Mode);