@crombolo/server 0.43.1 → 0.45.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/package.json +20 -14
- package/src/adapters/health.ts +48 -0
- package/src/bundle-admin.ts +235 -0
- package/src/bundle-build.ts +6 -2
- package/src/bundle-code-install.ts +168 -0
- package/src/bundle-install.ts +80 -2
- package/src/config.ts +61 -2
- package/src/core.ts +5 -1
- package/src/form-submit.ts +32 -5
- package/src/form-workflows.ts +7 -1
- package/src/index.ts +4 -0
- package/src/marketplace.ts +277 -65
- package/src/no-nodes.ts +1 -1
- package/src/provenance.ts +466 -0
- package/src/remote-ci.ts +334 -0
- package/src/remote.ts +679 -14
- package/src/restart-pending.ts +52 -0
- package/src/schema.ts +7 -0
- package/src/seed/compile.ts +17 -15
- package/src/seed/export.ts +16 -9
- package/src/seed/read.ts +43 -13
- package/src/server.ts +113 -67
- package/src/settings.ts +29 -4
package/src/remote.ts
CHANGED
|
@@ -17,15 +17,45 @@ import { tmpdir } from 'node:os'
|
|
|
17
17
|
import { join, sep } from 'node:path'
|
|
18
18
|
import { hasSection, type Principal } from '@crombolo/api-management/domain'
|
|
19
19
|
import { DEVICE_CODE_GRANT, REMOTE_CLIENT_ID } from '@crombolo/auth'
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
import {
|
|
21
|
+
EXPLICIT_PERMISSIONS,
|
|
22
|
+
managementApiPath,
|
|
23
|
+
RemotePermissions,
|
|
24
|
+
type RemoteVerb,
|
|
25
|
+
} from '@crombolo/core'
|
|
26
|
+
import {
|
|
27
|
+
AuditLog,
|
|
28
|
+
auditRecord,
|
|
29
|
+
type Db,
|
|
30
|
+
type RemoteJob,
|
|
31
|
+
RemoteJobRepository,
|
|
32
|
+
RemoteTrustRepository,
|
|
33
|
+
TransferRunRepository,
|
|
34
|
+
type TrustRule,
|
|
35
|
+
} from '@crombolo/data'
|
|
36
|
+
import {
|
|
37
|
+
type ContentSet,
|
|
38
|
+
isResolution,
|
|
39
|
+
type NodeResolutions,
|
|
40
|
+
type Resolution,
|
|
41
|
+
revertRun,
|
|
42
|
+
} from '@crombolo/transfer'
|
|
23
43
|
import { readAuditPageQuery, recordAudit } from './adapters/audit.ts'
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
44
|
+
import type { BundleAdmin } from './bundle-admin.ts'
|
|
45
|
+
import { codeChanges, installedCode, planCode } from './bundle-code-install.ts'
|
|
46
|
+
import {
|
|
47
|
+
checkBundleContent,
|
|
48
|
+
installBundleContent,
|
|
49
|
+
readBundle,
|
|
50
|
+
revertSections,
|
|
51
|
+
} from './bundle-install.ts'
|
|
52
|
+
import { carriesSections, type SectionFile, swappedSections } from './bundle-sections.ts'
|
|
53
|
+
import { type CromboloConfig, REMOTE_ACCESS_LEVELS, type RemoteAccess } from './config.ts'
|
|
26
54
|
import { answerContentQuery, contentQueryScope } from './content-query.ts'
|
|
27
55
|
import { mediaStoreFor } from './media-files.ts'
|
|
28
56
|
import { type MediaStore, streamOf } from './media-store.ts'
|
|
57
|
+
import { describeProvenance, provenanceProblem, verifyProvenance } from './provenance.ts'
|
|
58
|
+
import { createCiSignIn, readRuleInput, trustedIssuers } from './remote-ci.ts'
|
|
29
59
|
import { openSecret, sealSecret, usableSecretKey } from './secrets.ts'
|
|
30
60
|
import { exportSite } from './site-file.ts'
|
|
31
61
|
import { replaceSummary } from './site-replace.ts'
|
|
@@ -54,6 +84,16 @@ export interface RemoteOptions {
|
|
|
54
84
|
* import's cache instruction carries this node's id, and a node skips its own.
|
|
55
85
|
*/
|
|
56
86
|
onApplied?(): void
|
|
87
|
+
/** A new server from the supervising `crombolo start`, once it is healthy (story 241). */
|
|
88
|
+
restart?: () => Promise<RestartOutcome>
|
|
89
|
+
/** Installed bundles (story 241); absent where this node does not manage them. */
|
|
90
|
+
bundles?: BundleAdmin
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** What a supervised restart came to: the new server serving, or why the old one still is. */
|
|
94
|
+
export interface RestartOutcome {
|
|
95
|
+
ok: boolean
|
|
96
|
+
reason?: string
|
|
57
97
|
}
|
|
58
98
|
|
|
59
99
|
export interface Remote {
|
|
@@ -61,6 +101,11 @@ export interface Remote {
|
|
|
61
101
|
handle(request: Request, url: URL): Promise<Response | undefined>
|
|
62
102
|
/** Whether a request is an upload the remote takes beyond the usual body limit. */
|
|
63
103
|
isUpload(request: Request, url: URL): boolean
|
|
104
|
+
/**
|
|
105
|
+
* The trust rules (story 160), for the back office's CI access screen, which
|
|
106
|
+
* calls them under its own path: `rest` is `trust` or `trust/<key>[/<verb>]`.
|
|
107
|
+
*/
|
|
108
|
+
trust(request: Request, principal: Principal, rest: string): Promise<Response>
|
|
64
109
|
}
|
|
65
110
|
|
|
66
111
|
interface Problem {
|
|
@@ -76,8 +121,9 @@ const problem = (status: number, body: Problem) =>
|
|
|
76
121
|
headers: { 'content-type': 'application/problem+json' },
|
|
77
122
|
})
|
|
78
123
|
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
/** An administrator holds every remote permission but those a group has to name (story 241). */
|
|
125
|
+
export const may = (principal: Principal, verb: RemoteVerb) =>
|
|
126
|
+
(principal.isAdmin && !EXPLICIT_PERMISSIONS.has(verb)) || principal.permissions.includes(verb)
|
|
81
127
|
|
|
82
128
|
/** Who may read the audit log: whoever has its dashboard, in Settings. */
|
|
83
129
|
const mayReadAudit = (principal: Principal) => hasSection(principal, 'settings')
|
|
@@ -119,8 +165,25 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
119
165
|
id: settings.environment,
|
|
120
166
|
name: settings.environment,
|
|
121
167
|
protected: settings.protected,
|
|
168
|
+
access: level,
|
|
122
169
|
})
|
|
123
170
|
|
|
171
|
+
/** What the site takes (story 167): each level the ones before it and more. */
|
|
172
|
+
const level: RemoteAccess = settings.access ?? (settings.enabled ? 'all' : 'off')
|
|
173
|
+
const atLeast = (wanted: RemoteAccess) =>
|
|
174
|
+
REMOTE_ACCESS_LEVELS.indexOf(level) >= REMOTE_ACCESS_LEVELS.indexOf(wanted)
|
|
175
|
+
const notAtLevel = (wanted: RemoteAccess, what: string) =>
|
|
176
|
+
problem(403, {
|
|
177
|
+
code: 'access-level',
|
|
178
|
+
title: `This site does not take ${what}`,
|
|
179
|
+
detail: `Its CROMBOLO_REMOTE_ACCESS is ${level}; ${what} need ${wanted}.`,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
/** Who may change this site's content: Push, and PushProtected where it is protected. */
|
|
183
|
+
const mayChange = (principal: Principal) =>
|
|
184
|
+
may(principal, RemotePermissions.Push) &&
|
|
185
|
+
(!settings.protected || may(principal, RemotePermissions.PushProtected))
|
|
186
|
+
|
|
124
187
|
// Under the back office, as the editor's own API calls are; a command line
|
|
125
188
|
// follows these addresses rather than building its own.
|
|
126
189
|
const managementApi = managementApiPath(config.backOfficePath.replace(/\/+$/, ''))
|
|
@@ -134,17 +197,35 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
134
197
|
token: `${origin}${managementApi}/security/back-office/token`,
|
|
135
198
|
clientId: REMOTE_CLIENT_ID,
|
|
136
199
|
grantType: DEVICE_CODE_GRANT,
|
|
200
|
+
// Story 160: a CI job's identity token, exchanged for a token acting as a trust rule.
|
|
201
|
+
ci: ci.discovery(origin, `${origin}${REMOTE_API_PATH}`),
|
|
137
202
|
},
|
|
138
203
|
capabilities: [
|
|
204
|
+
...(atLeast('content') ? ['bundle-apply'] : []),
|
|
205
|
+
'ci-sign-in',
|
|
139
206
|
'media-fetch',
|
|
140
207
|
'push-check',
|
|
141
208
|
'audit',
|
|
142
209
|
'content-query',
|
|
143
210
|
...(settings.approvals ? ['approvals'] : []),
|
|
211
|
+
...(options.bundles && atLeast('read') ? ['bundle-manage'] : []),
|
|
212
|
+
...(options.restart && atLeast('all') ? ['restart'] : []),
|
|
144
213
|
],
|
|
145
214
|
environments: [environment()],
|
|
146
215
|
})
|
|
147
216
|
|
|
217
|
+
/** Where a CI principal's run was, for its audit rows: repository, ref and run. */
|
|
218
|
+
const ciRun = (principal: Principal) => {
|
|
219
|
+
const c = principal.ci?.claims
|
|
220
|
+
if (!c) return ''
|
|
221
|
+
const ref = c.ref
|
|
222
|
+
? ` ${c.refType ?? 'ref'} ${c.ref}`
|
|
223
|
+
: c.environment
|
|
224
|
+
? ` environment ${c.environment}`
|
|
225
|
+
: ''
|
|
226
|
+
return ` (CI: ${c.repository}${ref}${c.run ? `, run ${c.run}` : ''})`
|
|
227
|
+
}
|
|
228
|
+
|
|
148
229
|
const audit = (principal: Principal, request: Request, action: string, detail: string) =>
|
|
149
230
|
recordAudit(db, {
|
|
150
231
|
category: 'system',
|
|
@@ -156,9 +237,124 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
156
237
|
entityName: settings.environment,
|
|
157
238
|
ipAddress: null,
|
|
158
239
|
forwardedFor: request.headers.get('x-forwarded-for'),
|
|
159
|
-
detail
|
|
240
|
+
detail: `${detail}${ciRun(principal)}`,
|
|
160
241
|
})
|
|
161
242
|
|
|
243
|
+
const trust = new RemoteTrustRepository(db)
|
|
244
|
+
const ci = createCiSignIn({
|
|
245
|
+
db,
|
|
246
|
+
issuers: trustedIssuers(settings.oidcIssuers),
|
|
247
|
+
onExchange: (outcome, request) =>
|
|
248
|
+
recordAudit(db, {
|
|
249
|
+
category: 'system',
|
|
250
|
+
action: outcome.ok ? 'RemoteCiSignIn' : 'RemoteCiSignInRefused',
|
|
251
|
+
source: 'request',
|
|
252
|
+
userKey: outcome.ok ? outcome.rule.key : null,
|
|
253
|
+
userName: outcome.ok ? `CI: ${outcome.rule.name}` : null,
|
|
254
|
+
entityType: 'RemoteEnvironment',
|
|
255
|
+
entityName: settings.environment,
|
|
256
|
+
ipAddress: null,
|
|
257
|
+
forwardedFor: request.headers.get('x-forwarded-for'),
|
|
258
|
+
detail: outcome.ok
|
|
259
|
+
? `${outcome.claims.repository} ${outcome.claims.refType ?? ''} ${outcome.claims.ref ?? outcome.claims.environment ?? ''}${outcome.claims.run ? `, run ${outcome.claims.run}` : ''}`.replace(
|
|
260
|
+
/\s+/g,
|
|
261
|
+
' ',
|
|
262
|
+
)
|
|
263
|
+
: `Refused: ${outcome.reason}${outcome.repository ? ` (${outcome.repository})` : ''}`,
|
|
264
|
+
}),
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
/** A rule as the trust endpoints show it. */
|
|
268
|
+
const ruleView = (rule: TrustRule) => ({
|
|
269
|
+
key: rule.key,
|
|
270
|
+
name: rule.name,
|
|
271
|
+
issuer: rule.issuer,
|
|
272
|
+
repository: rule.repository,
|
|
273
|
+
refKind: rule.refKind,
|
|
274
|
+
refValue: rule.refValue,
|
|
275
|
+
permissions: rule.permissions,
|
|
276
|
+
disabled: rule.disabled,
|
|
277
|
+
createdBy: rule.createdBy,
|
|
278
|
+
createDate: rule.createDate.toISOString(),
|
|
279
|
+
lastUsedDate: rule.lastUsedDate?.toISOString() ?? null,
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
/** The trust rules, for administrators: a person, never CI, and never over a cross-site write. */
|
|
283
|
+
async function trustRoute(
|
|
284
|
+
request: Request,
|
|
285
|
+
principal: Principal,
|
|
286
|
+
rest: string,
|
|
287
|
+
): Promise<Response> {
|
|
288
|
+
if (!principal.isAdmin || principal.ci)
|
|
289
|
+
return problem(403, { code: 'forbidden', title: 'Only an administrator manages CI access' })
|
|
290
|
+
if (request.method !== 'GET' && !fromThisSiteOrBearer(request))
|
|
291
|
+
return new Response('Forbidden', { status: 403 })
|
|
292
|
+
const changed = (action: string, rule: TrustRule) =>
|
|
293
|
+
audit(
|
|
294
|
+
principal,
|
|
295
|
+
request,
|
|
296
|
+
action,
|
|
297
|
+
`${rule.name}: ${rule.repository} ${rule.refKind} ${rule.refValue}, may ${rule.permissions.join(', ')}`,
|
|
298
|
+
)
|
|
299
|
+
if (rest === 'trust') {
|
|
300
|
+
if (request.method === 'GET')
|
|
301
|
+
return Response.json({
|
|
302
|
+
// Rules can be made before the site answers as a remote; the screen says so.
|
|
303
|
+
remoteEnabled: settings.enabled,
|
|
304
|
+
issuers: ci.issuers,
|
|
305
|
+
permissions: Object.values(RemotePermissions),
|
|
306
|
+
items: (await trust.all()).map(ruleView),
|
|
307
|
+
})
|
|
308
|
+
if (request.method === 'POST') {
|
|
309
|
+
const { input, problems } = readRuleInput(
|
|
310
|
+
await request.json().catch(() => ({})),
|
|
311
|
+
ci.issuers,
|
|
312
|
+
)
|
|
313
|
+
if (!input)
|
|
314
|
+
return problem(400, {
|
|
315
|
+
code: 'invalid-rule',
|
|
316
|
+
title: 'That rule cannot be saved',
|
|
317
|
+
items: problems,
|
|
318
|
+
})
|
|
319
|
+
const rule = await trust.create(input, principal.name)
|
|
320
|
+
await changed('RemoteTrustRuleAdded', rule)
|
|
321
|
+
return Response.json(ruleView(rule), { status: 201 })
|
|
322
|
+
}
|
|
323
|
+
return new Response(null, { status: 405 })
|
|
324
|
+
}
|
|
325
|
+
const one = /^trust\/([0-9a-f-]{36})(?:\/(disable|enable))?$/.exec(rest)
|
|
326
|
+
if (!one) return problem(404, { code: 'not-found', title: 'There is no such rule' })
|
|
327
|
+
const [, key, action] = one as unknown as [string, string, string | undefined]
|
|
328
|
+
const existing = await trust.byKey(key)
|
|
329
|
+
if (!existing) return problem(404, { code: 'not-found', title: 'There is no such rule' })
|
|
330
|
+
if (action && request.method === 'POST') {
|
|
331
|
+
const rule = (await trust.setDisabled(key, action === 'disable')) as TrustRule
|
|
332
|
+
await changed(
|
|
333
|
+
action === 'disable' ? 'RemoteTrustRuleDisabled' : 'RemoteTrustRuleEnabled',
|
|
334
|
+
rule,
|
|
335
|
+
)
|
|
336
|
+
return Response.json(ruleView(rule))
|
|
337
|
+
}
|
|
338
|
+
if (!action && request.method === 'PUT') {
|
|
339
|
+
const { input, problems } = readRuleInput(await request.json().catch(() => ({})), ci.issuers)
|
|
340
|
+
if (!input)
|
|
341
|
+
return problem(400, {
|
|
342
|
+
code: 'invalid-rule',
|
|
343
|
+
title: 'That rule cannot be saved',
|
|
344
|
+
items: problems,
|
|
345
|
+
})
|
|
346
|
+
const rule = (await trust.update(key, input)) as TrustRule
|
|
347
|
+
await changed('RemoteTrustRuleChanged', rule)
|
|
348
|
+
return Response.json(ruleView(rule))
|
|
349
|
+
}
|
|
350
|
+
if (!action && request.method === 'DELETE') {
|
|
351
|
+
await trust.remove(key)
|
|
352
|
+
await changed('RemoteTrustRuleDeleted', existing)
|
|
353
|
+
return new Response(null, { status: 204 })
|
|
354
|
+
}
|
|
355
|
+
return new Response(null, { status: 405 })
|
|
356
|
+
}
|
|
357
|
+
|
|
162
358
|
/** A job as the protocol shows it; a running one gone quiet is reported as failed. */
|
|
163
359
|
const describe = async (job: RemoteJob, origin: string) => {
|
|
164
360
|
let current = job
|
|
@@ -433,6 +629,416 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
433
629
|
return { sha256: hasher.digest('hex'), size }
|
|
434
630
|
}
|
|
435
631
|
|
|
632
|
+
/** The options a bundle apply was sent with, in `Crombolo-Options` (story 167). */
|
|
633
|
+
const applyOptions = (request: Request) => {
|
|
634
|
+
let raw: Record<string, unknown> = {}
|
|
635
|
+
try {
|
|
636
|
+
raw = JSON.parse(request.headers.get('crombolo-options') ?? '{}') as Record<string, unknown>
|
|
637
|
+
} catch {
|
|
638
|
+
raw = {}
|
|
639
|
+
}
|
|
640
|
+
const resolutions =
|
|
641
|
+
raw.resolutions && typeof raw.resolutions === 'object'
|
|
642
|
+
? (raw.resolutions as Record<string, NodeResolutions>)
|
|
643
|
+
: undefined
|
|
644
|
+
const resolveAll =
|
|
645
|
+
typeof raw.resolveAll === 'string' && isResolution(raw.resolveAll)
|
|
646
|
+
? (raw.resolveAll as Resolution)
|
|
647
|
+
: undefined
|
|
648
|
+
return {
|
|
649
|
+
dryRun: raw.dryRun === true,
|
|
650
|
+
publish: raw.publish === true,
|
|
651
|
+
replaceFiles: raw.replaceFiles === true,
|
|
652
|
+
label: typeof raw.label === 'string' ? raw.label.slice(0, 200) : undefined,
|
|
653
|
+
resolutions,
|
|
654
|
+
resolveAll,
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* A bundle applied here (story 167): checked, and unless a dry run backed up
|
|
660
|
+
* and applied in one transaction as `bundle apply` does on a site's own
|
|
661
|
+
* machine. Content needs the `content` level and the right to change this
|
|
662
|
+
* site; schema, views or code need `all` and Crombolo.Remote.ApplyStructure.
|
|
663
|
+
*/
|
|
664
|
+
async function applyBundle(request: Request, principal: Principal): Promise<Response> {
|
|
665
|
+
if (!atLeast('content')) return notAtLevel('content', 'bundles')
|
|
666
|
+
if (!mayChange(principal))
|
|
667
|
+
return problem(403, { code: 'forbidden', title: 'You may not change this environment' })
|
|
668
|
+
const declared = request.headers.get('crombolo-sha256')?.toLowerCase()
|
|
669
|
+
if (!declared || !/^[0-9a-f]{64}$/.test(declared))
|
|
670
|
+
return problem(400, { code: 'hash-required', title: 'Crombolo-Sha256 is required' })
|
|
671
|
+
const asked = applyOptions(request)
|
|
672
|
+
const id = crypto.randomUUID()
|
|
673
|
+
const local = join(tmpdir(), `crombolo-remote-bundle-${id}.tgz`)
|
|
674
|
+
const dir = join(tmpdir(), `crombolo-remote-bundle-${id}`)
|
|
675
|
+
try {
|
|
676
|
+
let received: { sha256: string; size: number } | undefined
|
|
677
|
+
try {
|
|
678
|
+
received = await receive(request, local)
|
|
679
|
+
} catch {
|
|
680
|
+
return problem(413, {
|
|
681
|
+
code: 'too-large',
|
|
682
|
+
title: 'The bundle is larger than this remote takes',
|
|
683
|
+
})
|
|
684
|
+
}
|
|
685
|
+
if (!received)
|
|
686
|
+
return problem(400, { code: 'body-required', title: 'The request carried no bundle' })
|
|
687
|
+
if (received.sha256 !== declared)
|
|
688
|
+
return problem(400, {
|
|
689
|
+
code: 'hash-mismatch',
|
|
690
|
+
title: 'The bundle is not the one described',
|
|
691
|
+
detail:
|
|
692
|
+
'Its SHA-256 does not match Crombolo-Sha256: it was changed or cut short on the way.',
|
|
693
|
+
})
|
|
694
|
+
await extractTarball(local, dir)
|
|
695
|
+
let structural: boolean
|
|
696
|
+
let code: SectionFile[]
|
|
697
|
+
try {
|
|
698
|
+
const carried = readBundle(dir, config.siteDir).carried
|
|
699
|
+
structural = carriesSections(carried)
|
|
700
|
+
code = codeChanges(planCode(config, carried))
|
|
701
|
+
} catch (error) {
|
|
702
|
+
return problem(400, {
|
|
703
|
+
code: 'not-a-bundle',
|
|
704
|
+
title: 'That is not a bundle this site can read',
|
|
705
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
706
|
+
})
|
|
707
|
+
}
|
|
708
|
+
// Where it was built, before the rest is weighed (story 060).
|
|
709
|
+
const provenance = await verifyProvenance(dir)
|
|
710
|
+
const signatureRefused = provenanceProblem(provenance, config.bundlePolicy)
|
|
711
|
+
if (signatureRefused)
|
|
712
|
+
return problem(403, {
|
|
713
|
+
code: 'signature-refused',
|
|
714
|
+
title: 'This site does not take that bundle',
|
|
715
|
+
detail: `It is refused: ${signatureRefused}.`,
|
|
716
|
+
})
|
|
717
|
+
if (structural && !atLeast('all'))
|
|
718
|
+
return notAtLevel('all', 'bundles that change content types, views or code')
|
|
719
|
+
if (structural && !may(principal, RemotePermissions.ApplyStructure))
|
|
720
|
+
return problem(403, {
|
|
721
|
+
code: 'forbidden-structure',
|
|
722
|
+
title: "You may not change this site's structure",
|
|
723
|
+
detail:
|
|
724
|
+
'The bundle carries content types, views or code, which needs Crombolo.Remote.ApplyStructure.',
|
|
725
|
+
})
|
|
726
|
+
// Code that would change this site's files (story 241): installed here, and
|
|
727
|
+
// only by someone a group has given InstallCode, administrators included.
|
|
728
|
+
if (code.length > 0 && !config.runtimeInstalls)
|
|
729
|
+
return problem(409, {
|
|
730
|
+
code: 'installs-elsewhere',
|
|
731
|
+
title: 'This site does not install code while it runs',
|
|
732
|
+
detail:
|
|
733
|
+
config.installsElsewhere?.message ??
|
|
734
|
+
"Add the bundle's code to the site and deploy it the way this site is deployed.",
|
|
735
|
+
})
|
|
736
|
+
if (code.length > 0 && !may(principal, RemotePermissions.InstallCode))
|
|
737
|
+
return problem(403, {
|
|
738
|
+
code: 'forbidden-code',
|
|
739
|
+
title: 'You may not install code on this site',
|
|
740
|
+
detail: `The bundle would change ${code.length} code file(s) here, which needs Crombolo.Remote.InstallCode, given by a group.`,
|
|
741
|
+
items: code.map((file) => file.path),
|
|
742
|
+
})
|
|
743
|
+
const input = {
|
|
744
|
+
bundle: dir,
|
|
745
|
+
publish: asked.publish,
|
|
746
|
+
replaceFiles: asked.replaceFiles,
|
|
747
|
+
installCode: code.length > 0,
|
|
748
|
+
resolutions: asked.resolutions,
|
|
749
|
+
resolveAll: asked.resolveAll,
|
|
750
|
+
by: principal.name,
|
|
751
|
+
}
|
|
752
|
+
const report = (check: {
|
|
753
|
+
counts: unknown
|
|
754
|
+
findings: Array<{ kind: string; code: string; key?: string; message: string }>
|
|
755
|
+
outstanding: unknown[]
|
|
756
|
+
}) => ({
|
|
757
|
+
counts: check.counts,
|
|
758
|
+
findings: check.findings.map((f) => ({
|
|
759
|
+
kind: f.kind,
|
|
760
|
+
code: f.code,
|
|
761
|
+
key: f.key ?? null,
|
|
762
|
+
message: f.message,
|
|
763
|
+
})),
|
|
764
|
+
outstanding: check.outstanding.length,
|
|
765
|
+
})
|
|
766
|
+
if (asked.dryRun) {
|
|
767
|
+
const checked = await checkBundleContent(db, config, input)
|
|
768
|
+
return Response.json({
|
|
769
|
+
dryRun: true,
|
|
770
|
+
structural,
|
|
771
|
+
provenance,
|
|
772
|
+
code: code.map((file) => ({ path: file.path, action: file.action })),
|
|
773
|
+
bundle: checked.bundle,
|
|
774
|
+
...report(checked.check),
|
|
775
|
+
clean: checked.clean,
|
|
776
|
+
problems: checked.problems,
|
|
777
|
+
})
|
|
778
|
+
}
|
|
779
|
+
// A backup wherever this server can take one; on Postgres that needs CROMBOLO_PG_DUMP.
|
|
780
|
+
const canBackUp = config.dialect === 'sqlite' || Boolean(config.pgDump)
|
|
781
|
+
const result = await installBundleContent(db, config, {
|
|
782
|
+
...input,
|
|
783
|
+
backupTaken: !canBackUp,
|
|
784
|
+
label: asked.label ?? `bundle from ${principal.name}`,
|
|
785
|
+
})
|
|
786
|
+
if (result.runId) {
|
|
787
|
+
await audit(
|
|
788
|
+
principal,
|
|
789
|
+
request,
|
|
790
|
+
'RemoteBundleApplied',
|
|
791
|
+
`${result.bundle.id} as run ${result.runId}${structural ? ', with structure' : ''}; ${describeProvenance(provenance)}`,
|
|
792
|
+
)
|
|
793
|
+
options.onApplied?.()
|
|
794
|
+
}
|
|
795
|
+
return Response.json(
|
|
796
|
+
{
|
|
797
|
+
dryRun: false,
|
|
798
|
+
structural,
|
|
799
|
+
provenance,
|
|
800
|
+
code: result.code
|
|
801
|
+
? { written: result.code.written.length, installed: result.code.installed, live: false }
|
|
802
|
+
: null,
|
|
803
|
+
bundle: result.bundle,
|
|
804
|
+
runId: result.runId ?? null,
|
|
805
|
+
...report(result.check),
|
|
806
|
+
problems: result.problems,
|
|
807
|
+
published: result.published,
|
|
808
|
+
notPublished: result.publishFailures,
|
|
809
|
+
},
|
|
810
|
+
{ status: result.runId ? 200 : 409 },
|
|
811
|
+
)
|
|
812
|
+
} finally {
|
|
813
|
+
await rm(local, { force: true })
|
|
814
|
+
await rm(dir, { recursive: true, force: true })
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** The applies on this site, newest first: for `bundle runs --remote`. */
|
|
819
|
+
async function listRuns(url: URL, principal: Principal): Promise<Response> {
|
|
820
|
+
if (!atLeast('read')) return notAtLevel('read', 'reads')
|
|
821
|
+
if (!may(principal, RemotePermissions.Pull) && !mayChange(principal))
|
|
822
|
+
return problem(403, { code: 'forbidden', title: 'You may not read this environment' })
|
|
823
|
+
const take = Math.min(Number(url.searchParams.get('limit') ?? 20) || 20, 200)
|
|
824
|
+
const skip = Number(url.searchParams.get('offset') ?? 0) || 0
|
|
825
|
+
const runs = new TransferRunRepository(db)
|
|
826
|
+
const [items, total] = await Promise.all([runs.recent(take, skip), runs.count()])
|
|
827
|
+
return Response.json({
|
|
828
|
+
total,
|
|
829
|
+
items: items.map((run) => ({
|
|
830
|
+
id: run.id,
|
|
831
|
+
startedAt: run.startedAt.toISOString(),
|
|
832
|
+
direction: run.direction,
|
|
833
|
+
status: run.status,
|
|
834
|
+
nodeCount: run.nodeCount,
|
|
835
|
+
bundleId: run.bundleId,
|
|
836
|
+
bundleLabel: run.bundleLabel ?? null,
|
|
837
|
+
appliedBy: run.appliedBy ?? null,
|
|
838
|
+
})),
|
|
839
|
+
})
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Installed bundles (story 241), as Settings → Bundles manages them: listed
|
|
844
|
+
* at `read`; installed, removed, disabled and enabled at `all`. Installing or
|
|
845
|
+
* removing changes the code the server loads, so it also needs
|
|
846
|
+
* ApplyStructure and InstallCode, which an administrator holds only when a
|
|
847
|
+
* group gives it to them, and a site that installs at runtime.
|
|
848
|
+
*/
|
|
849
|
+
async function manageBundles(
|
|
850
|
+
request: Request,
|
|
851
|
+
principal: Principal,
|
|
852
|
+
what: string,
|
|
853
|
+
): Promise<Response> {
|
|
854
|
+
const bundles = options.bundles
|
|
855
|
+
if (!bundles)
|
|
856
|
+
return problem(404, { code: 'not-found', title: 'This remote does not manage bundles' })
|
|
857
|
+
const actor = {
|
|
858
|
+
id: principal.ci ? null : principal.id,
|
|
859
|
+
name: `${principal.name}${ciRun(principal)}`,
|
|
860
|
+
email: principal.ci ? null : principal.email,
|
|
861
|
+
source: 'request' as const,
|
|
862
|
+
ipAddress: null,
|
|
863
|
+
forwardedFor: request.headers.get('x-forwarded-for'),
|
|
864
|
+
}
|
|
865
|
+
if (what === 'installed' && request.method === 'GET') {
|
|
866
|
+
if (!atLeast('read')) return notAtLevel('read', 'reads')
|
|
867
|
+
if (!may(principal, RemotePermissions.Pull) && !mayChange(principal))
|
|
868
|
+
return problem(403, { code: 'forbidden', title: 'You may not read this environment' })
|
|
869
|
+
return Response.json(await bundles.installed())
|
|
870
|
+
}
|
|
871
|
+
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
872
|
+
if (!atLeast('all')) return notAtLevel('all', 'installing and switching bundles')
|
|
873
|
+
const switched = /^installed\/(.+)\/(disable|enable)$/.exec(what)
|
|
874
|
+
if (switched && request.method === 'POST') {
|
|
875
|
+
if (principal.ci ? !may(principal, RemotePermissions.ApplyStructure) : !principal.isAdmin)
|
|
876
|
+
return problem(403, {
|
|
877
|
+
code: 'forbidden',
|
|
878
|
+
title: 'Only an administrator turns bundles off and on',
|
|
879
|
+
})
|
|
880
|
+
const { status, ...outcome } = await bundles.setEnabled(
|
|
881
|
+
actor,
|
|
882
|
+
decodeURIComponent(switched[1] as string),
|
|
883
|
+
switched[2] === 'enable',
|
|
884
|
+
)
|
|
885
|
+
return status === 200
|
|
886
|
+
? Response.json(outcome)
|
|
887
|
+
: problem(status, { code: 'not-found', title: outcome.message })
|
|
888
|
+
}
|
|
889
|
+
const installing = what === 'installed' && request.method === 'POST'
|
|
890
|
+
const removing = /^installed\/[^/]/.test(what) && request.method === 'DELETE'
|
|
891
|
+
if (!installing && !removing) return new Response(null, { status: 405 })
|
|
892
|
+
if (!mayChange(principal) || !may(principal, RemotePermissions.ApplyStructure))
|
|
893
|
+
return problem(403, {
|
|
894
|
+
code: 'forbidden-structure',
|
|
895
|
+
title: "You may not change this site's structure",
|
|
896
|
+
detail: 'Installing or removing a bundle needs Crombolo.Remote.ApplyStructure.',
|
|
897
|
+
})
|
|
898
|
+
if (!may(principal, RemotePermissions.InstallCode))
|
|
899
|
+
return problem(403, {
|
|
900
|
+
code: 'forbidden-code',
|
|
901
|
+
title: 'You may not install code on this site',
|
|
902
|
+
detail:
|
|
903
|
+
'It needs "Install code on this site" (Crombolo.Remote.InstallCode), which only a group that names it gives, administrators included.',
|
|
904
|
+
})
|
|
905
|
+
if (!config.runtimeInstalls)
|
|
906
|
+
return problem(409, {
|
|
907
|
+
code: 'installs-elsewhere',
|
|
908
|
+
title: 'This site does not install bundles while it runs',
|
|
909
|
+
detail:
|
|
910
|
+
config.installsElsewhere?.message ??
|
|
911
|
+
"Add the bundle to the site's package.json and deploy it, so every server has it.",
|
|
912
|
+
})
|
|
913
|
+
if (removing) {
|
|
914
|
+
const name = decodeURIComponent(what.slice('installed/'.length))
|
|
915
|
+
const outcome = await bundles.uninstall(actor, name)
|
|
916
|
+
return outcome.ok
|
|
917
|
+
? Response.json(outcome)
|
|
918
|
+
: problem(409, { code: 'uninstall-refused', title: outcome.message })
|
|
919
|
+
}
|
|
920
|
+
const body = (await request.json().catch(() => ({}))) as Record<string, unknown>
|
|
921
|
+
const name = typeof body.name === 'string' ? body.name : ''
|
|
922
|
+
const grant = Array.isArray(body.grant)
|
|
923
|
+
? body.grant.filter((p): p is string => typeof p === 'string')
|
|
924
|
+
: []
|
|
925
|
+
const outcome = await bundles.install(actor, {
|
|
926
|
+
name,
|
|
927
|
+
version: typeof body.version === 'string' ? body.version : undefined,
|
|
928
|
+
applyContent: body.applyContent === true,
|
|
929
|
+
// Naming the grant is the consent: a script that names what it grants has said yes.
|
|
930
|
+
acceptServerCode: true,
|
|
931
|
+
grant,
|
|
932
|
+
})
|
|
933
|
+
if (outcome.ok) return Response.json(outcome)
|
|
934
|
+
if (outcome.needsServerConsent) {
|
|
935
|
+
const asked = (outcome.permissions ?? []).map((p) => p.permission)
|
|
936
|
+
const missing = asked.filter((p) => !grant.includes(p))
|
|
937
|
+
const extra = grant.filter((p) => !asked.includes(p))
|
|
938
|
+
return problem(409, {
|
|
939
|
+
code: 'grant-mismatch',
|
|
940
|
+
title: `${name} asks for other permissions than were granted`,
|
|
941
|
+
detail: outcome.message,
|
|
942
|
+
items: [
|
|
943
|
+
...missing.map((p) => `not granted: ${p}`),
|
|
944
|
+
...extra.map((p) => `not asked for: ${p}`),
|
|
945
|
+
],
|
|
946
|
+
})
|
|
947
|
+
}
|
|
948
|
+
return problem(409, { code: 'install-refused', title: outcome.message })
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/** Undoes an apply (story 167), as `bundle revert` does here; files it replaced come back too. */
|
|
952
|
+
async function revertBundleRun(
|
|
953
|
+
request: Request,
|
|
954
|
+
principal: Principal,
|
|
955
|
+
runId: string,
|
|
956
|
+
): Promise<Response> {
|
|
957
|
+
if (!atLeast('content')) return notAtLevel('content', 'reverts')
|
|
958
|
+
if (!mayChange(principal))
|
|
959
|
+
return problem(403, { code: 'forbidden', title: 'You may not change this environment' })
|
|
960
|
+
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
961
|
+
const body = (await request.json().catch(() => ({}))) as { force?: unknown }
|
|
962
|
+
// A run that installed code changes code back, which needs what it did.
|
|
963
|
+
if (
|
|
964
|
+
installedCode(config, runId) &&
|
|
965
|
+
(!atLeast('all') ||
|
|
966
|
+
!may(principal, RemotePermissions.ApplyStructure) ||
|
|
967
|
+
!may(principal, RemotePermissions.InstallCode))
|
|
968
|
+
)
|
|
969
|
+
return problem(403, {
|
|
970
|
+
code: 'forbidden-code',
|
|
971
|
+
title: "Reverting that run changes this site's code",
|
|
972
|
+
detail:
|
|
973
|
+
'It needs CROMBOLO_REMOTE_ACCESS=all, Crombolo.Remote.ApplyStructure and Crombolo.Remote.InstallCode.',
|
|
974
|
+
})
|
|
975
|
+
// A run that replaced files changes structure back, which needs the same as it did.
|
|
976
|
+
const swapped = swappedSections(config, runId)
|
|
977
|
+
if (
|
|
978
|
+
swapped.length > 0 &&
|
|
979
|
+
(!atLeast('all') || !may(principal, RemotePermissions.ApplyStructure))
|
|
980
|
+
)
|
|
981
|
+
return problem(403, {
|
|
982
|
+
code: 'forbidden-structure',
|
|
983
|
+
title: "Reverting that run changes this site's structure",
|
|
984
|
+
detail: 'It needs CROMBOLO_REMOTE_ACCESS=all and Crombolo.Remote.ApplyStructure.',
|
|
985
|
+
})
|
|
986
|
+
const result = await revertRun(db, runId, {
|
|
987
|
+
force: body.force === true,
|
|
988
|
+
nodeId: config.nodeId,
|
|
989
|
+
backOfficePath: config.backOfficePath,
|
|
990
|
+
})
|
|
991
|
+
if (!result.runId)
|
|
992
|
+
return problem(409, {
|
|
993
|
+
code: 'revert-refused',
|
|
994
|
+
title: 'The revert was refused; nothing was changed',
|
|
995
|
+
items: result.check.findings.map((f) => f.message),
|
|
996
|
+
})
|
|
997
|
+
const files = await revertSections(db, config, runId)
|
|
998
|
+
await audit(principal, request, 'RemoteBundleReverted', `${runId} as run ${result.runId}`)
|
|
999
|
+
options.onApplied?.()
|
|
1000
|
+
return Response.json({
|
|
1001
|
+
runId: result.runId,
|
|
1002
|
+
reverted: runId,
|
|
1003
|
+
restored: result.restored,
|
|
1004
|
+
recycled: result.recycled,
|
|
1005
|
+
files,
|
|
1006
|
+
})
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* A new server, through the supervising `crombolo start` (story 241): any
|
|
1011
|
+
* administrator, or CI whose rule may install code, at the `all` level.
|
|
1012
|
+
*/
|
|
1013
|
+
async function restartSite(request: Request, principal: Principal): Promise<Response> {
|
|
1014
|
+
if (!atLeast('all')) return notAtLevel('all', 'restarts')
|
|
1015
|
+
const allowed = principal.ci ? may(principal, RemotePermissions.InstallCode) : principal.isAdmin
|
|
1016
|
+
if (!allowed)
|
|
1017
|
+
return problem(403, { code: 'forbidden', title: 'Only an administrator restarts this site' })
|
|
1018
|
+
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
1019
|
+
if (!options.restart)
|
|
1020
|
+
return problem(409, {
|
|
1021
|
+
code: 'not-supervised',
|
|
1022
|
+
title: 'Nothing here can restart this site',
|
|
1023
|
+
detail:
|
|
1024
|
+
'It was not started with `crombolo start`, which restarts it; restart it the way its host does.',
|
|
1025
|
+
})
|
|
1026
|
+
const outcome = await options.restart()
|
|
1027
|
+
await audit(
|
|
1028
|
+
principal,
|
|
1029
|
+
request,
|
|
1030
|
+
outcome.ok ? 'RemoteRestart' : 'RemoteRestartFailed',
|
|
1031
|
+
outcome.ok ? 'a new server is serving' : (outcome.reason ?? 'the new server did not start'),
|
|
1032
|
+
)
|
|
1033
|
+
if (!outcome.ok)
|
|
1034
|
+
return problem(502, {
|
|
1035
|
+
code: 'restart-failed',
|
|
1036
|
+
title: 'The new server did not start; the old one is still serving',
|
|
1037
|
+
detail: outcome.reason,
|
|
1038
|
+
})
|
|
1039
|
+
return Response.json({ restarted: true })
|
|
1040
|
+
}
|
|
1041
|
+
|
|
436
1042
|
async function startPush(request: Request, url: URL, principal: Principal): Promise<Response> {
|
|
437
1043
|
if (!may(principal, RemotePermissions.Push))
|
|
438
1044
|
return problem(403, { code: 'forbidden', title: 'You may not push to this environment' })
|
|
@@ -513,6 +1119,9 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
513
1119
|
approve: boolean,
|
|
514
1120
|
): Promise<Response> {
|
|
515
1121
|
if (!fromThisSiteOrBearer(request)) return new Response('Forbidden', { status: 403 })
|
|
1122
|
+
// CI never approves, whatever its rule holds: a second person is the point.
|
|
1123
|
+
if (principal.ci)
|
|
1124
|
+
return problem(403, { code: 'ci-cannot-approve', title: 'CI cannot approve pushes' })
|
|
516
1125
|
const job = await jobs.get(id)
|
|
517
1126
|
if (job?.kind !== 'push')
|
|
518
1127
|
return problem(404, { code: 'not-found', title: 'There is no such push' })
|
|
@@ -710,10 +1319,16 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
710
1319
|
}
|
|
711
1320
|
|
|
712
1321
|
return {
|
|
1322
|
+
trust: trustRoute,
|
|
1323
|
+
|
|
713
1324
|
isUpload(request, url) {
|
|
714
1325
|
if (!settings.enabled || request.method !== 'PUT') return false
|
|
715
1326
|
const prefix = `${REMOTE_API_PATH}/environments/${settings.environment}/`
|
|
716
|
-
return
|
|
1327
|
+
return (
|
|
1328
|
+
url.pathname === `${prefix}pushes` ||
|
|
1329
|
+
url.pathname === `${prefix}bundles` ||
|
|
1330
|
+
url.pathname.startsWith(`${prefix}media/`)
|
|
1331
|
+
)
|
|
717
1332
|
},
|
|
718
1333
|
|
|
719
1334
|
async handle(request, url) {
|
|
@@ -727,7 +1342,12 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
727
1342
|
if (!pathname.startsWith(`${REMOTE_API_PATH}/`)) return undefined
|
|
728
1343
|
if (!settings.enabled)
|
|
729
1344
|
return problem(404, { code: 'not-enabled', title: 'This site is not a remote' })
|
|
730
|
-
|
|
1345
|
+
if (pathname === `${REMOTE_API_PATH}/token`)
|
|
1346
|
+
return request.method === 'POST'
|
|
1347
|
+
? ci.exchange(request, url, request.headers.get('x-forwarded-for')?.split(',')[0]?.trim())
|
|
1348
|
+
: new Response(null, { status: 405 })
|
|
1349
|
+
// A CI token is good here and nowhere else; a person's is the back office's own.
|
|
1350
|
+
const principal = (await ci.principalOf(request)) ?? (await options.authenticate(request))
|
|
731
1351
|
if (!principal)
|
|
732
1352
|
return problem(401, {
|
|
733
1353
|
code: 'sign-in-required',
|
|
@@ -736,16 +1356,33 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
736
1356
|
})
|
|
737
1357
|
const rest = pathname.slice(REMOTE_API_PATH.length + 1)
|
|
738
1358
|
|
|
1359
|
+
// Who this is, for `crombolo whoami`: a person, or CI acting by a rule.
|
|
1360
|
+
if (rest === 'me' && request.method === 'GET')
|
|
1361
|
+
return Response.json({
|
|
1362
|
+
name: principal.name,
|
|
1363
|
+
kind: principal.ci ? 'ci' : 'person',
|
|
1364
|
+
...(principal.ci ? { rule: principal.ci.rule, run: principal.ci.claims } : {}),
|
|
1365
|
+
permissions: Object.values(RemotePermissions).filter((verb) => may(principal, verb)),
|
|
1366
|
+
})
|
|
1367
|
+
if (rest === 'trust' || rest.startsWith('trust/')) return trustRoute(request, principal, rest)
|
|
1368
|
+
|
|
739
1369
|
if (rest === 'environments' && request.method === 'GET')
|
|
740
1370
|
return Response.json([
|
|
741
1371
|
{
|
|
742
1372
|
...environment(),
|
|
743
1373
|
may: {
|
|
744
|
-
pull: may(principal, RemotePermissions.Pull),
|
|
745
|
-
pullFull: may(principal, RemotePermissions.PullFull),
|
|
1374
|
+
pull: atLeast('read') && may(principal, RemotePermissions.Pull),
|
|
1375
|
+
pullFull: atLeast('read') && may(principal, RemotePermissions.PullFull),
|
|
1376
|
+
// A whole-site push changes structure, so it needs that right and the top level.
|
|
746
1377
|
push:
|
|
747
|
-
|
|
748
|
-
(
|
|
1378
|
+
atLeast('all') &&
|
|
1379
|
+
mayChange(principal) &&
|
|
1380
|
+
may(principal, RemotePermissions.ApplyStructure),
|
|
1381
|
+
apply: atLeast('content') && mayChange(principal),
|
|
1382
|
+
applyStructure:
|
|
1383
|
+
atLeast('all') &&
|
|
1384
|
+
mayChange(principal) &&
|
|
1385
|
+
may(principal, RemotePermissions.ApplyStructure),
|
|
749
1386
|
audit: mayReadAudit(principal),
|
|
750
1387
|
},
|
|
751
1388
|
},
|
|
@@ -790,6 +1427,34 @@ export function createRemote(options: RemoteOptions): Remote {
|
|
|
790
1427
|
await request.json().catch(() => undefined),
|
|
791
1428
|
)
|
|
792
1429
|
}
|
|
1430
|
+
if (what === 'restart' && request.method === 'POST') return restartSite(request, principal)
|
|
1431
|
+
if (what === 'installed' || what.startsWith('installed/'))
|
|
1432
|
+
return manageBundles(request, principal, what)
|
|
1433
|
+
// Story 167: the site's level first, then the person's permissions.
|
|
1434
|
+
const pulling =
|
|
1435
|
+
what === 'pulls' ||
|
|
1436
|
+
what === 'media/links' ||
|
|
1437
|
+
(what.startsWith('media/') && request.method === 'GET')
|
|
1438
|
+
const pushing =
|
|
1439
|
+
what === 'pushes' ||
|
|
1440
|
+
what === 'pushes/check' ||
|
|
1441
|
+
what === 'media/have' ||
|
|
1442
|
+
(what.startsWith('media/') && request.method === 'PUT')
|
|
1443
|
+
if (pulling && !atLeast('read')) return notAtLevel('read', 'pulls')
|
|
1444
|
+
if (pushing && !atLeast('all')) return notAtLevel('all', 'whole-site pushes')
|
|
1445
|
+
// Push and protection are refused by their own routes first, as before story 167.
|
|
1446
|
+
if (pushing && mayChange(principal) && !may(principal, RemotePermissions.ApplyStructure))
|
|
1447
|
+
return problem(403, {
|
|
1448
|
+
code: 'forbidden-structure',
|
|
1449
|
+
title: 'You may not push a whole site here',
|
|
1450
|
+
detail:
|
|
1451
|
+
"A push replaces the site's content types, views and code, which needs Crombolo.Remote.ApplyStructure.",
|
|
1452
|
+
})
|
|
1453
|
+
if (what === 'bundles' && request.method === 'PUT') return applyBundle(request, principal)
|
|
1454
|
+
if (what === 'runs' && request.method === 'GET') return listRuns(url, principal)
|
|
1455
|
+
const revert = /^runs\/([0-9a-f-]{36})\/revert$/.exec(what)
|
|
1456
|
+
if (revert && request.method === 'POST')
|
|
1457
|
+
return revertBundleRun(request, principal, revert[1] as string)
|
|
793
1458
|
if (what === 'pulls' && request.method === 'POST') return startPull(request, url, principal)
|
|
794
1459
|
if (what === 'pushes' && request.method === 'PUT') return startPush(request, url, principal)
|
|
795
1460
|
if (what === 'pushes/check' && request.method === 'POST') {
|