up
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Routing;
|
||||
using StellaOps.Replay.Core;
|
||||
using StellaOps.Scanner.ProofSpine;
|
||||
using StellaOps.Scanner.WebService.Contracts;
|
||||
using StellaOps.Scanner.WebService.Serialization;
|
||||
using StellaOps.Scanner.WebService.Security;
|
||||
|
||||
namespace StellaOps.Scanner.WebService.Endpoints;
|
||||
@@ -17,6 +18,7 @@ internal static class ProofSpineEndpoints
|
||||
spines.MapGet("/{spineId}", HandleGetSpineAsync)
|
||||
.WithName("scanner.spines.get")
|
||||
.Produces<ProofSpineResponseDto>(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status200OK, contentType: CborNegotiation.ContentType)
|
||||
.Produces(StatusCodes.Status404NotFound)
|
||||
.RequireAuthorization(ScannerPolicies.ScansRead);
|
||||
|
||||
@@ -24,15 +26,18 @@ internal static class ProofSpineEndpoints
|
||||
scans.MapGet("/{scanId}/spines", HandleListSpinesAsync)
|
||||
.WithName("scanner.spines.list-by-scan")
|
||||
.Produces<ProofSpineListResponseDto>(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status200OK, contentType: CborNegotiation.ContentType)
|
||||
.RequireAuthorization(ScannerPolicies.ScansRead);
|
||||
}
|
||||
|
||||
private static async Task<IResult> HandleGetSpineAsync(
|
||||
HttpRequest request,
|
||||
string spineId,
|
||||
IProofSpineRepository repository,
|
||||
ProofSpineVerifier verifier,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(repository);
|
||||
ArgumentNullException.ThrowIfNull(verifier);
|
||||
|
||||
@@ -93,19 +98,36 @@ internal static class ProofSpineEndpoints
|
||||
}
|
||||
};
|
||||
|
||||
if (CborNegotiation.AcceptsCbor(request))
|
||||
{
|
||||
return Results.Bytes(
|
||||
DeterministicCborSerializer.Serialize(dto),
|
||||
contentType: CborNegotiation.ContentType);
|
||||
}
|
||||
|
||||
return Results.Ok(dto);
|
||||
}
|
||||
|
||||
private static async Task<IResult> HandleListSpinesAsync(
|
||||
HttpRequest request,
|
||||
string scanId,
|
||||
IProofSpineRepository repository,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(repository);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(scanId))
|
||||
{
|
||||
return Results.Ok(new ProofSpineListResponseDto { Items = Array.Empty<ProofSpineSummaryDto>(), Total = 0 });
|
||||
var empty = new ProofSpineListResponseDto { Items = Array.Empty<ProofSpineSummaryDto>(), Total = 0 };
|
||||
if (CborNegotiation.AcceptsCbor(request))
|
||||
{
|
||||
return Results.Bytes(
|
||||
DeterministicCborSerializer.Serialize(empty),
|
||||
contentType: CborNegotiation.ContentType);
|
||||
}
|
||||
|
||||
return Results.Ok(empty);
|
||||
}
|
||||
|
||||
var summaries = await repository.GetSummariesByScanRunAsync(scanId, cancellationToken).ConfigureAwait(false);
|
||||
@@ -119,11 +141,20 @@ internal static class ProofSpineEndpoints
|
||||
CreatedAt = summary.CreatedAt
|
||||
}).ToArray();
|
||||
|
||||
return Results.Ok(new ProofSpineListResponseDto
|
||||
var response = new ProofSpineListResponseDto
|
||||
{
|
||||
Items = items,
|
||||
Total = items.Length
|
||||
});
|
||||
};
|
||||
|
||||
if (CborNegotiation.AcceptsCbor(request))
|
||||
{
|
||||
return Results.Bytes(
|
||||
DeterministicCborSerializer.Serialize(response),
|
||||
contentType: CborNegotiation.ContentType);
|
||||
}
|
||||
|
||||
return Results.Ok(response);
|
||||
}
|
||||
|
||||
private static DsseEnvelopeDto MapEnvelope(DsseEnvelope envelope)
|
||||
@@ -163,4 +194,3 @@ internal static class ProofSpineEndpoints
|
||||
return "/" + trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user