Namespaces, assemblies, projects and directories, the solution, binaries, images, systemd units, config paths, environment variables, protocol method names, the media type and the raw chunk magic all move to MoShiro/moshiro. Existing data and deployments are not compatible and must be recreated. Also fix the architecture tests after the solution layout change and make the update tests independent of their order.
44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using System.Text.Json.Nodes;
|
|
using Fleet.Core;
|
|
using Fleet.Enrollment.Client;
|
|
|
|
// fleet-enroll --server https://panel --join jt_xxx --name jp-1 --identity-dir /etc/moshiro [--meta '{"probe_tcp_port":7443,...}'] [--version 1.0]
|
|
// 一次性运行:生成身份、注册、写入身份目录,然后退出。
|
|
string? Arg(string name) => args.SkipWhile(a => a != name).Skip(1).FirstOrDefault();
|
|
|
|
string? server = Arg("--server");
|
|
string? join = Arg("--join");
|
|
string? name = Arg("--name");
|
|
string? directory = Arg("--identity-dir");
|
|
if (server is null || join is null || name is null || directory is null)
|
|
{
|
|
Console.Error.WriteLine("usage: fleet-enroll --server <url> --join <token> --name <node name> --identity-dir <dir> [--meta <json>] [--version <v>]");
|
|
return 2;
|
|
}
|
|
|
|
JsonNode? meta = null;
|
|
if (Arg("--meta") is { } metaText)
|
|
{
|
|
try
|
|
{
|
|
meta = JsonNode.Parse(metaText);
|
|
}
|
|
catch (System.Text.Json.JsonException ex)
|
|
{
|
|
Console.Error.WriteLine("--meta is not valid JSON: " + ex.Message);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
|
|
Result<EnrollmentResult> result = await EnrollmentClient.EnrollAsync(
|
|
http, new Uri(server), join, name, directory, Arg("--version") ?? "0.0.0", meta, TimeProvider.System, CancellationToken.None);
|
|
if (!result.TryGet(out EnrollmentResult? enrolled, out FleetError? error))
|
|
{
|
|
Console.Error.WriteLine($"enrollment failed ({error.Code}): {error.Message}");
|
|
return 1;
|
|
}
|
|
|
|
Console.WriteLine($"enrolled as {enrolled.NodeId} ({enrolled.Status}); identity written to {enrolled.IdentityDirectory}");
|
|
return 0;
|