@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/src/agents-api.ts
CHANGED
|
@@ -3403,7 +3403,10 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3403
3403
|
}
|
|
3404
3404
|
if (!deps.githubAccessPreview)
|
|
3405
3405
|
return c.json({ status: "unconfigured" as const }, 200);
|
|
3406
|
-
const preview = await deps.githubAccessPreview(
|
|
3406
|
+
const preview = await deps.githubAccessPreview(
|
|
3407
|
+
agent.githubUsername,
|
|
3408
|
+
agent.accountId,
|
|
3409
|
+
);
|
|
3407
3410
|
return c.json(preview, 200);
|
|
3408
3411
|
});
|
|
3409
3412
|
|
|
@@ -388,11 +388,17 @@ describe("POST validate", () => {
|
|
|
388
388
|
"/github-enterprise/apps/installer/validate",
|
|
389
389
|
{ method: "POST", headers: ADMIN },
|
|
390
390
|
);
|
|
391
|
-
const body = (await res.json()) as {
|
|
391
|
+
const body = (await res.json()) as {
|
|
392
|
+
ok: boolean;
|
|
393
|
+
status: string;
|
|
394
|
+
error: string;
|
|
395
|
+
};
|
|
392
396
|
expect(body).toMatchObject({ ok: false, status: "error" });
|
|
393
397
|
expect(body.error).toContain("not installed on enterprise acme");
|
|
394
398
|
expect(body.error).toContain("slug");
|
|
395
|
-
expect(h.appService.rows.get("installer")?.lastValidationError).toBe(
|
|
399
|
+
expect(h.appService.rows.get("installer")?.lastValidationError).toBe(
|
|
400
|
+
body.error,
|
|
401
|
+
);
|
|
396
402
|
});
|
|
397
403
|
|
|
398
404
|
it("installer: a 404 on the token mint keeps the generic reason", async () => {
|
|
@@ -415,28 +421,48 @@ describe("POST validate", () => {
|
|
|
415
421
|
"/github-enterprise/apps/installer/validate",
|
|
416
422
|
{ method: "POST", headers: ADMIN },
|
|
417
423
|
);
|
|
418
|
-
const body = (await res.json()) as {
|
|
424
|
+
const body = (await res.json()) as {
|
|
425
|
+
ok: boolean;
|
|
426
|
+
status: string;
|
|
427
|
+
warnings: string[];
|
|
428
|
+
};
|
|
419
429
|
expect(body).toMatchObject({ ok: true, status: "valid" });
|
|
420
430
|
expect(body.warnings).toHaveLength(1);
|
|
421
|
-
expect(body.warnings[0]).toContain(
|
|
431
|
+
expect(body.warnings[0]).toContain(
|
|
432
|
+
"enterprise_organization_installation_repositories",
|
|
433
|
+
);
|
|
422
434
|
});
|
|
423
435
|
|
|
424
436
|
it("installer: read-only repositories permission also warns; write does not", async () => {
|
|
425
|
-
const ro = build({
|
|
426
|
-
|
|
427
|
-
const r1 = await ro.app.request("/github-enterprise/apps/installer/validate", {
|
|
428
|
-
method: "POST",
|
|
429
|
-
headers: ADMIN,
|
|
437
|
+
const ro = build({
|
|
438
|
+
routes: { [MINT]: "access_token_repositories_read_only" },
|
|
430
439
|
});
|
|
431
|
-
|
|
440
|
+
await seed(ro);
|
|
441
|
+
const r1 = await ro.app.request(
|
|
442
|
+
"/github-enterprise/apps/installer/validate",
|
|
443
|
+
{
|
|
444
|
+
method: "POST",
|
|
445
|
+
headers: ADMIN,
|
|
446
|
+
},
|
|
447
|
+
);
|
|
448
|
+
expect(((await r1.json()) as { warnings: string[] }).warnings).toHaveLength(
|
|
449
|
+
1,
|
|
450
|
+
);
|
|
432
451
|
|
|
433
452
|
const full = build({ routes: { [MINT]: "access_token_all_permissions" } });
|
|
434
453
|
await seed(full);
|
|
435
|
-
const r2 = await full.app.request(
|
|
436
|
-
|
|
437
|
-
|
|
454
|
+
const r2 = await full.app.request(
|
|
455
|
+
"/github-enterprise/apps/installer/validate",
|
|
456
|
+
{
|
|
457
|
+
method: "POST",
|
|
458
|
+
headers: ADMIN,
|
|
459
|
+
},
|
|
460
|
+
);
|
|
461
|
+
expect(await r2.json()).toMatchObject({
|
|
462
|
+
ok: true,
|
|
463
|
+
status: "valid",
|
|
464
|
+
warnings: [],
|
|
438
465
|
});
|
|
439
|
-
expect(await r2.json()).toMatchObject({ ok: true, status: "valid", warnings: [] });
|
|
440
466
|
});
|
|
441
467
|
|
|
442
468
|
it("lookup: warns (still valid) without Organization Members read; none with it", async () => {
|
|
@@ -460,29 +486,51 @@ describe("POST validate", () => {
|
|
|
460
486
|
|
|
461
487
|
const h2 = build({ routes: { "GET /app": "app_get_all_permissions" } });
|
|
462
488
|
await seedLookup(h2);
|
|
463
|
-
const res2 = await h2.app.request(
|
|
464
|
-
|
|
465
|
-
|
|
489
|
+
const res2 = await h2.app.request(
|
|
490
|
+
"/github-enterprise/apps/lookup/validate",
|
|
491
|
+
{
|
|
492
|
+
method: "POST",
|
|
493
|
+
headers: ADMIN,
|
|
494
|
+
},
|
|
495
|
+
);
|
|
496
|
+
expect(await res2.json()).toMatchObject({
|
|
497
|
+
ok: true,
|
|
498
|
+
status: "valid",
|
|
499
|
+
warnings: [],
|
|
466
500
|
});
|
|
467
|
-
expect(await res2.json()).toMatchObject({ ok: true, status: "valid", warnings: [] });
|
|
468
501
|
});
|
|
469
502
|
|
|
470
503
|
it("warnings never flip validity: a missing required permission stays invalid, an error has none", async () => {
|
|
471
|
-
const h = build({
|
|
504
|
+
const h = build({
|
|
505
|
+
routes: { [MINT]: "access_token_no_installer_permission" },
|
|
506
|
+
});
|
|
472
507
|
await seed(h);
|
|
473
|
-
const res = await h.app.request(
|
|
474
|
-
|
|
475
|
-
|
|
508
|
+
const res = await h.app.request(
|
|
509
|
+
"/github-enterprise/apps/installer/validate",
|
|
510
|
+
{
|
|
511
|
+
method: "POST",
|
|
512
|
+
headers: ADMIN,
|
|
513
|
+
},
|
|
514
|
+
);
|
|
515
|
+
expect(await res.json()).toMatchObject({
|
|
516
|
+
ok: false,
|
|
517
|
+
status: "missing_permission",
|
|
476
518
|
});
|
|
477
|
-
expect(await res.json()).toMatchObject({ ok: false, status: "missing_permission" });
|
|
478
519
|
|
|
479
520
|
const e = build({ routes: { [ENT]: "enterprise_installation_403" } });
|
|
480
521
|
await seed(e);
|
|
481
|
-
const r = await e.app.request(
|
|
482
|
-
|
|
483
|
-
|
|
522
|
+
const r = await e.app.request(
|
|
523
|
+
"/github-enterprise/apps/installer/validate",
|
|
524
|
+
{
|
|
525
|
+
method: "POST",
|
|
526
|
+
headers: ADMIN,
|
|
527
|
+
},
|
|
528
|
+
);
|
|
529
|
+
expect(await r.json()).toMatchObject({
|
|
530
|
+
ok: false,
|
|
531
|
+
status: "error",
|
|
532
|
+
warnings: [],
|
|
484
533
|
});
|
|
485
|
-
expect(await r.json()).toMatchObject({ ok: false, status: "error", warnings: [] });
|
|
486
534
|
});
|
|
487
535
|
|
|
488
536
|
it("lookup: checks metadata read via GET /app", async () => {
|
|
@@ -772,3 +820,99 @@ describe("POST install", () => {
|
|
|
772
820
|
expect((await post(h, { agentId: "agent-1" })).status).toBe(429);
|
|
773
821
|
});
|
|
774
822
|
});
|
|
823
|
+
|
|
824
|
+
describe("account-scoped routes", () => {
|
|
825
|
+
/** Records the accountId every appService method receives. */
|
|
826
|
+
function spied() {
|
|
827
|
+
const h = build();
|
|
828
|
+
const seen: Record<string, unknown[]> = {};
|
|
829
|
+
for (const m of [
|
|
830
|
+
"list",
|
|
831
|
+
"get",
|
|
832
|
+
"save",
|
|
833
|
+
"delete",
|
|
834
|
+
"getPrivateKey",
|
|
835
|
+
] as const) {
|
|
836
|
+
const orig = (
|
|
837
|
+
h.appService as never as Record<string, (...a: unknown[]) => unknown>
|
|
838
|
+
)[m];
|
|
839
|
+
(h.appService as never as Record<string, unknown>)[m] = async (
|
|
840
|
+
...args: unknown[]
|
|
841
|
+
) => {
|
|
842
|
+
const acct =
|
|
843
|
+
m === "save"
|
|
844
|
+
? (args[0] as { accountId?: string }).accountId
|
|
845
|
+
: args[m === "list" ? 0 : 1];
|
|
846
|
+
seen[m] = [...(seen[m] ?? []), acct];
|
|
847
|
+
return orig.apply(h.appService, args);
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
return { ...h, seen };
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
it("GET /apps, PUT, DELETE and validate pass the accountId query param", async () => {
|
|
854
|
+
const h = spied();
|
|
855
|
+
await h.app.request("/github-enterprise/apps?accountId=acct-1", {
|
|
856
|
+
headers: ADMIN,
|
|
857
|
+
});
|
|
858
|
+
expect(h.seen.list).toEqual(["acct-1"]);
|
|
859
|
+
|
|
860
|
+
const put = await h.app.request(
|
|
861
|
+
"/github-enterprise/apps/installer?accountId=acct-1",
|
|
862
|
+
{
|
|
863
|
+
method: "PUT",
|
|
864
|
+
headers: JSON_ADMIN,
|
|
865
|
+
body: JSON.stringify(installerBody),
|
|
866
|
+
},
|
|
867
|
+
);
|
|
868
|
+
expect(put.status).toBe(200);
|
|
869
|
+
expect(h.seen.save).toEqual(["acct-1"]);
|
|
870
|
+
|
|
871
|
+
const del = await h.app.request(
|
|
872
|
+
"/github-enterprise/apps/installer?accountId=acct-1",
|
|
873
|
+
{ method: "DELETE", headers: ADMIN },
|
|
874
|
+
);
|
|
875
|
+
expect(del.status).toBe(204);
|
|
876
|
+
expect(h.seen.delete).toEqual(["acct-1"]);
|
|
877
|
+
|
|
878
|
+
await h.app.request(
|
|
879
|
+
"/github-enterprise/apps/installer/validate?accountId=acct-1",
|
|
880
|
+
{ method: "POST", headers: ADMIN },
|
|
881
|
+
);
|
|
882
|
+
expect(h.seen.get?.[0]).toBe("acct-1");
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
it("omitting accountId targets the deployment-wide pair", async () => {
|
|
886
|
+
const h = spied();
|
|
887
|
+
await h.app.request("/github-enterprise/apps", { headers: ADMIN });
|
|
888
|
+
await h.app.request("/github-enterprise/orgs", { headers: ADMIN });
|
|
889
|
+
expect(h.seen.list).toEqual([undefined]);
|
|
890
|
+
expect(h.seen.get).toEqual([undefined]);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it("orgs and install read the account's installer App", async () => {
|
|
894
|
+
const h = spied();
|
|
895
|
+
await h.app.request("/github-enterprise/orgs?accountId=acct-1", {
|
|
896
|
+
headers: ADMIN,
|
|
897
|
+
});
|
|
898
|
+
expect(h.seen.get).toEqual(["acct-1"]);
|
|
899
|
+
const res = await h.app.request(
|
|
900
|
+
"/github-enterprise/orgs/org-1/install?accountId=acct-1",
|
|
901
|
+
{
|
|
902
|
+
method: "POST",
|
|
903
|
+
headers: JSON_ADMIN,
|
|
904
|
+
body: JSON.stringify({ agentId: "agent-1" }),
|
|
905
|
+
},
|
|
906
|
+
);
|
|
907
|
+
expect(res.status).toBe(409);
|
|
908
|
+
expect(h.seen.get).toEqual(["acct-1", "acct-1"]);
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
it("stays admin-only with an account param", async () => {
|
|
912
|
+
const h = spied();
|
|
913
|
+
const res = await h.app.request("/github-enterprise/apps?accountId=a", {
|
|
914
|
+
headers: { Authorization: "Bearer tok-read" },
|
|
915
|
+
});
|
|
916
|
+
expect(res.status).toBe(403);
|
|
917
|
+
});
|
|
918
|
+
});
|
|
@@ -111,8 +111,23 @@ const OrgParamSchema = z.object({
|
|
|
111
111
|
.openapi({ param: { name: "org", in: "path" }, example: "example-org" }),
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
+
const AccountQuerySchema = z.object({
|
|
115
|
+
accountId: z
|
|
116
|
+
.string()
|
|
117
|
+
.min(1)
|
|
118
|
+
.optional()
|
|
119
|
+
.openapi({
|
|
120
|
+
param: { name: "accountId", in: "query" },
|
|
121
|
+
description:
|
|
122
|
+
"Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
|
|
114
126
|
const AppMetadataSchema = z
|
|
115
127
|
.object({
|
|
128
|
+
accountId: z.string().nullable().optional().openapi({
|
|
129
|
+
description: "Null for the deployment-wide App.",
|
|
130
|
+
}),
|
|
116
131
|
role: z.string().openapi({ example: "installer" }),
|
|
117
132
|
appId: z.string().openapi({ example: "12345" }),
|
|
118
133
|
slug: z.string().openapi({ example: "example-installer" }),
|
|
@@ -168,7 +183,7 @@ const ValidateResultSchema = z
|
|
|
168
183
|
})
|
|
169
184
|
.openapi("GithubEnterpriseValidateResult");
|
|
170
185
|
|
|
171
|
-
const OrgsQuerySchema =
|
|
186
|
+
const OrgsQuerySchema = AccountQuerySchema.extend({
|
|
172
187
|
agentId: z
|
|
173
188
|
.string()
|
|
174
189
|
.min(1)
|
|
@@ -253,6 +268,7 @@ const statusRoute = createRoute({
|
|
|
253
268
|
summary: "GitHub Enterprise App status",
|
|
254
269
|
description:
|
|
255
270
|
"Admin-only. Metadata and key-set flag per role; never the key. Returns configured=false with null roles when nothing is set.",
|
|
271
|
+
request: { query: AccountQuerySchema },
|
|
256
272
|
responses: {
|
|
257
273
|
200: {
|
|
258
274
|
description: "Status",
|
|
@@ -271,6 +287,7 @@ const putRoute = createRoute({
|
|
|
271
287
|
"Admin-only. Stores the App id, slug, enterprise slug (installer) and the encrypted private key, and resets validation state. 422 when SHIPWRIGHT_ENCRYPTION_KEY is not configured.",
|
|
272
288
|
request: {
|
|
273
289
|
params: RoleParamSchema,
|
|
290
|
+
query: AccountQuerySchema,
|
|
274
291
|
body: { content: { "application/json": { schema: PutAppBodySchema } } },
|
|
275
292
|
},
|
|
276
293
|
responses: {
|
|
@@ -293,7 +310,7 @@ const deleteRoute = createRoute({
|
|
|
293
310
|
tags,
|
|
294
311
|
summary: "Remove the App for a role",
|
|
295
312
|
description: "Admin-only. No-op when the role is not configured.",
|
|
296
|
-
request: { params: RoleParamSchema },
|
|
313
|
+
request: { params: RoleParamSchema, query: AccountQuerySchema },
|
|
297
314
|
responses: {
|
|
298
315
|
204: { description: "Removed" },
|
|
299
316
|
...errorResponses,
|
|
@@ -307,7 +324,7 @@ const validateRoute = createRoute({
|
|
|
307
324
|
summary: "Validate the App for a role",
|
|
308
325
|
description:
|
|
309
326
|
"Admin-only. Authenticates as the App and checks the required permission (installer: enterprise_organization_installations write; lookup: metadata read). The outcome is persisted and returned; GitHub failures are reported as status=error with a generic message.",
|
|
310
|
-
request: { params: RoleParamSchema },
|
|
327
|
+
request: { params: RoleParamSchema, query: AccountQuerySchema },
|
|
311
328
|
responses: {
|
|
312
329
|
200: {
|
|
313
330
|
description: "Validation outcome",
|
|
@@ -345,6 +362,7 @@ const installRoute = createRoute({
|
|
|
345
362
|
"Admin-only. Uses the agent's stored GH_APP_CLIENT_ID when set; otherwise resolves the stored GH_APP_SLUG and looks the App up through the public GET /apps/{slug} to get its client id. Installs it on the org with the installer App. 422 for an agent with neither a stored client id nor a slug, and for a private App (not visible to the public lookup) with no stored client id; 409 when the installer App is not configured.",
|
|
346
363
|
request: {
|
|
347
364
|
params: OrgParamSchema,
|
|
365
|
+
query: AccountQuerySchema,
|
|
348
366
|
body: { content: { "application/json": { schema: InstallBodySchema } } },
|
|
349
367
|
},
|
|
350
368
|
responses: {
|
|
@@ -417,6 +435,7 @@ export function mapEnterpriseFailure(kind: GithubEnterpriseErrorKind): Mapped {
|
|
|
417
435
|
|
|
418
436
|
function serializeApp(m: GitHubEnterpriseAppMetadata) {
|
|
419
437
|
return {
|
|
438
|
+
accountId: m.accountId ?? null,
|
|
420
439
|
role: m.role,
|
|
421
440
|
appId: m.appId,
|
|
422
441
|
slug: m.slug,
|
|
@@ -444,17 +463,17 @@ export function createGithubAccessPreview(
|
|
|
444
463
|
"appService" | "fetchFn" | "apiBase" | "now"
|
|
445
464
|
>,
|
|
446
465
|
): GithubAccessPreviewFn {
|
|
447
|
-
return async (username) => {
|
|
466
|
+
return async (username, accountId) => {
|
|
448
467
|
const [installer, lookup] = await Promise.all([
|
|
449
|
-
deps.appService.get("installer"),
|
|
450
|
-
deps.appService.get("lookup"),
|
|
468
|
+
deps.appService.get("installer", accountId),
|
|
469
|
+
deps.appService.get("lookup", accountId),
|
|
451
470
|
]);
|
|
452
471
|
if (!installer || !lookup || !installer.enterpriseSlug) {
|
|
453
472
|
return { status: "unconfigured" };
|
|
454
473
|
}
|
|
455
474
|
const [installerKey, lookupKey] = await Promise.all([
|
|
456
|
-
deps.appService.getPrivateKey("installer"),
|
|
457
|
-
deps.appService.getPrivateKey("lookup"),
|
|
475
|
+
deps.appService.getPrivateKey("installer", accountId),
|
|
476
|
+
deps.appService.getPrivateKey("lookup", accountId),
|
|
458
477
|
]);
|
|
459
478
|
if (!installerKey || !lookupKey) return { status: "unconfigured" };
|
|
460
479
|
|
|
@@ -504,15 +523,18 @@ export function createGithubLookupService(
|
|
|
504
523
|
},
|
|
505
524
|
): GithubLookupService {
|
|
506
525
|
return {
|
|
507
|
-
async listRepositories() {
|
|
526
|
+
async listRepositories(accountId) {
|
|
508
527
|
let clients = deps.clients;
|
|
509
528
|
if (!clients) {
|
|
510
529
|
const [installer, lookup] = await Promise.all([
|
|
511
|
-
deps.appService.get("installer"),
|
|
512
|
-
deps.appService.get("lookup"),
|
|
530
|
+
deps.appService.get("installer", accountId),
|
|
531
|
+
deps.appService.get("lookup", accountId),
|
|
513
532
|
]);
|
|
514
533
|
if (!lookup) return { configured: false, repos: [] };
|
|
515
|
-
const lookupKey = await deps.appService.getPrivateKey(
|
|
534
|
+
const lookupKey = await deps.appService.getPrivateKey(
|
|
535
|
+
"lookup",
|
|
536
|
+
accountId,
|
|
537
|
+
);
|
|
516
538
|
if (!lookupKey) return { configured: false, repos: [] };
|
|
517
539
|
const common = {
|
|
518
540
|
apiBase: deps.apiBase,
|
|
@@ -522,7 +544,7 @@ export function createGithubLookupService(
|
|
|
522
544
|
// An installer with an enterprise slug supplies the org list; without
|
|
523
545
|
// one the lookup App lists the orgs it is installed on.
|
|
524
546
|
const installerKey = installer?.enterpriseSlug
|
|
525
|
-
? await deps.appService.getPrivateKey("installer")
|
|
547
|
+
? await deps.appService.getPrivateKey("installer", accountId)
|
|
526
548
|
: null;
|
|
527
549
|
if (installer?.enterpriseSlug && !installerKey) {
|
|
528
550
|
return { configured: false, repos: [] };
|
|
@@ -613,9 +635,11 @@ export function createGithubEnterpriseApp(
|
|
|
613
635
|
|
|
614
636
|
const clientFor = async (
|
|
615
637
|
meta: GitHubEnterpriseAppMetadata,
|
|
638
|
+
accountId: string | undefined,
|
|
616
639
|
): Promise<GithubEnterpriseClient> => {
|
|
617
640
|
const privateKey = await appService.getPrivateKey(
|
|
618
641
|
meta.role as GitHubEnterpriseAppRole,
|
|
642
|
+
accountId,
|
|
619
643
|
);
|
|
620
644
|
if (!privateKey || !meta.enterpriseSlug) {
|
|
621
645
|
throw new UnprocessableEntityError(
|
|
@@ -682,7 +706,8 @@ export function createGithubEnterpriseApp(
|
|
|
682
706
|
|
|
683
707
|
app.openapi(statusRoute, async (c) => {
|
|
684
708
|
requireAdmin(c);
|
|
685
|
-
const
|
|
709
|
+
const { accountId } = c.req.valid("query");
|
|
710
|
+
const rows = await appService.list(accountId);
|
|
686
711
|
const byRole = (role: string) => {
|
|
687
712
|
const r = rows.find((x) => x.role === role);
|
|
688
713
|
return r ? serializeApp(r) : null;
|
|
@@ -700,6 +725,7 @@ export function createGithubEnterpriseApp(
|
|
|
700
725
|
app.openapi(putRoute, async (c) => {
|
|
701
726
|
requireAdmin(c);
|
|
702
727
|
const { role } = c.req.valid("param");
|
|
728
|
+
const { accountId } = c.req.valid("query");
|
|
703
729
|
const body = c.req.valid("json");
|
|
704
730
|
if (role === "installer" && !body.enterpriseSlug) {
|
|
705
731
|
throw new UnprocessableEntityError(
|
|
@@ -715,6 +741,7 @@ export function createGithubEnterpriseApp(
|
|
|
715
741
|
);
|
|
716
742
|
}
|
|
717
743
|
const saved = await appService.save({
|
|
744
|
+
accountId,
|
|
718
745
|
role,
|
|
719
746
|
appId: body.appId,
|
|
720
747
|
slug: body.slug,
|
|
@@ -726,16 +753,20 @@ export function createGithubEnterpriseApp(
|
|
|
726
753
|
|
|
727
754
|
app.openapi(deleteRoute, async (c) => {
|
|
728
755
|
requireAdmin(c);
|
|
729
|
-
await appService.delete(
|
|
756
|
+
await appService.delete(
|
|
757
|
+
c.req.valid("param").role,
|
|
758
|
+
c.req.valid("query").accountId,
|
|
759
|
+
);
|
|
730
760
|
return c.body(null, 204);
|
|
731
761
|
});
|
|
732
762
|
|
|
733
763
|
app.openapi(validateRoute, async (c) => {
|
|
734
764
|
requireAdmin(c);
|
|
735
765
|
const { role } = c.req.valid("param");
|
|
736
|
-
const
|
|
766
|
+
const { accountId } = c.req.valid("query");
|
|
767
|
+
const meta = await appService.get(role, accountId);
|
|
737
768
|
if (!meta) throw new NotFoundError(`no '${role}' App is configured`);
|
|
738
|
-
const privateKey = await appService.getPrivateKey(role);
|
|
769
|
+
const privateKey = await appService.getPrivateKey(role, accountId);
|
|
739
770
|
if (!privateKey) throw new NotFoundError(`no '${role}' App is configured`);
|
|
740
771
|
|
|
741
772
|
const required = REQUIRED_PERMISSION[role];
|
|
@@ -792,8 +823,14 @@ export function createGithubEnterpriseApp(
|
|
|
792
823
|
}
|
|
793
824
|
}
|
|
794
825
|
|
|
795
|
-
|
|
796
|
-
|
|
826
|
+
// Record against the row that was validated (the deployment-wide row when
|
|
827
|
+
// the account has none of its own).
|
|
828
|
+
await appService.recordValidation(
|
|
829
|
+
role,
|
|
830
|
+
{ status, error },
|
|
831
|
+
meta.accountId ?? null,
|
|
832
|
+
);
|
|
833
|
+
const updated = await appService.get(role, accountId);
|
|
797
834
|
return c.json(
|
|
798
835
|
{
|
|
799
836
|
role,
|
|
@@ -811,8 +848,8 @@ export function createGithubEnterpriseApp(
|
|
|
811
848
|
|
|
812
849
|
app.openapi(orgsRoute, async (c) => {
|
|
813
850
|
requireAdmin(c);
|
|
814
|
-
const { agentId } = c.req.valid("query");
|
|
815
|
-
const installer = await appService.get("installer");
|
|
851
|
+
const { agentId, accountId } = c.req.valid("query");
|
|
852
|
+
const installer = await appService.get("installer", accountId);
|
|
816
853
|
if (!installer) return c.json({ configured: false, orgs: [] }, 200);
|
|
817
854
|
|
|
818
855
|
let agentAppSlug: string | null = null;
|
|
@@ -835,9 +872,9 @@ export function createGithubEnterpriseApp(
|
|
|
835
872
|
}
|
|
836
873
|
}
|
|
837
874
|
}
|
|
838
|
-
const lookup = await appService.get("lookup");
|
|
875
|
+
const lookup = await appService.get("lookup", accountId);
|
|
839
876
|
|
|
840
|
-
const client = await clientFor(installer);
|
|
877
|
+
const client = await clientFor(installer, accountId);
|
|
841
878
|
const orgs = await client.listInstallableOrganizations();
|
|
842
879
|
const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();
|
|
843
880
|
const needInstallations = lookup !== null || agentAppSlug !== null;
|
|
@@ -872,8 +909,9 @@ export function createGithubEnterpriseApp(
|
|
|
872
909
|
requireAdmin(c);
|
|
873
910
|
const { org } = c.req.valid("param");
|
|
874
911
|
const body = c.req.valid("json");
|
|
912
|
+
const { accountId } = c.req.valid("query");
|
|
875
913
|
|
|
876
|
-
const installer = await appService.get("installer");
|
|
914
|
+
const installer = await appService.get("installer", accountId);
|
|
877
915
|
if (!installer) {
|
|
878
916
|
throw new ConflictError("the installer App is not configured");
|
|
879
917
|
}
|
|
@@ -902,7 +940,7 @@ export function createGithubEnterpriseApp(
|
|
|
902
940
|
}
|
|
903
941
|
}
|
|
904
942
|
|
|
905
|
-
const client = await clientFor(installer);
|
|
943
|
+
const client = await clientFor(installer, accountId);
|
|
906
944
|
const res = await client.installOnOrg(org, {
|
|
907
945
|
clientId,
|
|
908
946
|
repositorySelection: body.repositorySelection,
|
|
@@ -46,10 +46,12 @@ function lazyInstallerClient(
|
|
|
46
46
|
"appService" | "fetchFn" | "apiBase" | "now"
|
|
47
47
|
>,
|
|
48
48
|
): InstallationRepoClient & InstalledOrgsClient {
|
|
49
|
-
const client = async (
|
|
49
|
+
const client = async (
|
|
50
|
+
accountId?: string | null,
|
|
51
|
+
): Promise<GithubEnterpriseClient> => {
|
|
50
52
|
const [installer, privateKey] = await Promise.all([
|
|
51
|
-
deps.appService.get("installer"),
|
|
52
|
-
deps.appService.getPrivateKey("installer"),
|
|
53
|
+
deps.appService.get("installer", accountId),
|
|
54
|
+
deps.appService.getPrivateKey("installer", accountId),
|
|
53
55
|
]);
|
|
54
56
|
if (!installer?.enterpriseSlug || !privateKey) {
|
|
55
57
|
throw new Error("installer App is not configured");
|
|
@@ -64,16 +66,16 @@ function lazyInstallerClient(
|
|
|
64
66
|
});
|
|
65
67
|
};
|
|
66
68
|
return {
|
|
67
|
-
listInstallableOrganizations: async () =>
|
|
68
|
-
(await client()).listInstallableOrganizations(),
|
|
69
|
-
listOrgInstallations: async (org) =>
|
|
70
|
-
(await client()).listOrgInstallations(org),
|
|
71
|
-
listInstallationRepositories: async (org, id) =>
|
|
72
|
-
(await client()).listInstallationRepositories(org, id),
|
|
73
|
-
addRepositories: async (org, id, names) =>
|
|
74
|
-
(await client()).addRepositories(org, id, names),
|
|
75
|
-
removeRepositories: async (org, id, names) =>
|
|
76
|
-
(await client()).removeRepositories(org, id, names),
|
|
69
|
+
listInstallableOrganizations: async (accountId) =>
|
|
70
|
+
(await client(accountId)).listInstallableOrganizations(),
|
|
71
|
+
listOrgInstallations: async (org, accountId) =>
|
|
72
|
+
(await client(accountId)).listOrgInstallations(org),
|
|
73
|
+
listInstallationRepositories: async (org, id, accountId) =>
|
|
74
|
+
(await client(accountId)).listInstallationRepositories(org, id),
|
|
75
|
+
addRepositories: async (org, id, names, accountId) =>
|
|
76
|
+
(await client(accountId)).addRepositories(org, id, names),
|
|
77
|
+
removeRepositories: async (org, id, names, accountId) =>
|
|
78
|
+
(await client(accountId)).removeRepositories(org, id, names),
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
|