@app-vitals/agent-admin 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/openapi.json +193 -0
- package/openapi.platform.json +193 -0
- package/package.json +2 -2
- package/src/admin-boot.ts +15 -2
- package/src/admin-ui-github-identity-pages.ts +163 -0
- package/src/admin-ui-github-identity-pages.unit.test.ts +220 -0
- package/src/admin-ui-github-identity.smoke.test.ts +205 -0
- package/src/admin-ui-pages.ts +17 -2
- package/src/admin-ui.smoke.test.ts +2 -2
- package/src/admin-ui.ts +135 -1
- package/src/agents-api.smoke.test.ts +144 -0
- package/src/agents-api.ts +88 -0
- package/src/github-access-preview.integration.test.ts +364 -0
- package/src/github-access-preview.ts +19 -0
- package/src/github-enterprise-api.ts +64 -0
|
@@ -29,6 +29,7 @@ import type { AgentTokenService } from "./agent-tokens.ts";
|
|
|
29
29
|
import type { AgentService } from "./agents.ts";
|
|
30
30
|
import {
|
|
31
31
|
ApiError,
|
|
32
|
+
BadGatewayError,
|
|
32
33
|
ConflictError,
|
|
33
34
|
ForbiddenError,
|
|
34
35
|
NotFoundError,
|
|
@@ -47,7 +48,10 @@ import {
|
|
|
47
48
|
type GitHubEnterpriseAppRole,
|
|
48
49
|
type GitHubEnterpriseAppService,
|
|
49
50
|
} from "./github-enterprise-apps.ts";
|
|
51
|
+
import { GithubLookupClient } from "./github-lookup-client.ts";
|
|
52
|
+
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
50
53
|
import { ErrorSchema } from "./openapi-schemas.ts";
|
|
54
|
+
import { UserRepoAccessResolver } from "./user-repo-access-resolver.ts";
|
|
51
55
|
|
|
52
56
|
// ─── Deps ─────────────────────────────────────────────────────────────────────
|
|
53
57
|
|
|
@@ -423,6 +427,66 @@ function serializeApp(m: GitHubEnterpriseAppMetadata) {
|
|
|
423
427
|
};
|
|
424
428
|
}
|
|
425
429
|
|
|
430
|
+
// ─── Access preview (GHE-2.4) ─────────────────────────────────────────────────
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Backs GET /agents/:id/github-access. Unconfigured (either App missing, or a
|
|
434
|
+
* stored App without its key / enterprise slug) returns before any GitHub
|
|
435
|
+
* call. A GitHub failure while listing orgs is rethrown as a 502 carrying only
|
|
436
|
+
* the mapped, non-leaky message.
|
|
437
|
+
*/
|
|
438
|
+
export function createGithubAccessPreview(
|
|
439
|
+
deps: Pick<
|
|
440
|
+
GithubEnterpriseApiDeps,
|
|
441
|
+
"appService" | "fetchFn" | "apiBase" | "now"
|
|
442
|
+
>,
|
|
443
|
+
): GithubAccessPreviewFn {
|
|
444
|
+
return async (username) => {
|
|
445
|
+
const [installer, lookup] = await Promise.all([
|
|
446
|
+
deps.appService.get("installer"),
|
|
447
|
+
deps.appService.get("lookup"),
|
|
448
|
+
]);
|
|
449
|
+
if (!installer || !lookup || !installer.enterpriseSlug) {
|
|
450
|
+
return { status: "unconfigured" };
|
|
451
|
+
}
|
|
452
|
+
const [installerKey, lookupKey] = await Promise.all([
|
|
453
|
+
deps.appService.getPrivateKey("installer"),
|
|
454
|
+
deps.appService.getPrivateKey("lookup"),
|
|
455
|
+
]);
|
|
456
|
+
if (!installerKey || !lookupKey) return { status: "unconfigured" };
|
|
457
|
+
|
|
458
|
+
const common = {
|
|
459
|
+
apiBase: deps.apiBase,
|
|
460
|
+
fetchFn: deps.fetchFn,
|
|
461
|
+
now: deps.now,
|
|
462
|
+
};
|
|
463
|
+
const resolver = new UserRepoAccessResolver({
|
|
464
|
+
installer: new GithubEnterpriseClient({
|
|
465
|
+
appId: installer.appId,
|
|
466
|
+
enterprise: installer.enterpriseSlug,
|
|
467
|
+
privateKey: installerKey,
|
|
468
|
+
...common,
|
|
469
|
+
}),
|
|
470
|
+
lookup: new GithubLookupClient({
|
|
471
|
+
appId: lookup.appId,
|
|
472
|
+
privateKey: lookupKey,
|
|
473
|
+
...common,
|
|
474
|
+
}),
|
|
475
|
+
now: deps.now,
|
|
476
|
+
});
|
|
477
|
+
try {
|
|
478
|
+
const access = await resolver.resolve(username);
|
|
479
|
+
return { status: access.outcome, access };
|
|
480
|
+
} catch (err) {
|
|
481
|
+
if (err instanceof GithubEnterpriseError) {
|
|
482
|
+
throw new BadGatewayError(mapEnterpriseFailure(err.kind).message);
|
|
483
|
+
}
|
|
484
|
+
// Anything else (e.g. JWT signing): generic, no detail.
|
|
485
|
+
throw new BadGatewayError("GitHub access could not be resolved.");
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
426
490
|
// ─── App ──────────────────────────────────────────────────────────────────────
|
|
427
491
|
|
|
428
492
|
export function createGithubEnterpriseApp(
|