Files
MoShiro/backend/fleet/src/Fleet.Server.Enrollment/EnrollmentModels.cs
T
2026-10-07 16:57:34 +08:00

74 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Fleet.Server;
public sealed class EnrollRequest
{
[JsonPropertyName("join_token")]
public string JoinToken { get; set; } = "";
[JsonPropertyName("name")]
public string Name { get; set; } = "";
/// <summary>身份公钥(SPKI,base64)。</summary>
[JsonPropertyName("pubkey")]
public string PublicKey { get; set; } = "";
/// <summary>面向对端节点的 TLS 证书指纹(SHA-256,base64)。</summary>
[JsonPropertyName("tls_spki")]
public string TlsSpki { get; set; } = "";
/// <summary>
/// 同一把 TLS 密钥的完整公钥(SPKI,base64),必须和 <see cref="TlsSpki"/> 对得上。节点用这把密钥做对等面的签名认证
/// (和连服务端用的身份密钥是两把独立的密钥),对端要验签就需要完整的公钥,而不只是指纹。
/// </summary>
[JsonPropertyName("tls_pubkey")]
public string TlsPublicKey { get; set; } = "";
/// <summary>持有证明:对 <c>fleet|v1|enroll|{sha256_hex(join_token)}|{pubkey}</c> 的签名(base64)。</summary>
[JsonPropertyName("proof")]
public string Proof { get; set; } = "";
[JsonPropertyName("node_version")]
public string NodeVersion { get; set; } = "";
[JsonPropertyName("meta")]
public JsonElement? Meta { get; set; }
}
public sealed class EnrollResponse
{
[JsonPropertyName("node_id")]
public string NodeId { get; set; } = "";
/// <summary>pending | active</summary>
[JsonPropertyName("status")]
public string Status { get; set; } = "";
}
/// <summary>RFC 9457 problem+json,带 <c>code</c> 扩展字段。</summary>
public sealed class FleetProblem
{
[JsonPropertyName("type")]
public string Type { get; set; } = "about:blank";
[JsonPropertyName("title")]
public string Title { get; set; } = "";
[JsonPropertyName("status")]
public int Status { get; set; }
[JsonPropertyName("code")]
public string Code { get; set; } = "";
[JsonPropertyName("detail")]
public string? Detail { get; set; }
}
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(EnrollRequest))]
[JsonSerializable(typeof(EnrollResponse))]
[JsonSerializable(typeof(FleetProblem))]
internal sealed partial class EnrollmentJsonContext : JsonSerializerContext;