File size: 937 Bytes
17c0464 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import {Hono} from 'hono';
import {TestRunGithubApp} from '../../services/test-run-github-app';
import {createTestHostAuth, type TestHostEnv} from '../middleware/test-host-auth.middleware';
import {configuredTestingTarget} from '../../types/testing-source.types';
/** Enrolled controllers refresh org runner authority; no App key leaves Core. */
export function createTestingDispatchApi(appCredentials: Pick<TestRunGithubApp, 'runnerCredential'> = new TestRunGithubApp(),
credentials?: () => string | undefined) {
const app = new Hono<TestHostEnv>();
app.use('*', async (c, next) => {c.header('Cache-Control', 'no-store'); await next();});
app.use('*', createTestHostAuth(credentials));
app.onError((_error, c) => c.json({error: 'runner_credential_unavailable'}, 503));
app.post('/runner-token', async c => c.json(await appCredentials.runnerCredential(configuredTestingTarget().repository)));
return app;
}
|