Files
git.stella-ops.org/src/Policy/StellaOps.Policy.Engine/Endpoints/OrchestratorJobEndpoint.cs
StellaOps Bot 150b3730ef
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
up
2025-11-24 07:52:25 +02:00

63 lines
2.0 KiB
C#

using Microsoft.AspNetCore.Mvc;
using StellaOps.Policy.Engine.Orchestration;
namespace StellaOps.Policy.Engine.Endpoints;
public static class OrchestratorJobEndpoint
{
public static IEndpointRouteBuilder MapOrchestratorJobs(this IEndpointRouteBuilder routes)
{
routes.MapPost("/policy/orchestrator/jobs", SubmitAsync)
.WithName("PolicyEngine.Orchestrator.Jobs.Submit");
routes.MapPost("/policy/orchestrator/jobs/preview", PreviewAsync)
.WithName("PolicyEngine.Orchestrator.Jobs.Preview");
routes.MapGet("/policy/orchestrator/jobs/{jobId}", GetAsync)
.WithName("PolicyEngine.Orchestrator.Jobs.Get");
return routes;
}
private static async Task<IResult> SubmitAsync(
[FromBody] OrchestratorJobRequest request,
OrchestratorJobService service,
CancellationToken cancellationToken)
{
try
{
var job = await service.SubmitAsync(request, cancellationToken).ConfigureAwait(false);
return Results.Json(job);
}
catch (ArgumentException ex)
{
return Results.BadRequest(new { message = ex.Message });
}
}
private static async Task<IResult> PreviewAsync(
[FromBody] OrchestratorJobRequest request,
OrchestratorJobService service,
CancellationToken cancellationToken)
{
try
{
var job = await service.PreviewAsync(request, cancellationToken).ConfigureAwait(false);
return Results.Json(job);
}
catch (ArgumentException ex)
{
return Results.BadRequest(new { message = ex.Message });
}
}
private static async Task<IResult> GetAsync(
[FromRoute] string jobId,
OrchestratorJobService service,
CancellationToken cancellationToken)
{
var job = await service.GetAsync(jobId, cancellationToken).ConfigureAwait(false);
return job is null ? Results.NotFound() : Results.Json(job);
}
}