52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using EntKube.SharedKernel.Contracts;
|
|
using EntKube.SharedKernel.Domain;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EntKube.Clusters.Features.ClusterSettings;
|
|
|
|
/// <summary>
|
|
/// Maps the cluster settings endpoints:
|
|
/// GET /api/clusters/{id}/settings — read current settings from the live cluster
|
|
/// PUT /api/clusters/{id}/settings — update settings on the live cluster
|
|
///
|
|
/// These endpoints let the UI's Settings tab fetch and save cluster-level
|
|
/// configuration like allowed container registries without going through
|
|
/// the component configure flow.
|
|
/// </summary>
|
|
public static class ClusterSettingsEndpoint
|
|
{
|
|
public static void Map(IEndpointRouteBuilder app)
|
|
{
|
|
app.MapGet("/api/clusters/{id:guid}/settings", async (
|
|
Guid id,
|
|
[FromServices] GetClusterSettingsHandler handler,
|
|
CancellationToken ct) =>
|
|
{
|
|
Result<ClusterSettingsDto> result = await handler.HandleAsync(id, ct);
|
|
|
|
if (result.IsFailure)
|
|
{
|
|
return Results.BadRequest(ApiResponse<ClusterSettingsDto>.Fail(result.Error!));
|
|
}
|
|
|
|
return Results.Ok(ApiResponse<ClusterSettingsDto>.Ok(result.Value!));
|
|
});
|
|
|
|
app.MapPut("/api/clusters/{id:guid}/settings", async (
|
|
Guid id,
|
|
[FromBody] UpdateClusterSettingsRequest request,
|
|
[FromServices] UpdateClusterSettingsHandler handler,
|
|
CancellationToken ct) =>
|
|
{
|
|
Result result = await handler.HandleAsync(id, request, ct);
|
|
|
|
if (result.IsFailure)
|
|
{
|
|
return Results.BadRequest(ApiResponse<object>.Fail(result.Error!));
|
|
}
|
|
|
|
return Results.Ok(ApiResponse<object>.Ok(new { }));
|
|
});
|
|
}
|
|
}
|