@app-vitals/agent-admin 1.60.0 → 1.62.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.platform.json +75 -0
- package/package.json +2 -2
- package/prisma/client/browser.ts +5 -0
- package/prisma/client/client.ts +5 -0
- package/prisma/client/internal/class.ts +14 -4
- package/prisma/client/internal/prismaNamespace.ts +94 -1
- package/prisma/client/internal/prismaNamespaceBrowser.ts +18 -0
- package/prisma/client/models/Account.ts +164 -0
- package/prisma/client/models/SlackConfigToken.ts +1574 -0
- package/prisma/client/models.ts +1 -0
- package/prisma/migrations/20261115000000_add_slack_config_token/migration.sql +34 -0
- package/prisma/schema/schema.prisma +33 -1
- package/src/admin-ui-github-enterprise-pages.ts +88 -16
- package/src/admin-ui-github-enterprise.smoke.test.ts +135 -12
- package/src/admin-ui-github-enterprise.ts +59 -18
- package/src/admin-ui.ts +2 -1
- package/src/agents-api.ts +4 -1
- package/src/github-access-preview.ts +2 -0
- package/src/github-enterprise-api.smoke.test.ts +171 -27
- package/src/github-enterprise-api.ts +63 -25
- package/src/github-installation-wiring.ts +15 -13
- package/src/github-lookup-repositories.integration.test.ts +136 -6
- package/src/github-lookup-repositories.ts +4 -1
- package/src/github-sync.ts +1 -1
- package/src/installation-ports.ts +16 -3
- package/src/installation-repos-service.ts +9 -3
- package/src/slack-config-token.integration.test.ts +208 -0
- package/src/slack-config-token.ts +181 -0
package/prisma/client/models.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type * from './models/AgentMember.ts'
|
|
|
23
23
|
export type * from './models/Account.ts'
|
|
24
24
|
export type * from './models/AgentTemplate.ts'
|
|
25
25
|
export type * from './models/AgentTemplateItem.ts'
|
|
26
|
+
export type * from './models/SlackConfigToken.ts'
|
|
26
27
|
export type * from './models/AccountMember.ts'
|
|
27
28
|
export type * from './models/AccountInvite.ts'
|
|
28
29
|
export type * from './models/AgentCronRun.ts'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- SlackConfigToken: Slack app-configuration token per scope (account or
|
|
2
|
+
-- deployment-wide default). Additive only: one new table.
|
|
3
|
+
-- CreateTable
|
|
4
|
+
CREATE TABLE "SlackConfigToken" (
|
|
5
|
+
"id" TEXT NOT NULL,
|
|
6
|
+
"accountId" TEXT,
|
|
7
|
+
"refreshTokenEncrypted" TEXT NOT NULL,
|
|
8
|
+
"accessTokenEncrypted" TEXT,
|
|
9
|
+
"accessTokenExpiresAt" TIMESTAMP(3),
|
|
10
|
+
"slackTeamId" TEXT,
|
|
11
|
+
"slackUserId" TEXT,
|
|
12
|
+
"lastRotatedAt" TIMESTAMP(3),
|
|
13
|
+
"lastError" TEXT,
|
|
14
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
16
|
+
|
|
17
|
+
CONSTRAINT "SlackConfigToken_pkey" PRIMARY KEY ("id")
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- CreateIndex
|
|
21
|
+
CREATE INDEX "SlackConfigToken_accountId_idx" ON "SlackConfigToken"("accountId");
|
|
22
|
+
|
|
23
|
+
-- AddForeignKey
|
|
24
|
+
ALTER TABLE "SlackConfigToken" ADD CONSTRAINT "SlackConfigToken_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
25
|
+
|
|
26
|
+
-- Partial unique indexes (not expressible in Prisma; see the SlackConfigToken
|
|
27
|
+
-- comment in schema.prisma). Together they allow at most one row per scope with
|
|
28
|
+
-- NULL treated as a value, which a plain UNIQUE index would not do since NULLs
|
|
29
|
+
-- compare distinct.
|
|
30
|
+
-- CreateIndex
|
|
31
|
+
CREATE UNIQUE INDEX "SlackConfigToken_accountId_key" ON "SlackConfigToken"("accountId") WHERE "accountId" IS NOT NULL;
|
|
32
|
+
|
|
33
|
+
-- CreateIndex
|
|
34
|
+
CREATE UNIQUE INDEX "SlackConfigToken_global_key" ON "SlackConfigToken"((1)) WHERE "accountId" IS NULL;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Shipwright — Admin Service Schema
|
|
2
2
|
// Owns: Agent, AgentEnv, AgentCronJob, AgentTool, AgentToken, AgentPlugin,
|
|
3
|
-
// AgentMarketplace, AgentTemplate, AgentTemplateItem,
|
|
3
|
+
// AgentMarketplace, AgentTemplate, AgentTemplateItem, SlackConfigToken,
|
|
4
4
|
// plus the coding-owned models in coding.prisma (AgentWorkQueueSnapshot,
|
|
5
5
|
// AgentPhaseMethodology, SessionFollow, SessionAlertState).
|
|
6
6
|
// Agent is a first-class model (standalone, not embedded in a User model).
|
|
@@ -293,6 +293,7 @@ model Account {
|
|
|
293
293
|
invites AccountInvite[]
|
|
294
294
|
templates AgentTemplate[]
|
|
295
295
|
githubEnterpriseApps GitHubEnterpriseApp[]
|
|
296
|
+
slackConfigTokens SlackConfigToken[]
|
|
296
297
|
}
|
|
297
298
|
|
|
298
299
|
// ─── Agent Templates ──────────────────────────────────────────────────────────
|
|
@@ -343,6 +344,37 @@ model AgentTemplateItem {
|
|
|
343
344
|
@@unique([templateId, kind, key])
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
// ─── Slack Config Token ───────────────────────────────────────────────────────
|
|
348
|
+
// Slack app-configuration token pair (refresh + short-lived access token) used
|
|
349
|
+
// to manage Slack apps. accountId null = deployment-wide default; an account
|
|
350
|
+
// row overrides the default for that account. Tokens are AES-256-GCM encrypted
|
|
351
|
+
// at the service layer (admin/src/slack-config-token.ts) and never read back.
|
|
352
|
+
//
|
|
353
|
+
// UNIQUENESS: at most one row per scope, with NULL treated as a value. Prisma
|
|
354
|
+
// cannot express partial unique indexes, so they are hand-written in
|
|
355
|
+
// 20261115000000_add_slack_config_token/migration.sql:
|
|
356
|
+
// SlackConfigToken_accountId_key (accountId set)
|
|
357
|
+
// SlackConfigToken_global_key (accountId NULL)
|
|
358
|
+
// Prisma's schema diff does not see them, so keep them when editing this
|
|
359
|
+
// model and re-create them by hand if the table is ever rebuilt.
|
|
360
|
+
|
|
361
|
+
model SlackConfigToken {
|
|
362
|
+
id String @id @default(cuid())
|
|
363
|
+
accountId String?
|
|
364
|
+
account Account? @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
|
365
|
+
refreshTokenEncrypted String
|
|
366
|
+
accessTokenEncrypted String?
|
|
367
|
+
accessTokenExpiresAt DateTime?
|
|
368
|
+
slackTeamId String?
|
|
369
|
+
slackUserId String?
|
|
370
|
+
lastRotatedAt DateTime?
|
|
371
|
+
lastError String?
|
|
372
|
+
createdAt DateTime @default(now())
|
|
373
|
+
updatedAt DateTime @updatedAt
|
|
374
|
+
|
|
375
|
+
@@index([accountId])
|
|
376
|
+
}
|
|
377
|
+
|
|
346
378
|
model AccountMember {
|
|
347
379
|
id String @id @default(cuid())
|
|
348
380
|
accountId String
|
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
* never renders a key (the status API only reports `keySet`).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
GHE_WARNINGS,
|
|
12
|
-
type GheWarningCode,
|
|
13
|
-
} from "./github-enterprise-warnings.ts";
|
|
14
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
15
|
-
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
16
11
|
import {
|
|
17
12
|
buildSettingsNav,
|
|
18
13
|
renderSettingsLayout,
|
|
19
14
|
type SettingsNav,
|
|
20
15
|
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
17
|
+
import {
|
|
18
|
+
GHE_WARNINGS,
|
|
19
|
+
type GheWarningCode,
|
|
20
|
+
} from "./github-enterprise-warnings.ts";
|
|
21
21
|
|
|
22
22
|
export const ADMIN_GITHUB_ENTERPRISE_PATH = "/admin/settings/github-enterprise";
|
|
23
23
|
|
|
@@ -63,6 +63,12 @@ export interface GithubEnterpriseSettingsPageOpts {
|
|
|
63
63
|
/** Settings sidebar nav; defaults to the base Platform nav. */
|
|
64
64
|
nav?: SettingsNav;
|
|
65
65
|
status: GheStatus;
|
|
66
|
+
/** Account whose pair is shown; omitted for the deployment-wide pair. */
|
|
67
|
+
accountId?: string;
|
|
68
|
+
/** Accounts offered by the selector; omitted hides it. */
|
|
69
|
+
accounts?: { id: string; name: string }[];
|
|
70
|
+
/** Deployment-wide pair, passed when an account is selected (fallback). */
|
|
71
|
+
defaultStatus?: GheStatus;
|
|
66
72
|
/** Present when the installer App is configured and the org list loaded. */
|
|
67
73
|
orgs?: GheOrgs;
|
|
68
74
|
/** Readable message when the org list could not be loaded. */
|
|
@@ -113,12 +119,31 @@ const ROLE_COPY = {
|
|
|
113
119
|
},
|
|
114
120
|
} as const;
|
|
115
121
|
|
|
122
|
+
/** Lookup setup steps when no installer App exists (per-org manual install). */
|
|
123
|
+
function lookupOnlySteps(slug: string | undefined): string[] {
|
|
124
|
+
const link = slug
|
|
125
|
+
? `https://github.com/apps/${escapeHtml(slug)}/installations/new`
|
|
126
|
+
: "https://github.com/apps/<slug>/installations/new";
|
|
127
|
+
return [
|
|
128
|
+
"In GitHub, open the organization that will own the App: Settings → Developer settings → GitHub Apps → New GitHub App.",
|
|
129
|
+
"Grant Repository <code>Metadata</code> at <strong>Read</strong> and Organization <code>Members</code> at <strong>Read</strong>.",
|
|
130
|
+
"Create the App. The App ID is on the App's settings page; the App slug is the last part of its public URL (<code>github.com/apps/<slug></code>).",
|
|
131
|
+
`Install it manually on each organization you want covered, choosing <strong>All repositories</strong> (it must be installed on all repositories of each organization, not selected repositories only): <a href="${link}" target="_blank" rel="noopener noreferrer">${link}</a>. GitHub Enterprise Cloud is not needed.`,
|
|
132
|
+
"Under Private keys, choose Generate a private key and paste the downloaded PEM below.",
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
116
136
|
const IGNORED_OPTIONS =
|
|
117
137
|
"Ignore these options: callback URL, request user authorization, expire user authorization tokens, device flow, and webhook (uncheck Active).";
|
|
118
138
|
|
|
119
|
-
function guidance(
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
function guidance(
|
|
140
|
+
role: "installer" | "lookup",
|
|
141
|
+
lookupOnly: string[] | null,
|
|
142
|
+
): string {
|
|
143
|
+
const steps =
|
|
144
|
+
role === "lookup" && lookupOnly ? lookupOnly : ROLE_COPY[role].steps;
|
|
145
|
+
const variant = role === "lookup" && lookupOnly ? " gh-ent-lookup-only" : "";
|
|
146
|
+
return `<ol class="help-text gh-ent-steps${variant}" style="font-size:12px;margin:8px 0;padding-left:20px">${steps.map((x) => `<li>${x}</li>`).join("")}</ol>
|
|
122
147
|
<p class="help-text gh-ent-ignore" style="font-size:12px;margin:8px 0">${IGNORED_OPTIONS}</p>`;
|
|
123
148
|
}
|
|
124
149
|
|
|
@@ -160,17 +185,57 @@ function warningsBlock(
|
|
|
160
185
|
.join("");
|
|
161
186
|
}
|
|
162
187
|
|
|
188
|
+
/** Query suffix carrying the selected account (empty = deployment-wide). */
|
|
189
|
+
function scopeQuery(accountId: string | undefined): string {
|
|
190
|
+
return accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function accountSelector(opts: GithubEnterpriseSettingsPageOpts): string {
|
|
194
|
+
if (!opts.accounts) return "";
|
|
195
|
+
const options = [
|
|
196
|
+
`<option value=""${opts.accountId ? "" : " selected"}>Deployment-wide default</option>`,
|
|
197
|
+
...opts.accounts.map(
|
|
198
|
+
(a) =>
|
|
199
|
+
`<option value="${escapeHtml(a.id)}"${a.id === opts.accountId ? " selected" : ""}>${escapeHtml(a.name)}</option>`,
|
|
200
|
+
),
|
|
201
|
+
].join("");
|
|
202
|
+
return `<form method="GET" action="${BASE}" class="gh-ent-account-selector" style="display:flex;gap:8px;align-items:center;margin:8px 0">
|
|
203
|
+
<label>Account <select name="accountId" class="form-input">${options}</select></label>
|
|
204
|
+
<button type="submit" class="btn btn-secondary" style="font-size:12px;padding:4px 10px">Switch</button>
|
|
205
|
+
</form>`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Which pair the selected account is using: its own row or the fallback. */
|
|
209
|
+
function scopeNote(
|
|
210
|
+
role: "installer" | "lookup",
|
|
211
|
+
opts: GithubEnterpriseSettingsPageOpts,
|
|
212
|
+
own: GheApp | null,
|
|
213
|
+
): string {
|
|
214
|
+
if (!opts.accountId) return "";
|
|
215
|
+
if (own)
|
|
216
|
+
return `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-green">Account's own App</span> This account uses its own ${role} App.</p>`;
|
|
217
|
+
const fallback = opts.defaultStatus?.[role];
|
|
218
|
+
return fallback
|
|
219
|
+
? `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-gray">Deployment-wide fallback</span> This account has no ${role} App of its own and uses the deployment-wide one (slug <strong>${escapeHtml(fallback.slug)}</strong>). Saving credentials below creates an account-specific App.</p>`
|
|
220
|
+
: `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-gray">None</span> No ${role} App for this account or deployment-wide.</p>`;
|
|
221
|
+
}
|
|
222
|
+
|
|
163
223
|
function appCard(
|
|
164
224
|
role: "installer" | "lookup",
|
|
165
225
|
app: GheApp | null,
|
|
166
|
-
|
|
226
|
+
opts: GithubEnterpriseSettingsPageOpts,
|
|
227
|
+
lookupOnly: string[] | null,
|
|
167
228
|
): string {
|
|
229
|
+
const warnings = opts.warnings;
|
|
168
230
|
const copy = ROLE_COPY[role];
|
|
169
|
-
const
|
|
231
|
+
const scope = scopeQuery(opts.accountId);
|
|
232
|
+
const action = `${BASE}/apps/${role}${scope}`;
|
|
233
|
+
const actionFor = (suffix: string) =>
|
|
234
|
+
`${BASE}/apps/${role}/${suffix}${scope}`;
|
|
170
235
|
const summary = app
|
|
171
236
|
? `<p style="margin:8px 0">App ID <strong>${escapeHtml(app.appId)}</strong> · slug <strong>${escapeHtml(app.slug)}</strong>${app.enterpriseSlug ? ` · enterprise <strong>${escapeHtml(app.enterpriseSlug)}</strong>` : ""}</p>
|
|
172
237
|
${statusLine(app)}${warningsBlock(role, warnings)}
|
|
173
|
-
<div style="display:flex;gap:8px;margin:12px 0">${postButton(
|
|
238
|
+
<div style="display:flex;gap:8px;margin:12px 0">${postButton(actionFor("validate"), "Validate")}${postButton(actionFor("delete"), "Delete", "btn-danger")}</div>`
|
|
174
239
|
: `<p class="help-text" style="font-size:12px;margin:8px 0">Not configured.</p>`;
|
|
175
240
|
const enterprise =
|
|
176
241
|
role === "installer"
|
|
@@ -179,7 +244,9 @@ function appCard(
|
|
|
179
244
|
return `<div class="card">
|
|
180
245
|
<div class="card-title">${copy.title}</div>
|
|
181
246
|
<p class="help-text" style="font-size:12px">${copy.descriptor}</p>
|
|
182
|
-
${
|
|
247
|
+
${accountSelector(opts)}
|
|
248
|
+
${scopeNote(role, opts, app)}
|
|
249
|
+
${guidance(role, lookupOnly)}
|
|
183
250
|
${summary}
|
|
184
251
|
<form method="POST" action="${action}" enctype="multipart/form-data" style="display:grid;gap:8px;max-width:480px">
|
|
185
252
|
<label>App ID <input name="appId" class="form-input" required inputmode="numeric" pattern="[0-9]+" /></label>
|
|
@@ -201,8 +268,8 @@ function installedCell(v: boolean | null): string {
|
|
|
201
268
|
|
|
202
269
|
function orgsCard(opts: GithubEnterpriseSettingsPageOpts): string {
|
|
203
270
|
const { status } = opts;
|
|
204
|
-
if (!status.installer) return "";
|
|
205
|
-
const lookupSlug = status.lookup?.slug;
|
|
271
|
+
if (!(status.installer ?? opts.defaultStatus?.installer)) return "";
|
|
272
|
+
const lookupSlug = (status.lookup ?? opts.defaultStatus?.lookup)?.slug;
|
|
206
273
|
|
|
207
274
|
let body: string;
|
|
208
275
|
if (opts.orgsError) {
|
|
@@ -240,6 +307,11 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
240
307
|
opts: GithubEnterpriseSettingsPageOpts,
|
|
241
308
|
): string {
|
|
242
309
|
const { status } = opts;
|
|
310
|
+
const effectiveInstaller = status.installer ?? opts.defaultStatus?.installer;
|
|
311
|
+
const effectiveLookup = status.lookup ?? opts.defaultStatus?.lookup;
|
|
312
|
+
const lookupOnly = effectiveInstaller
|
|
313
|
+
? null
|
|
314
|
+
: lookupOnlySteps(effectiveLookup?.slug);
|
|
243
315
|
const error = opts.error
|
|
244
316
|
? `<div class="alert alert-error">${escapeHtml(opts.error)}</div>`
|
|
245
317
|
: "";
|
|
@@ -262,8 +334,8 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
262
334
|
active: BASE,
|
|
263
335
|
isAdmin: opts.isAdmin ?? false,
|
|
264
336
|
body: `${error}${notice}${intro}
|
|
265
|
-
${appCard("installer", status.installer, opts
|
|
266
|
-
${appCard("lookup", status.lookup, opts
|
|
337
|
+
${appCard("installer", status.installer, opts, lookupOnly)}
|
|
338
|
+
${appCard("lookup", status.lookup, opts, lookupOnly)}
|
|
267
339
|
${orgsCard(opts)}`,
|
|
268
340
|
}),
|
|
269
341
|
});
|
|
@@ -9,8 +9,8 @@ import { describe, expect, it } from "bun:test";
|
|
|
9
9
|
import { generateKeyPairSync } from "node:crypto";
|
|
10
10
|
import type { MiddlewareHandler } from "hono";
|
|
11
11
|
import { Hono } from "hono";
|
|
12
|
-
import { type AdminUIEnv, createAdminUIApp } from "./admin-ui.ts";
|
|
13
12
|
import { makeMockDeps, makeSessionCookie } from "./admin-ui.fixtures.ts";
|
|
13
|
+
import { type AdminUIEnv, createAdminUIApp } from "./admin-ui.ts";
|
|
14
14
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
15
15
|
import { parseAdminApiKeys } from "./api-auth.ts";
|
|
16
16
|
import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
|
|
@@ -29,20 +29,28 @@ const { privateKey: PEM } = generateKeyPairSync("rsa", {
|
|
|
29
29
|
function fakeAppService() {
|
|
30
30
|
const rows = new Map<string, GitHubEnterpriseAppMetadata & { pem: string }>();
|
|
31
31
|
const now = new Date("2026-11-09T12:00:00Z");
|
|
32
|
+
const key = (role: string, accountId?: string | null) =>
|
|
33
|
+
`${accountId ?? ""}/${role}`;
|
|
32
34
|
const strip = ({
|
|
33
35
|
pem: _p,
|
|
34
36
|
...m
|
|
35
37
|
}: GitHubEnterpriseAppMetadata & { pem: string }) => m;
|
|
38
|
+
// Account row wins, else the deployment-wide row.
|
|
39
|
+
const resolve = (role: string, accountId?: string | null) =>
|
|
40
|
+
rows.get(key(role, accountId)) ?? rows.get(key(role));
|
|
36
41
|
return {
|
|
37
|
-
async list() {
|
|
38
|
-
return [...rows.values()]
|
|
42
|
+
async list(accountId?: string | null) {
|
|
43
|
+
return [...rows.values()]
|
|
44
|
+
.filter((r) => (r.accountId ?? null) === (accountId ?? null))
|
|
45
|
+
.map(strip);
|
|
39
46
|
},
|
|
40
|
-
async get(role: GitHubEnterpriseAppRole) {
|
|
41
|
-
const r =
|
|
47
|
+
async get(role: GitHubEnterpriseAppRole, accountId?: string | null) {
|
|
48
|
+
const r = resolve(role, accountId);
|
|
42
49
|
return r ? strip(r) : null;
|
|
43
50
|
},
|
|
44
51
|
async save(input: SaveGitHubEnterpriseAppInput) {
|
|
45
52
|
const row = {
|
|
53
|
+
accountId: input.accountId ?? null,
|
|
46
54
|
role: input.role,
|
|
47
55
|
appId: input.appId,
|
|
48
56
|
slug: input.slug,
|
|
@@ -55,20 +63,24 @@ function fakeAppService() {
|
|
|
55
63
|
updatedAt: now,
|
|
56
64
|
pem: input.privateKey,
|
|
57
65
|
} as GitHubEnterpriseAppMetadata & { pem: string };
|
|
58
|
-
rows.set(input.role, row);
|
|
66
|
+
rows.set(key(input.role, input.accountId), row);
|
|
59
67
|
return strip(row);
|
|
60
68
|
},
|
|
61
|
-
async delete(role: GitHubEnterpriseAppRole) {
|
|
62
|
-
rows.delete(role);
|
|
69
|
+
async delete(role: GitHubEnterpriseAppRole, accountId?: string | null) {
|
|
70
|
+
rows.delete(key(role, accountId));
|
|
63
71
|
},
|
|
64
|
-
async getPrivateKey(
|
|
65
|
-
|
|
72
|
+
async getPrivateKey(
|
|
73
|
+
role: GitHubEnterpriseAppRole,
|
|
74
|
+
accountId?: string | null,
|
|
75
|
+
) {
|
|
76
|
+
return resolve(role, accountId)?.pem ?? null;
|
|
66
77
|
},
|
|
67
78
|
async recordValidation(
|
|
68
79
|
role: GitHubEnterpriseAppRole,
|
|
69
80
|
r: { status: string; error: string | null },
|
|
81
|
+
accountId?: string | null,
|
|
70
82
|
) {
|
|
71
|
-
const row = rows.get(role);
|
|
83
|
+
const row = rows.get(key(role, accountId));
|
|
72
84
|
if (row) {
|
|
73
85
|
row.lastValidationStatus = r.status;
|
|
74
86
|
row.lastValidationError = r.error;
|
|
@@ -78,7 +90,9 @@ function fakeAppService() {
|
|
|
78
90
|
};
|
|
79
91
|
}
|
|
80
92
|
|
|
81
|
-
function setup(
|
|
93
|
+
function setup(
|
|
94
|
+
opts: { isAdmin?: boolean; fetchStatus?: number; accounts?: boolean } = {},
|
|
95
|
+
) {
|
|
82
96
|
const appService = fakeAppService();
|
|
83
97
|
const fetchCalls: string[] = [];
|
|
84
98
|
const fetchFn = (async (input: RequestInfo | URL) => {
|
|
@@ -116,6 +130,16 @@ function setup(opts: { isAdmin?: boolean; fetchStatus?: number } = {}) {
|
|
|
116
130
|
c.set("isAdmin", opts.isAdmin ?? true);
|
|
117
131
|
await next();
|
|
118
132
|
}) as MiddlewareHandler<AdminUIEnv>,
|
|
133
|
+
...(opts.accounts
|
|
134
|
+
? {
|
|
135
|
+
accounts: {
|
|
136
|
+
listWithCounts: async () => [
|
|
137
|
+
{ id: "acct-1", name: "Acme" },
|
|
138
|
+
{ id: "acct-2", name: "Globex" },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
: {}),
|
|
119
143
|
html: (content, o) =>
|
|
120
144
|
new Response(content, {
|
|
121
145
|
status: o?.status ?? 200,
|
|
@@ -169,6 +193,105 @@ describe("GET /admin/settings/github-enterprise", () => {
|
|
|
169
193
|
});
|
|
170
194
|
});
|
|
171
195
|
|
|
196
|
+
const saveForm = (
|
|
197
|
+
appId: string,
|
|
198
|
+
slug: string,
|
|
199
|
+
extra: Record<string, string> = {},
|
|
200
|
+
) => form({ appId, slug, privateKey: PEM, ...extra });
|
|
201
|
+
|
|
202
|
+
describe("lookup card without an installer", () => {
|
|
203
|
+
it("shows manual per-org install steps with the lookup slug link", async () => {
|
|
204
|
+
const { app } = setup();
|
|
205
|
+
await app.request(`${BASE}/apps/lookup`, saveForm("7", "my-lookup"));
|
|
206
|
+
const html = await (await app.request(BASE)).text();
|
|
207
|
+
expect(html).toContain("gh-ent-lookup-only");
|
|
208
|
+
expect(html).toContain(
|
|
209
|
+
"https://github.com/apps/my-lookup/installations/new",
|
|
210
|
+
);
|
|
211
|
+
expect(html).toContain("GitHub Enterprise Cloud is not needed");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("shows a slug placeholder link when no lookup App is known", async () => {
|
|
215
|
+
const { app } = setup();
|
|
216
|
+
const html = await (await app.request(BASE)).text();
|
|
217
|
+
expect(html).toContain("gh-ent-lookup-only");
|
|
218
|
+
expect(html).toContain("github.com/apps/<slug>/installations/new");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("keeps the existing instructions once an installer exists", async () => {
|
|
222
|
+
const { app } = setup();
|
|
223
|
+
await app.request(
|
|
224
|
+
`${BASE}/apps/installer`,
|
|
225
|
+
saveForm("1", "inst", { enterpriseSlug: "ent" }),
|
|
226
|
+
);
|
|
227
|
+
const html = await (await app.request(BASE)).text();
|
|
228
|
+
expect(html).not.toContain("gh-ent-lookup-only");
|
|
229
|
+
expect(html).toContain("It must be installed on all repositories");
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("account selector", () => {
|
|
234
|
+
it("is hidden without an accounts dependency", async () => {
|
|
235
|
+
const { app } = setup();
|
|
236
|
+
expect(await (await app.request(BASE)).text()).not.toContain(
|
|
237
|
+
"gh-ent-account-selector",
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("renders on both cards with the default and each account", async () => {
|
|
242
|
+
const { app } = setup({ accounts: true });
|
|
243
|
+
const html = await (await app.request(`${BASE}?accountId=acct-2`)).text();
|
|
244
|
+
expect(html.match(/gh-ent-account-selector/g)?.length).toBe(2);
|
|
245
|
+
expect(html).toContain("Deployment-wide default");
|
|
246
|
+
expect(html).toContain('<option value="acct-1">Acme</option>');
|
|
247
|
+
expect(html).toContain('<option value="acct-2" selected>Globex</option>');
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("saves under the chosen account and marks own vs fallback", async () => {
|
|
251
|
+
const { app, appService } = setup({ accounts: true });
|
|
252
|
+
await app.request(`${BASE}/apps/lookup`, saveForm("7", "shared-lookup"));
|
|
253
|
+
const res = await app.request(
|
|
254
|
+
`${BASE}/apps/lookup?accountId=acct-1`,
|
|
255
|
+
saveForm("8", "acme-lookup"),
|
|
256
|
+
);
|
|
257
|
+
expect(res.status).toBe(302);
|
|
258
|
+
expect(res.headers.get("location")).toBe(
|
|
259
|
+
`${BASE}?notice=saved&accountId=acct-1`,
|
|
260
|
+
);
|
|
261
|
+
expect((await appService.list("acct-1"))[0]?.slug).toBe("acme-lookup");
|
|
262
|
+
expect((await appService.list())[0]?.slug).toBe("shared-lookup");
|
|
263
|
+
|
|
264
|
+
const own = await (await app.request(`${BASE}?accountId=acct-1`)).text();
|
|
265
|
+
expect(own).toContain("Account's own App");
|
|
266
|
+
const fallback = await (
|
|
267
|
+
await app.request(`${BASE}?accountId=acct-2`)
|
|
268
|
+
).text();
|
|
269
|
+
expect(fallback).toContain("Deployment-wide fallback");
|
|
270
|
+
expect(fallback).toContain("shared-lookup");
|
|
271
|
+
expect(fallback).toContain(`action="${BASE}/apps/lookup?accountId=acct-2"`);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("validates and deletes against the chosen account", async () => {
|
|
275
|
+
const { app, appService } = setup({ accounts: true });
|
|
276
|
+
await app.request(
|
|
277
|
+
`${BASE}/apps/installer?accountId=acct-1`,
|
|
278
|
+
saveForm("1", "inst", { enterpriseSlug: "ent" }),
|
|
279
|
+
);
|
|
280
|
+
const v = await app.request(
|
|
281
|
+
`${BASE}/apps/installer/validate?accountId=acct-1`,
|
|
282
|
+
{ method: "POST" },
|
|
283
|
+
);
|
|
284
|
+
expect(v.headers.get("location")).toContain("accountId=acct-1");
|
|
285
|
+
expect((await appService.list("acct-1"))[0]?.lastValidationStatus).toBe(
|
|
286
|
+
"valid",
|
|
287
|
+
);
|
|
288
|
+
await app.request(`${BASE}/apps/installer/delete?accountId=acct-1`, {
|
|
289
|
+
method: "POST",
|
|
290
|
+
});
|
|
291
|
+
expect(await appService.list("acct-1")).toEqual([]);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
172
295
|
const upload = (fields: Record<string, string>, file?: File) => {
|
|
173
296
|
const body = new FormData();
|
|
174
297
|
for (const [k, v] of Object.entries(fields)) body.set(k, v);
|
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
* `{ error }` bodies as readable messages. No key is ever read back.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
11
10
|
import type { Context, Hono, MiddlewareHandler } from "hono";
|
|
12
|
-
import { readPrivateKeyField } from "./github-enterprise-pem-upload.ts";
|
|
13
|
-
import { warningCodeFor } from "./github-enterprise-warnings.ts";
|
|
14
11
|
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
15
12
|
import {
|
|
16
13
|
ADMIN_GITHUB_ENTERPRISE_PATH as BASE,
|
|
@@ -18,11 +15,16 @@ import {
|
|
|
18
15
|
type GheStatus,
|
|
19
16
|
renderGithubEnterpriseSettingsPage,
|
|
20
17
|
} from "./admin-ui-github-enterprise-pages.ts";
|
|
18
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
19
|
+
import { readPrivateKeyField } from "./github-enterprise-pem-upload.ts";
|
|
20
|
+
import { warningCodeFor } from "./github-enterprise-warnings.ts";
|
|
21
21
|
|
|
22
22
|
export interface AdminGithubEnterpriseRouteDeps {
|
|
23
23
|
requireAuth: MiddlewareHandler<AdminUIEnv>;
|
|
24
24
|
/** Calls the GHE-1.3 API app (its `.request`), e.g. `/github-enterprise/apps`. */
|
|
25
25
|
api: (path: string, init?: RequestInit) => Response | Promise<Response>;
|
|
26
|
+
/** Accounts for the per-account App selector; omitted hides it. */
|
|
27
|
+
accounts?: { listWithCounts: () => Promise<{ id: string; name: string }[]> };
|
|
26
28
|
/** Settings sidebar nav (SGL-2.2). */
|
|
27
29
|
settingsNav?: SettingsNav;
|
|
28
30
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
@@ -90,14 +92,24 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
90
92
|
return { ok: false, status: res.status, error };
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
/** Selected account (query), as an API query suffix and a redirect suffix. */
|
|
96
|
+
const scopeOf = (c: Context<AdminUIEnv>) => {
|
|
97
|
+
const accountId = c.req.query("accountId")?.trim() || undefined;
|
|
98
|
+
const q = accountId ? `accountId=${encodeURIComponent(accountId)}` : "";
|
|
99
|
+
return { accountId, q };
|
|
100
|
+
};
|
|
101
|
+
const withQuery = (path: string, q: string) =>
|
|
102
|
+
q ? `${path}${path.includes("?") ? "&" : "?"}${q}` : path;
|
|
103
|
+
|
|
93
104
|
async function renderPage(
|
|
94
105
|
c: Context<AdminUIEnv>,
|
|
95
106
|
flash: { error?: string; notice?: string; status?: number } = {},
|
|
96
107
|
): Promise<Response> {
|
|
108
|
+
const { accountId, q } = scopeOf(c);
|
|
97
109
|
const statusRes = await call<GheStatus>(
|
|
98
110
|
c,
|
|
99
111
|
"GET",
|
|
100
|
-
"/github-enterprise/apps",
|
|
112
|
+
withQuery("/github-enterprise/apps", q),
|
|
101
113
|
);
|
|
102
114
|
if (!statusRes.ok || !statusRes.data) {
|
|
103
115
|
return deps.html(
|
|
@@ -114,8 +126,22 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
114
126
|
const status = statusRes.data;
|
|
115
127
|
let orgs: GheOrgs | undefined;
|
|
116
128
|
let orgsError: string | undefined;
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
// With an account selected, the deployment-wide pair is the fallback.
|
|
130
|
+
let defaultStatus: GheStatus | undefined;
|
|
131
|
+
if (accountId) {
|
|
132
|
+
const d = await call<GheStatus>(c, "GET", "/github-enterprise/apps");
|
|
133
|
+
if (d.ok) defaultStatus = d.data;
|
|
134
|
+
}
|
|
135
|
+
let accounts: { id: string; name: string }[] | undefined;
|
|
136
|
+
if (deps.accounts) {
|
|
137
|
+
accounts = await deps.accounts.listWithCounts().catch(() => undefined);
|
|
138
|
+
}
|
|
139
|
+
if (status.installer ?? defaultStatus?.installer) {
|
|
140
|
+
const r = await call<GheOrgs>(
|
|
141
|
+
c,
|
|
142
|
+
"GET",
|
|
143
|
+
withQuery("/github-enterprise/orgs", q),
|
|
144
|
+
);
|
|
119
145
|
if (r.ok) orgs = r.data;
|
|
120
146
|
else orgsError = r.error;
|
|
121
147
|
}
|
|
@@ -127,6 +153,9 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
127
153
|
isAdmin: c.var.isAdmin === true,
|
|
128
154
|
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
129
155
|
status,
|
|
156
|
+
accountId,
|
|
157
|
+
accounts: accounts?.map((a) => ({ id: a.id, name: a.name })),
|
|
158
|
+
defaultStatus,
|
|
130
159
|
orgs,
|
|
131
160
|
orgsError,
|
|
132
161
|
error: flash.error,
|
|
@@ -146,8 +175,10 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
146
175
|
return new FormData();
|
|
147
176
|
}
|
|
148
177
|
}
|
|
149
|
-
const back = (c: Context<AdminUIEnv>, notice: string) =>
|
|
150
|
-
|
|
178
|
+
const back = (c: Context<AdminUIEnv>, notice: string) => {
|
|
179
|
+
const { q } = scopeOf(c);
|
|
180
|
+
return c.redirect(`${BASE}?notice=${notice}${q ? `&${q}` : ""}`, 302);
|
|
181
|
+
};
|
|
151
182
|
const fail = (c: Context<AdminUIEnv>, r: ApiResult<unknown>) =>
|
|
152
183
|
renderPage(c, { error: r.error, status: r.status >= 400 ? r.status : 400 });
|
|
153
184
|
|
|
@@ -160,13 +191,19 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
160
191
|
const enterpriseSlug = field(form, "enterpriseSlug");
|
|
161
192
|
const key = await readPrivateKeyField(form);
|
|
162
193
|
if (!key.ok) return renderPage(c, { error: key.error, status: 400 });
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
194
|
+
const { q } = scopeOf(c);
|
|
195
|
+
const r = await call(
|
|
196
|
+
c,
|
|
197
|
+
"PUT",
|
|
198
|
+
withQuery(`/github-enterprise/apps/${role}`, q),
|
|
199
|
+
{
|
|
200
|
+
appId: field(form, "appId"),
|
|
201
|
+
slug: field(form, "slug"),
|
|
202
|
+
...(enterpriseSlug ? { enterpriseSlug } : {}),
|
|
203
|
+
// Pasted or uploaded; never echoed back to the page.
|
|
204
|
+
privateKey: key.pem,
|
|
205
|
+
},
|
|
206
|
+
);
|
|
170
207
|
return r.ok ? back(c, "saved") : fail(c, r);
|
|
171
208
|
});
|
|
172
209
|
|
|
@@ -180,7 +217,7 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
180
217
|
const r = await call<{ warnings?: string[] }>(
|
|
181
218
|
c,
|
|
182
219
|
"POST",
|
|
183
|
-
`/github-enterprise/apps/${role}/validate`,
|
|
220
|
+
withQuery(`/github-enterprise/apps/${role}/validate`, scopeOf(c).q),
|
|
184
221
|
);
|
|
185
222
|
if (!r.ok) return fail(c, r);
|
|
186
223
|
// Warnings ride the redirect as stable codes, never free text.
|
|
@@ -188,7 +225,7 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
188
225
|
.map(warningCodeFor)
|
|
189
226
|
.filter((x): x is NonNullable<typeof x> => x !== undefined);
|
|
190
227
|
return c.redirect(
|
|
191
|
-
`${BASE}?notice=validated${codes.length ? `&warn=${codes.join(",")}` : ""}`,
|
|
228
|
+
`${BASE}?notice=validated${codes.length ? `&warn=${codes.join(",")}` : ""}${scopeOf(c).q ? `&${scopeOf(c).q}` : ""}`,
|
|
192
229
|
302,
|
|
193
230
|
);
|
|
194
231
|
},
|
|
@@ -201,7 +238,11 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
201
238
|
async (c) => {
|
|
202
239
|
const role = c.req.param("role");
|
|
203
240
|
if (!isRole(role)) return new Response("Not Found", { status: 404 });
|
|
204
|
-
const r = await call(
|
|
241
|
+
const r = await call(
|
|
242
|
+
c,
|
|
243
|
+
"DELETE",
|
|
244
|
+
withQuery(`/github-enterprise/apps/${role}`, scopeOf(c).q),
|
|
245
|
+
);
|
|
205
246
|
return r.ok ? back(c, "deleted") : fail(c, r);
|
|
206
247
|
},
|
|
207
248
|
);
|
package/src/admin-ui.ts
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
* Allowed users are controlled by the adminAllowedEmails allowlist in deps.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
|
|
26
25
|
import { join } from "node:path";
|
|
27
26
|
import { isGithubLogin } from "@app-vitals/agent-lib/github-login";
|
|
28
27
|
import { isOrgRepo } from "@app-vitals/agent-lib/org-repo";
|
|
@@ -51,6 +50,7 @@ import { runWithSettingsNav } from "./admin-ui-account-nav.ts";
|
|
|
51
50
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
52
51
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
53
52
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
53
|
+
import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
|
|
54
54
|
import {
|
|
55
55
|
type GithubAccessPreviewView,
|
|
56
56
|
renderGithubAccessError,
|
|
@@ -4091,6 +4091,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4091
4091
|
requireAuth,
|
|
4092
4092
|
settingsNav,
|
|
4093
4093
|
api: githubEnterpriseApi,
|
|
4094
|
+
...(accountServices ? { accounts: accountServices.accounts } : {}),
|
|
4094
4095
|
html,
|
|
4095
4096
|
});
|
|
4096
4097
|
}
|