feat(backtests): separate saving from retry-safe run submission
This commit is contained in:
parent
5eb0985057
commit
9b9403e36b
18 changed files with 1200 additions and 226 deletions
|
|
@ -2,6 +2,12 @@ import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypt
|
|||
import type { Hono, MiddlewareHandler } from 'hono';
|
||||
|
||||
type Role = 'read' | 'admin' | 'service';
|
||||
const verifiedPrincipals = new WeakMap<Request, 'operator' | 'service'>();
|
||||
|
||||
/** Server-owned identity established only after successful HTTP authorization. */
|
||||
export function getVerifiedHttpPrincipal(request: Request): 'operator' | 'service' | undefined {
|
||||
return verifiedPrincipals.get(request);
|
||||
}
|
||||
export interface HttpSecurityOptions {
|
||||
readToken?: string;
|
||||
adminToken?: string;
|
||||
|
|
@ -142,6 +148,7 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
return { role, cookie: true };
|
||||
}
|
||||
function authorize(request: Request, admin = false): Response | undefined {
|
||||
verifiedPrincipals.delete(request);
|
||||
const identity = authenticate(request);
|
||||
if (!identity) {
|
||||
return Response.json(
|
||||
|
|
@ -161,6 +168,9 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
) {
|
||||
return Response.json({ error: 'Untrusted request origin' }, { status: 403 });
|
||||
}
|
||||
if (identity.role !== 'read') {
|
||||
verifiedPrincipals.set(request, identity.role === 'service' ? 'service' : 'operator');
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
const middleware: MiddlewareHandler = async (context, next) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue