-
Notifications
You must be signed in to change notification settings - Fork 409
refactor: migrate control plane routing to Hono #1716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { BetterAuthRuntime } from "./user/runtime"; | ||
| import type { SqlDatabase } from "../db/sql-database"; | ||
| import type { CorrelationContext } from "../logger"; | ||
|
|
||
| /** | ||
| * Narrow request-scoped capabilities required by authentication. | ||
| * | ||
| * Core authentication deliberately depends on this auth-owned port instead | ||
| * of the aggregate route/admission context. | ||
| */ | ||
| export interface AuthenticationRequestServices extends CorrelationContext { | ||
| db: SqlDatabase; | ||
| getUserAuth?: () => BetterAuthRuntime; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { getUserAuth, getUserAuthRuntime } from "../auth/user/runtime"; | ||
| import { createRequestMetrics, instrumentD1 } from "../db/instrumented-d1"; | ||
| import type { SqlDatabase } from "../db/sql-database"; | ||
| import type { BackgroundTasks } from "../platform-ports"; | ||
| import type { Env } from "../types"; | ||
| import type { RequestContext } from "./request-context"; | ||
|
|
||
| /** Assemble framework-neutral per-request state after the DB guard passes. */ | ||
| export function createRequestContext(input: { | ||
| request: Request; | ||
| env: Env; | ||
| database: SqlDatabase; | ||
| executionCtx: BackgroundTasks; | ||
| }): RequestContext { | ||
| const { request, env, database, executionCtx } = input; | ||
| const metrics = createRequestMetrics(); | ||
|
|
||
| return { | ||
| trace_id: request.headers.get("x-trace-id") || crypto.randomUUID(), | ||
| request_id: crypto.randomUUID().slice(0, 8), | ||
| metrics, | ||
| db: instrumentD1(database, metrics), | ||
| // The stable uninstrumented binding remains the Better Auth cache key. | ||
| getUserAuth: () => getUserAuth(env, database), | ||
| getUserAuthRuntime: () => getUserAuthRuntime(env, database), | ||
| executionCtx, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { EffectiveAuthorization } from "@open-inspect/shared/rbac"; | ||
| import type { AuthenticationContext, Principal } from "../auth/principal"; | ||
| import type { AuthenticationRequestServices } from "../auth/request-services"; | ||
| import type { UserAuthRuntime } from "../auth/user/runtime"; | ||
| import type { AutomationRow } from "../db/automation-store"; | ||
| import type { RequestMetrics } from "../db/instrumented-d1"; | ||
| import type { BackgroundTasks } from "../platform-ports"; | ||
|
|
||
| /** Automation resource admitted for the current mutation. */ | ||
| export interface AutomationRouteAdmission { | ||
| automation: AutomationRow; | ||
| } | ||
|
|
||
| /** | ||
| * Framework-neutral aggregate state assembled at the HTTP composition root. | ||
| * Authentication consumes only its narrower AuthenticationRequestServices | ||
| * projection, preventing auth from depending on route or Hono contracts. | ||
| */ | ||
| export type RequestContext = AuthenticationRequestServices & { | ||
| metrics: RequestMetrics; | ||
| executionCtx: BackgroundTasks; | ||
| getUserAuthRuntime?: () => UserAuthRuntime; | ||
| principal?: Principal; | ||
| authentication?: AuthenticationContext; | ||
| authorization?: EffectiveAuthorization; | ||
| automationAdmission?: AutomationRouteAdmission; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** Create a JSON response without framework-added content-type parameters. */ | ||
| export function json(data: unknown, status = 200): Response { | ||
| return new Response(JSON.stringify(data), { | ||
| status, | ||
| headers: { "Content-Type": "application/json" }, | ||
| }); | ||
| } | ||
|
|
||
| /** Create the control plane's standard JSON error envelope. */ | ||
| export function error(message: string, status = 400): Response { | ||
| return json({ error: message }, status); | ||
| } | ||
|
|
||
| /** | ||
| * Raise from a route handler or helper to request a specific HTTP response. | ||
| * The route handler boundary maps this without exposing framework errors. | ||
| */ | ||
| export class HttpError extends Error { | ||
| constructor( | ||
| message: string, | ||
| readonly status: number | ||
| ) { | ||
| super(message); | ||
| this.name = "HttpError"; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.