@fabrika/provider-cloudflare 0.9.0-dev.4 → 0.9.0-dev.6
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 +11 -10
- package/src/authoring.ts +56 -6
- package/src/bounds.ts +145 -4
- package/src/cli.ts +14 -0
- package/src/command.ts +29 -4
- package/src/contract-support.ts +235 -0
- package/src/control.ts +55 -118
- package/src/deploy-order.ts +35 -0
- package/src/index.ts +19 -3
- package/src/installation/init.ts +11 -18
- package/src/installation/installation.ts +2 -4
- package/src/installation/scaffold.ts +29 -2
- package/src/installation/templates/README.md +29 -11
- package/src/installation/templates/platform.yml +9 -5
- package/src/managed-secrets.ts +61 -0
- package/src/plan.ts +13 -3
- package/src/provider.ts +455 -64
- package/src/proxy-worker.ts +40 -16
- package/src/proxy.ts +48 -16
- package/src/runner-protocol.ts +35 -2
- package/src/spa-assets.ts +176 -0
- package/types/src/authoring.d.ts +27 -5
- package/types/src/bounds.d.ts +19 -0
- package/types/src/cli.d.ts +6 -0
- package/types/src/command.d.ts +8 -3
- package/types/src/contract-support.d.ts +80 -0
- package/types/src/control.d.ts +108 -69
- package/types/src/deploy-order.d.ts +8 -0
- package/types/src/index.d.ts +3 -3
- package/types/src/managed-secrets.d.ts +19 -0
- package/types/src/plan.d.ts +2 -1
- package/types/src/provider.d.ts +38 -1
- package/types/src/proxy-worker.d.ts +1 -0
- package/types/src/proxy.d.ts +21 -0
- package/types/src/runner-protocol.d.ts +32 -0
- package/types/src/spa-assets.d.ts +28 -0
package/src/installation/init.ts
CHANGED
|
@@ -21,17 +21,20 @@ import {
|
|
|
21
21
|
confirmations,
|
|
22
22
|
detail,
|
|
23
23
|
type EnvironmentConfig,
|
|
24
|
+
generateSigningKeys,
|
|
25
|
+
generateVaultKey,
|
|
24
26
|
ghRepoExists,
|
|
25
27
|
info,
|
|
26
28
|
type InstallationEmail,
|
|
27
29
|
ok,
|
|
28
30
|
type ProtectionOutcome,
|
|
31
|
+
randomPxKey,
|
|
32
|
+
randomSecret,
|
|
29
33
|
step,
|
|
30
34
|
triggerPlatformWorkflow,
|
|
31
35
|
url,
|
|
32
36
|
warn,
|
|
33
37
|
} from '@fabrika/installation-init'
|
|
34
|
-
import { createHash, generateKeyPairSync, randomBytes } from 'node:crypto'
|
|
35
38
|
import { type CfAccount, type CfZone, findZone, listAccounts, selectAccount, verifyToken } from './cloudflare'
|
|
36
39
|
import { envPath, fromEnv, openEnvFile, persistEnv } from './envfile'
|
|
37
40
|
import { type InitInput, parseInitAccount, parseInitArgs, PLACEHOLDER_OIDC_CLIENT_ID, rerunCommand } from './init-options'
|
|
@@ -356,7 +359,7 @@ interface VaultKeyDependencies {
|
|
|
356
359
|
const vaultKeyDependencies: VaultKeyDependencies = {
|
|
357
360
|
source: ENVIRONMENT_SOURCE,
|
|
358
361
|
persist: persistEnv,
|
|
359
|
-
generate:
|
|
362
|
+
generate: generateVaultKey,
|
|
360
363
|
created: action,
|
|
361
364
|
}
|
|
362
365
|
|
|
@@ -381,8 +384,8 @@ export async function ensureVaultKey(dependencies: VaultKeyDependencies = vaultK
|
|
|
381
384
|
* Generate the operator-side provisioning key (the "seeded key"): a single opaque `px_` bearer, stored
|
|
382
385
|
* once. IAM Stage 1 SEEDS it (the `FABRIKA_IAM_PROVISIONING_KEY` secret — `resolveCaller` admits a
|
|
383
386
|
* bearer matching it as a synthetic admin) and fabrika Stage 2 USES it to authenticate schema reconciles.
|
|
384
|
-
*
|
|
385
|
-
* pre-set `FABRIKA_IAM_PROVISIONING_KEY` in env and init reuses it.
|
|
387
|
+
* The same `px_` key a Zerops installation generates (`randomPxKey`, 256 bits). An operator who already has
|
|
388
|
+
* one can pre-set `FABRIKA_IAM_PROVISIONING_KEY` in env and init reuses it.
|
|
386
389
|
*/
|
|
387
390
|
async function ensureProvisioningKey(): Promise<string> {
|
|
388
391
|
step('Provisioning key (FABRIKA_IAM_PROVISIONING_KEY)')
|
|
@@ -392,7 +395,7 @@ async function ensureProvisioningKey(): Promise<string> {
|
|
|
392
395
|
ok('Reusing the provisioning key from the installer env file (resume).')
|
|
393
396
|
return existing
|
|
394
397
|
}
|
|
395
|
-
const key =
|
|
398
|
+
const key = randomPxKey()
|
|
396
399
|
await persistEnv('FABRIKA_IAM_PROVISIONING_KEY', key)
|
|
397
400
|
ok('Provisioning key generated + saved to the installer env file.')
|
|
398
401
|
detail('IAM Stage 1 seeds this as an admin credential; the control plane reconciles with it in Stage 2.')
|
|
@@ -407,7 +410,7 @@ async function ensureOperationsSyncKey(): Promise<string> {
|
|
|
407
410
|
ok('Reusing OPERATIONS_SYNC_KEY from the installer env file (resume).')
|
|
408
411
|
return existing
|
|
409
412
|
}
|
|
410
|
-
const key =
|
|
413
|
+
const key = randomSecret()
|
|
411
414
|
await persistEnv('OPERATIONS_SYNC_KEY', key)
|
|
412
415
|
ok('Operations catalog key generated + saved to the installer env file.')
|
|
413
416
|
return key
|
|
@@ -426,23 +429,13 @@ export async function ensureRunnerKey(): Promise<string> {
|
|
|
426
429
|
ok('Reusing FABRIKA_RUNNER_KEY from the installer env file (resume).')
|
|
427
430
|
return existing
|
|
428
431
|
}
|
|
429
|
-
const key =
|
|
432
|
+
const key = randomSecret()
|
|
430
433
|
await persistEnv('FABRIKA_RUNNER_KEY', key)
|
|
431
434
|
ok('Runner key generated + saved to the installer env file.')
|
|
432
435
|
detail('The pipeline pushes it to the control plane and the deploy runner as a Worker secret.')
|
|
433
436
|
return key
|
|
434
437
|
}
|
|
435
438
|
|
|
436
|
-
/** One ES256 (EC P-256) private JWK with an RFC 7638 thumbprint `kid`, shaped exactly as IAM's
|
|
437
|
-
* `Signer.fromPrivateJwks` loads it (index 0 = the active signer). */
|
|
438
|
-
function generateEs256Jwk(): JsonWebKey & { kid: string } {
|
|
439
|
-
const { privateKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' })
|
|
440
|
-
const jwk = privateKey.export({ format: 'jwk' })
|
|
441
|
-
// RFC 7638 thumbprint over the canonical EC members, lexicographic order (crv, kty, x, y).
|
|
442
|
-
const thumbprint = createHash('sha256').update(JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y })).digest('base64url')
|
|
443
|
-
return { ...jwk, kid: thumbprint, alg: 'ES256', use: 'sig' }
|
|
444
|
-
}
|
|
445
|
-
|
|
446
439
|
/**
|
|
447
440
|
* Generate IAM's token-signing key (Stage 1): a JSON array with one ES256 private JWK. IAM
|
|
448
441
|
* signs every token it issues with index 0 and publishes the public half in its JWKS. Stored once
|
|
@@ -457,7 +450,7 @@ async function ensureSigningKeys(): Promise<string> {
|
|
|
457
450
|
ok('Reusing FABRIKA_IAM_SIGNING_KEYS from the installer env file (resume).')
|
|
458
451
|
return existing
|
|
459
452
|
}
|
|
460
|
-
const keys =
|
|
453
|
+
const keys = generateSigningKeys()
|
|
461
454
|
await persistEnv('FABRIKA_IAM_SIGNING_KEYS', keys)
|
|
462
455
|
ok('IAM signing key generated (1 × ES256) + saved to the installer env file.')
|
|
463
456
|
return keys
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { builtinEmailProviders } from '@fabrika/email/providers'
|
|
1
|
+
import { builtinEmailProviders, builtinEmailProviderVariables } from '@fabrika/email/providers'
|
|
2
2
|
import { IAM_APP_ID, IAM_APP_SCHEMA } from '@fabrika/iam-contract'
|
|
3
3
|
import type { InstallationCli, InstallationCommand } from '@fabrika/provider-contract/installation'
|
|
4
4
|
import { resolve } from 'node:path'
|
|
@@ -9,9 +9,7 @@ import { defaultReconcileSchema } from '../schema'
|
|
|
9
9
|
import { initCommand } from './init'
|
|
10
10
|
|
|
11
11
|
const EMAIL_PROVIDERS = Object.keys(builtinEmailProviders).join(', ')
|
|
12
|
-
const EMAIL_PROVIDER_VARIABLES =
|
|
13
|
-
.flatMap((provider) => provider.variables.map((variable) => variable.name))
|
|
14
|
-
.join(', ')
|
|
12
|
+
const EMAIL_PROVIDER_VARIABLES = builtinEmailProviderVariables.map((variable) => variable.name).join(', ')
|
|
15
13
|
|
|
16
14
|
const USAGE = `Cloudflare installation
|
|
17
15
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* base); `platform.yml` / `README.md` / `.gitignore` are CLI-owned and refreshed every run.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { builtinEmailProviders, builtinEmailProviderVariables } from '@fabrika/email/providers'
|
|
10
11
|
import {
|
|
11
12
|
INITIAL_SCAFFOLD_COMMIT_MESSAGE,
|
|
12
13
|
type ProtectionOutcome,
|
|
@@ -43,10 +44,36 @@ export interface ScaffoldResult {
|
|
|
43
44
|
branchProtection?: ProtectionOutcome
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Render a template: replace every `{{ACCOUNT}}` token, and the mail placeholders with the built-in providers, so a
|
|
49
|
+
* provider added to the registry reaches the workflow and the README without a template edit.
|
|
50
|
+
*/
|
|
47
51
|
async function renderTemplate(name: string, account: string): Promise<string> {
|
|
48
52
|
const raw = await Bun.file(resolve(TEMPLATES, name)).text()
|
|
49
|
-
return raw
|
|
53
|
+
return raw
|
|
54
|
+
.replaceAll('{{ACCOUNT}}', () => account)
|
|
55
|
+
.replaceAll('{{EMAIL_PROVIDER_NAMES}}', () => Object.keys(builtinEmailProviders).join('|'))
|
|
56
|
+
.replaceAll(/^\{\{EMAIL_PROVIDER_VARIABLES\}\}$/gm, () => emailProviderVariablesList())
|
|
57
|
+
.replaceAll(/^( *)# \{\{EMAIL_PROVIDER_ENV\}\}$/gm, (_line, indent: string) => emailProviderEnv(indent))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Each provider's variables, a credential from the Environment's secrets and the rest from its variables. */
|
|
61
|
+
function emailProviderEnv(indent: string): string {
|
|
62
|
+
return builtinEmailProviderVariables
|
|
63
|
+
.map((variable) => `${indent}${variable.name}: \${{ ${variable.secret ? 'secrets' : 'vars'}.${variable.name} }}`)
|
|
64
|
+
.join('\n')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The README's list: one line per provider, naming its variables and how each is stored. */
|
|
68
|
+
function emailProviderVariablesList(): string {
|
|
69
|
+
return Object.entries(builtinEmailProviders)
|
|
70
|
+
.map(([name, provider]) => {
|
|
71
|
+
const variables = provider.variables.map((variable) =>
|
|
72
|
+
`\`${variable.name}\` (${variable.secret ? 'secret' : 'variable'}${variable.required ? '' : ', optional'})`
|
|
73
|
+
)
|
|
74
|
+
return `- \`${name}\`: ${variables.join(', ')}`
|
|
75
|
+
})
|
|
76
|
+
.join('\n')
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
/** Write the file at `rel` under `dir` with `content`, creating parent dirs as needed. */
|
|
@@ -42,7 +42,7 @@ Run init with the Cloudflare API token in `CLOUDFLARE_API_TOKEN`:
|
|
|
42
42
|
```sh
|
|
43
43
|
fabrika platform init --provider=cloudflare {{ACCOUNT}} \
|
|
44
44
|
--console-host=<host> --operations-host=<host> --iam-host=<host> \
|
|
45
|
-
--auth-methods=<oidc|password|oidc,password> --email-provider=<none|
|
|
45
|
+
--auth-methods=<oidc|password|oidc,password> --email-provider=<none|{{EMAIL_PROVIDER_NAMES}}>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
`fabrika platform init --provider=cloudflare --help` lists the optional flags. It creates this repo,
|
|
@@ -59,15 +59,21 @@ To close the escape hatch once IAM grants you admin, set the `{{ACCOUNT}}` Envir
|
|
|
59
59
|
IAM authentication methods are independent Environment switches: `FABRIKA_IAM_OIDC_ENABLED` and
|
|
60
60
|
`FABRIKA_IAM_PASSWORD_ENABLED`. At least one must be `true`. Password enrollment is managed through
|
|
61
61
|
IAM provisioning and its admin surface. Email delivery is optional; `FABRIKA_EMAIL_PROVIDER=none`
|
|
62
|
-
keeps password enrollment and reset admin-driven. A provider
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
keeps password enrollment and reset admin-driven. A provider also needs the sender variable
|
|
63
|
+
`FABRIKA_EMAIL_FROM` (optionally `FABRIKA_EMAIL_FROM_NAME`) and its own Environment secrets and variables:
|
|
64
|
+
|
|
65
|
+
{{EMAIL_PROVIDER_VARIABLES}}
|
|
66
|
+
|
|
67
|
+
The workflow hands the same set to IAM and to the control plane. The control plane hands it to every application
|
|
68
|
+
whose job declares `mailer: 'installation'`, at that application's deploy.
|
|
69
|
+
|
|
70
|
+
To change or rotate them, re-run `fabrika platform init` with the new values; it rewrites this Environment
|
|
71
|
+
and triggers the workflow, which redeploys IAM and the control plane. An application gets the new set at its next
|
|
72
|
+
deploy: redeploy each environment that sends installation mail with
|
|
73
|
+
`fabrika control deploy --app=<id> --env=<name>`, or **Deploy** in the console.
|
|
74
|
+
|
|
75
|
+
Switching provider leaves the old provider's values stored: init writes the new ones and deletes none. IAM and
|
|
76
|
+
the control plane read only the selected provider's variables, but delete the old credentials so nothing holds them, for
|
|
71
77
|
example after leaving SmartEmailing:
|
|
72
78
|
|
|
73
79
|
```sh
|
|
@@ -78,6 +84,16 @@ gh variable delete FABRIKA_EMAIL_SMARTEMAILING_TAG --env {{ACCOUNT}}
|
|
|
78
84
|
|
|
79
85
|
Remove the same names from the installer env file (init prints its path when it starts), or a later run of
|
|
80
86
|
init resumes them.
|
|
87
|
+
IAM's and the control plane's Workers also keep the old provider's credentials as Worker secrets, which neither reads.
|
|
88
|
+
Delete each of them from both Workers, with the account's id in `CLOUDFLARE_ACCOUNT_ID` and its API token in
|
|
89
|
+
`CLOUDFLARE_API_TOKEN`:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
for worker in prod-propustka-worker prod-vozka; do
|
|
93
|
+
bunx wrangler secret delete FABRIKA_EMAIL_SMARTEMAILING_USERNAME --name "$worker"
|
|
94
|
+
bunx wrangler secret delete FABRIKA_EMAIL_SMARTEMAILING_API_KEY --name "$worker"
|
|
95
|
+
done
|
|
96
|
+
```
|
|
81
97
|
|
|
82
98
|
## Routine redeploy or version bump
|
|
83
99
|
|
|
@@ -88,4 +104,6 @@ Both paths rebuild the account-owned runner image from the exact checkout select
|
|
|
88
104
|
|
|
89
105
|
`fabrika.ref` is operator-owned. `fabrika platform init` creates it once and does not overwrite later version pins.
|
|
90
106
|
A bump does not rewrite this workflow. Re-run `fabrika platform init --provider=cloudflare {{ACCOUNT}}` with the same
|
|
91
|
-
flags to bring `.github/workflows/platform.yml` to the one
|
|
107
|
+
flags, with the CLI of the release `fabrika.ref` names, to bring `.github/workflows/platform.yml` to the one that release
|
|
108
|
+
generates. A change in what the workflow hands a stage (such as the mail transport the control plane holds) reaches
|
|
109
|
+
the account only this way.
|
|
@@ -140,17 +140,15 @@ jobs:
|
|
|
140
140
|
FABRIKA_IAM_OIDC_CLIENT_ID: ${{ vars.FABRIKA_IAM_OIDC_CLIENT_ID }}
|
|
141
141
|
FABRIKA_IAM_OIDC_SCOPES: ${{ vars.FABRIKA_IAM_OIDC_SCOPES }}
|
|
142
142
|
FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL: ${{ vars.FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL }}
|
|
143
|
-
# Every built-in mail provider's variables: IAM reads only the selected provider's, and an unset one is ''.
|
|
144
143
|
FABRIKA_EMAIL_PROVIDER: ${{ vars.FABRIKA_EMAIL_PROVIDER }}
|
|
145
144
|
FABRIKA_EMAIL_FROM: ${{ vars.FABRIKA_EMAIL_FROM }}
|
|
146
145
|
FABRIKA_EMAIL_FROM_NAME: ${{ vars.FABRIKA_EMAIL_FROM_NAME }}
|
|
147
|
-
FABRIKA_EMAIL_SMARTEMAILING_TAG: ${{ vars.FABRIKA_EMAIL_SMARTEMAILING_TAG }}
|
|
148
146
|
FABRIKA_IAM_SIGNING_KEYS: ${{ secrets.FABRIKA_IAM_SIGNING_KEYS }}
|
|
149
147
|
OIDC_CLIENT_SECRET: ${{ secrets.FABRIKA_IAM_OIDC_CLIENT_SECRET }}
|
|
150
|
-
FABRIKA_EMAIL_RESEND_API_KEY: ${{ secrets.FABRIKA_EMAIL_RESEND_API_KEY }}
|
|
151
|
-
FABRIKA_EMAIL_SMARTEMAILING_USERNAME: ${{ secrets.FABRIKA_EMAIL_SMARTEMAILING_USERNAME }}
|
|
152
|
-
FABRIKA_EMAIL_SMARTEMAILING_API_KEY: ${{ secrets.FABRIKA_EMAIL_SMARTEMAILING_API_KEY }}
|
|
153
148
|
FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
|
|
149
|
+
# Every built-in mail provider's variables, written by init from the provider registry: IAM reads only the
|
|
150
|
+
# selected provider's, and an unset one is ''.
|
|
151
|
+
# {{EMAIL_PROVIDER_ENV}}
|
|
154
152
|
# `platform deploy`, not `app deploy`: IAM's own Worker is a PLATFORM resource name, and only the
|
|
155
153
|
# platform verb may name one. The single-component form deploys just this config.
|
|
156
154
|
run: fabrika platform deploy --provider=cloudflare --env=prod --component-config=fabrika.config.ts
|
|
@@ -190,6 +188,12 @@ jobs:
|
|
|
190
188
|
FABRIKA_IAM_ISSUER: ${{ vars.FABRIKA_IAM_ISSUER }}
|
|
191
189
|
OPERATIONS_ARTIFACT_ORIGIN: https://${{ vars.OPERATIONS_HOSTNAME }}
|
|
192
190
|
FABRIKA_CONTROL_BOOTSTRAP_ADMINS: ${{ vars.FABRIKA_CONTROL_BOOTSTRAP_ADMINS }}
|
|
191
|
+
# The installation's mail transport, the same set as IAM's: the control plane hands it to every application
|
|
192
|
+
# whose job declares `mailer: 'installation'`. Its credentials become Worker secrets of the control plane only.
|
|
193
|
+
FABRIKA_EMAIL_PROVIDER: ${{ vars.FABRIKA_EMAIL_PROVIDER }}
|
|
194
|
+
FABRIKA_EMAIL_FROM: ${{ vars.FABRIKA_EMAIL_FROM }}
|
|
195
|
+
FABRIKA_EMAIL_FROM_NAME: ${{ vars.FABRIKA_EMAIL_FROM_NAME }}
|
|
196
|
+
# {{EMAIL_PROVIDER_ENV}}
|
|
193
197
|
run: |
|
|
194
198
|
fabrika platform deploy --provider=cloudflare \
|
|
195
199
|
--runner-config=packages/runner-cloudflare/fabrika-runner.config.ts \
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isFrameworkVariableName } from '@fabrika/auth-core'
|
|
2
|
+
import type { ProviderManagedEnvironment } from '@fabrika/provider-contract'
|
|
3
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export interface ManagedSplit {
|
|
9
|
+
readonly vars: Readonly<Record<string, string>>
|
|
10
|
+
readonly secrets: Readonly<Record<string, string>>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The values a deploy writes: a credential as a Worker secret, any other as a plain var; a null value is not written. */
|
|
14
|
+
export const splitManagedEnvironment = (managed: ProviderManagedEnvironment): ManagedSplit => {
|
|
15
|
+
const vars: Record<string, string> = {}
|
|
16
|
+
const secrets: Record<string, string> = {}
|
|
17
|
+
for (const [name, { value, credential }] of Object.entries(managed)) {
|
|
18
|
+
if (value === null) continue
|
|
19
|
+
if (credential) secrets[name] = value
|
|
20
|
+
else vars[name] = value
|
|
21
|
+
}
|
|
22
|
+
return { vars, secrets }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Run `body` with the secrets in a JSON file only its owner reads, in a directory of its own, removed however `body`
|
|
27
|
+
* ends. `body` gets null when there is nothing to write.
|
|
28
|
+
*/
|
|
29
|
+
export const withSecretsFile = async <T>(secrets: Readonly<Record<string, string>>, body: (path: string | null) => Promise<T>): Promise<T> => {
|
|
30
|
+
if (Object.keys(secrets).length === 0) return body(null)
|
|
31
|
+
const dir = await mkdtemp(join(tmpdir(), 'fabrika-secrets-'))
|
|
32
|
+
try {
|
|
33
|
+
const path = join(dir, 'secrets.json')
|
|
34
|
+
await writeFile(path, JSON.stringify(secrets), { mode: 0o600, flag: 'wx' })
|
|
35
|
+
return await body(path)
|
|
36
|
+
} finally {
|
|
37
|
+
await rm(dir, { recursive: true, force: true })
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const secretListSchema = z.array(z.object({ name: z.string() }))
|
|
42
|
+
|
|
43
|
+
/** The names `wrangler secret list --format json` printed. */
|
|
44
|
+
export const parseSecretNames = (stdout: string): readonly string[] => {
|
|
45
|
+
let decoded: unknown
|
|
46
|
+
try {
|
|
47
|
+
decoded = JSON.parse(stdout)
|
|
48
|
+
} catch {
|
|
49
|
+
decoded = undefined
|
|
50
|
+
}
|
|
51
|
+
const list = secretListSchema.safeParse(decoded)
|
|
52
|
+
if (!list.success) throw new Error('wrangler secret list printed no readable list of secrets')
|
|
53
|
+
return list.data.map((secret) => secret.name)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The framework secrets a Worker still holds that this deploy no longer writes. Wider than `staleManagedVariables`: the
|
|
58
|
+
* executor writes no framework secret of its own, so any other one is stale.
|
|
59
|
+
*/
|
|
60
|
+
export const staleManagedSecrets = (present: readonly string[], written: Readonly<Record<string, string>>): readonly string[] =>
|
|
61
|
+
present.filter((name) => isFrameworkVariableName(name) && !Object.hasOwn(written, name))
|
package/src/plan.ts
CHANGED
|
@@ -57,6 +57,8 @@ export const PLATFORM_RESOURCE_NAMES: ReadonlySet<string> = new Set([
|
|
|
57
57
|
'vozka-runner',
|
|
58
58
|
'vozka-deploy',
|
|
59
59
|
'vozka-deploy-runner',
|
|
60
|
+
'fabrika-mail',
|
|
61
|
+
'fabrika-mail-content',
|
|
60
62
|
'vozka-run-logs',
|
|
61
63
|
'propustka',
|
|
62
64
|
'propustka-worker',
|
|
@@ -68,11 +70,19 @@ export const PLATFORM_RESOURCE_NAMES: ReadonlySet<string> = new Set([
|
|
|
68
70
|
'operations-ingest-dlq',
|
|
69
71
|
])
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
const ENTRY_BUILD = '`fabrika app build --provider=cloudflare`'
|
|
74
|
+
|
|
75
|
+
/** `regeneratesEntry`: the release pins the generated entry, so the build step always runs, after `pipeline.build`. */
|
|
76
|
+
export const buildPlan = (config: CloudflareAppConfig, worker: Worker, regeneratesEntry: boolean): readonly CloudflareStep[] => {
|
|
72
77
|
const steps: CloudflareStep[] = []
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
const build = config.pipeline?.build
|
|
80
|
+
if (build !== undefined && regeneratesEntry) {
|
|
81
|
+
steps.push({ id: 'build', kind: 'build', description: `Build the Worker (\`${build}\`), then regenerate its entry (${ENTRY_BUILD})` })
|
|
82
|
+
} else if (build !== undefined) {
|
|
83
|
+
steps.push({ id: 'build', kind: 'build', description: `Build the Worker (\`${build}\`)` })
|
|
84
|
+
} else if (regeneratesEntry) {
|
|
85
|
+
steps.push({ id: 'build', kind: 'build', description: `Regenerate the Worker's entry (${ENTRY_BUILD})` })
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
steps.push({ id: 'provision-resources', kind: 'provision-resources', description: 'Provision Cloudflare resources via oblaka' })
|