55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using System.Net.Http.Json;
|
|
|
|
namespace EntKube.Web.Components.Provisioning;
|
|
|
|
/// <summary>
|
|
/// BFF proxy endpoints for Harbor operations. The Blazor frontend calls these
|
|
/// endpoints to list Harbor projects and create pull secrets. Requests are
|
|
/// forwarded to the Clusters microservice which has direct Harbor API access.
|
|
/// </summary>
|
|
public static class HarborProxyEndpoints
|
|
{
|
|
public static void Map(IEndpointRouteBuilder app)
|
|
{
|
|
RouteGroupBuilder group = app.MapGroup("/api/harbor")
|
|
.RequireAuthorization()
|
|
.DisableAntiforgery();
|
|
|
|
// GET /api/harbor/{clusterId}/projects — list Harbor projects on a cluster.
|
|
|
|
group.MapGet("{clusterId:guid}/projects", async (
|
|
Guid clusterId,
|
|
IHttpClientFactory httpClientFactory,
|
|
CancellationToken ct) =>
|
|
{
|
|
HttpClient client = httpClientFactory.CreateClient("ClustersApi");
|
|
HttpResponseMessage response = await client.GetAsync(
|
|
$"/api/clusters/{clusterId}/harbor/projects", ct);
|
|
|
|
string body = await response.Content.ReadAsStringAsync(ct);
|
|
return Results.Content(body, "application/json", statusCode: (int)response.StatusCode);
|
|
});
|
|
|
|
// POST /api/harbor/{clusterId}/pull-secret — create a Harbor pull secret.
|
|
|
|
group.MapPost("{clusterId:guid}/pull-secret", async (
|
|
Guid clusterId,
|
|
CreateHarborPullSecretProxyRequest request,
|
|
IHttpClientFactory httpClientFactory,
|
|
CancellationToken ct) =>
|
|
{
|
|
HttpClient client = httpClientFactory.CreateClient("ClustersApi");
|
|
HttpResponseMessage response = await client.PostAsJsonAsync(
|
|
$"/api/clusters/{clusterId}/harbor/pull-secret", request, ct);
|
|
|
|
string body = await response.Content.ReadAsStringAsync(ct);
|
|
return Results.Content(body, "application/json", statusCode: (int)response.StatusCode);
|
|
});
|
|
}
|
|
}
|
|
|
|
public record CreateHarborPullSecretProxyRequest(
|
|
string ProjectName,
|
|
string AppSlug,
|
|
string TargetNamespace);
|