refactor(control): remove duplicate /nodes route for enrollment code
This commit is contained in:
parent
93eb507f7a
commit
55a19e9eea
2 changed files with 1 additions and 27 deletions
|
|
@ -629,32 +629,6 @@ control.MapPost("/agents/{nodeId}/enrollment-code", async (
|
||||||
return Results.Conflict(new ProblemDetails { Title = exception.Message });
|
return Results.Conflict(new ProblemDetails { Title = exception.Message });
|
||||||
}
|
}
|
||||||
}).RequireRateLimiting("enrollment");
|
}).RequireRateLimiting("enrollment");
|
||||||
control.MapPost("/nodes/{nodeId}/enrollment-code", async (
|
|
||||||
string nodeId,
|
|
||||||
HttpContext context,
|
|
||||||
NodeEnrollmentService enrollmentService,
|
|
||||||
CancellationToken cancellationToken) =>
|
|
||||||
{
|
|
||||||
if (!NodeIdValidator.IsValid(nodeId))
|
|
||||||
{
|
|
||||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
|
||||||
{
|
|
||||||
["nodeId"] = ["Node id must contain 1-63 lowercase letters, digits, or hyphens."]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var actor = context.User.FindFirstValue(ClaimTypes.NameIdentifier) ?? "unknown";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var response = await enrollmentService.CreateEnrollmentCodeAsync(
|
|
||||||
nodeId, actor, cancellationToken);
|
|
||||||
return Results.Ok(response);
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException exception)
|
|
||||||
{
|
|
||||||
return Results.Conflict(new ProblemDetails { Title = exception.Message });
|
|
||||||
}
|
|
||||||
}).RequireRateLimiting("enrollment");
|
|
||||||
control.MapGet("/agents", async (ControlStore controlStore, CancellationToken cancellationToken) =>
|
control.MapGet("/agents", async (ControlStore controlStore, CancellationToken cancellationToken) =>
|
||||||
Results.Ok((await controlStore.ListAgentsAsync(cancellationToken)).ToArray()));
|
Results.Ok((await controlStore.ListAgentsAsync(cancellationToken)).ToArray()));
|
||||||
control.MapGet("/provisioning/catalogs/system-base-install/1", () =>
|
control.MapGet("/provisioning/catalogs/system-base-install/1", () =>
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ public sealed class NodeEnrollmentCodeTests : IAsyncDisposable
|
||||||
await conn.OpenAsync(TestContext.Current.CancellationToken);
|
await conn.OpenAsync(TestContext.Current.CancellationToken);
|
||||||
var cmd = conn.CreateCommand();
|
var cmd = conn.CreateCommand();
|
||||||
cmd.CommandText = "SELECT COUNT(*) FROM enrollment_tokens;";
|
cmd.CommandText = "SELECT COUNT(*) FROM enrollment_tokens;";
|
||||||
var count = Convert.ToInt32(await cmd.ExecuteScalarAsync(TestContext.Current.CancellationToken));
|
var count = Convert.ToInt32(await cmd.ExecuteScalarAsync(TestContext.Current.CancellationToken), System.Globalization.CultureInfo.InvariantCulture);
|
||||||
Assert.Equal(0, count);
|
Assert.Equal(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue