@fabrika/cli 0.5.0 → 0.5.1
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 +12 -12
- package/src/control.ts +94 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,19 +30,19 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"zod": "^3.25.76",
|
|
33
|
-
"@fabrika/app": "0.5.
|
|
34
|
-
"@fabrika/auth-core": "0.5.
|
|
35
|
-
"@fabrika/control-contract": "0.5.
|
|
36
|
-
"@fabrika/provider-contract": "0.5.
|
|
37
|
-
"@fabrika/db": "0.5.
|
|
38
|
-
"@fabrika/platform": "0.5.
|
|
39
|
-
"@fabrika/platform-node": "0.5.
|
|
40
|
-
"@fabrika/check": "0.5.
|
|
33
|
+
"@fabrika/app": "0.5.1",
|
|
34
|
+
"@fabrika/auth-core": "0.5.1",
|
|
35
|
+
"@fabrika/control-contract": "0.5.1",
|
|
36
|
+
"@fabrika/provider-contract": "0.5.1",
|
|
37
|
+
"@fabrika/db": "0.5.1",
|
|
38
|
+
"@fabrika/platform": "0.5.1",
|
|
39
|
+
"@fabrika/platform-node": "0.5.1",
|
|
40
|
+
"@fabrika/check": "0.5.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@fabrika/builder": "0.5.
|
|
44
|
-
"@fabrika/provider-cloudflare": "0.5.
|
|
45
|
-
"@fabrika/provider-zerops": "0.5.
|
|
43
|
+
"@fabrika/builder": "0.5.1",
|
|
44
|
+
"@fabrika/provider-cloudflare": "0.5.1",
|
|
45
|
+
"@fabrika/provider-zerops": "0.5.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@fabrika/builder": {
|
package/src/control.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { createRpcClient, type InferRpcClient, RpcError } from '@fabrika/app'
|
|
|
13
13
|
import { type IssueKeyInput, type IssueKeyResult, MAX_KEY_LIFETIME_SECONDS } from '@fabrika/auth-core'
|
|
14
14
|
import type {
|
|
15
15
|
AppDto,
|
|
16
|
+
AppSecretDto,
|
|
16
17
|
ControlRpcContract,
|
|
17
18
|
DeploymentNamespaceDetailDto,
|
|
18
19
|
DeploymentNamespaceDto,
|
|
@@ -20,6 +21,7 @@ import type {
|
|
|
20
21
|
PlanDeploymentNamespaceRequest,
|
|
21
22
|
PlanDeploymentNamespaceResponse,
|
|
22
23
|
PutAppEnvRequest,
|
|
24
|
+
PutAppSecretRequest,
|
|
23
25
|
PutAppVarRequest,
|
|
24
26
|
RegisterAppRequest,
|
|
25
27
|
RegisterAppResponse,
|
|
@@ -56,6 +58,9 @@ Usage:
|
|
|
56
58
|
fabrika control apps variables list --app=<id>
|
|
57
59
|
fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]
|
|
58
60
|
fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]
|
|
61
|
+
fabrika control apps secrets list --app=<id>
|
|
62
|
+
fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)
|
|
63
|
+
fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]
|
|
59
64
|
fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>
|
|
60
65
|
[--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]
|
|
61
66
|
[--namespace=<id>] [--installation-id=<n|none>]
|
|
@@ -81,6 +86,13 @@ refused before anything is created. \`namespaces get\` lists the hosts a \`zerop
|
|
|
81
86
|
serves and which of them are still free; a custom-domain namespace serves the domain you bound to its
|
|
82
87
|
proxy. A manifest with no proxy target needs no domain.
|
|
83
88
|
|
|
89
|
+
A variable's value is stored and printed in clear. A secret's value is write-only: \`apps secrets put\`
|
|
90
|
+
reads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and
|
|
91
|
+
one trailing newline is dropped. No command prints it back; \`apps secrets list\` shows names, scope and
|
|
92
|
+
storage only. Generate one in the pipe:
|
|
93
|
+
|
|
94
|
+
openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>
|
|
95
|
+
|
|
84
96
|
\`--public-origin\` is where IAM may return a signed-in person: without one, sign-in to the environment is
|
|
85
97
|
refused. When \`register\` is given none and the namespace lists \`--domain\` among its hosts, it sets
|
|
86
98
|
\`https://<domain>\` and says so on stderr. A custom domain needs the flag.
|
|
@@ -450,10 +462,10 @@ export type ManifestTextCompiler = (environment: string) => Promise<CompiledMani
|
|
|
450
462
|
|
|
451
463
|
const IN_MEMORY_MANIFEST = 'the compiled manifest'
|
|
452
464
|
|
|
453
|
-
/** The
|
|
454
|
-
const failureMessage = (error: unknown,
|
|
465
|
+
/** The message of a failure that ran with `value` in reach, with `value` cut out and named by `label`. */
|
|
466
|
+
const failureMessage = (error: unknown, value: string, label: string): string => {
|
|
455
467
|
const message = error instanceof RpcError ? `${error.type}: ${error.message}` : error instanceof Error ? error.message : String(error)
|
|
456
|
-
return message.replaceAll(
|
|
468
|
+
return message.replaceAll(value, `[${label}]`)
|
|
457
469
|
}
|
|
458
470
|
|
|
459
471
|
/**
|
|
@@ -483,13 +495,15 @@ export const registerCompiledManifest = async (
|
|
|
483
495
|
const manifest = parseJsonText(compiled.text, IN_MEMORY_MANIFEST)
|
|
484
496
|
body = registrationRequest(inputs, compiled.provider, manifest, IN_MEMORY_MANIFEST)
|
|
485
497
|
} catch (error) {
|
|
486
|
-
throw new Error(`Compile phase failed; nothing was registered. ${failureMessage(error, controlKey)}`)
|
|
498
|
+
throw new Error(`Compile phase failed; nothing was registered. ${failureMessage(error, controlKey, 'FABRIKA_CONTROL_KEY')}`)
|
|
487
499
|
}
|
|
488
500
|
let result: RegisterAppResponse
|
|
489
501
|
try {
|
|
490
502
|
result = await client.register(await withNamespacePublicOrigin(body, client))
|
|
491
503
|
} catch (error) {
|
|
492
|
-
throw new Error(
|
|
504
|
+
throw new Error(
|
|
505
|
+
`Register phase failed after a successful compile; no manifest file was written. ${failureMessage(error, controlKey, 'FABRIKA_CONTROL_KEY')}`,
|
|
506
|
+
)
|
|
493
507
|
}
|
|
494
508
|
emit(flags, result, () => registrationLine(result))
|
|
495
509
|
}
|
|
@@ -573,12 +587,85 @@ const runVariables = async (verb: string | undefined, flags: Flags, env: Readonl
|
|
|
573
587
|
throw new Error(`Unknown \`control apps variables\` verb: ${verb ?? '(missing)'}`)
|
|
574
588
|
}
|
|
575
589
|
|
|
590
|
+
/** Where `apps secrets put` reads a secret's value. The CLI reads the process's stdin; a test hands its own. */
|
|
591
|
+
export interface SecretValueInput {
|
|
592
|
+
readonly isTerminal: () => boolean
|
|
593
|
+
readonly text: () => Promise<string>
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const processStdin: SecretValueInput = {
|
|
597
|
+
isTerminal: () => process.stdin.isTTY === true,
|
|
598
|
+
text: () => Bun.stdin.text(),
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** The value piped in, without the one newline `echo` or a heredoc ends it with. */
|
|
602
|
+
const readSecretValue = async (input: SecretValueInput, appId: string, name: string): Promise<string> => {
|
|
603
|
+
if (input.isTerminal()) {
|
|
604
|
+
throw new Error(
|
|
605
|
+
'`apps secrets put` reads the value from stdin, and stdin is a terminal. Pipe the value in, for example: '
|
|
606
|
+
+ `openssl rand -base64 32 | fabrika control apps secrets put --app=${appId} --name=${name}`,
|
|
607
|
+
)
|
|
608
|
+
}
|
|
609
|
+
const value = (await input.text()).replace(/\r?\n$/, '')
|
|
610
|
+
if (value === '') {
|
|
611
|
+
throw new Error('`apps secrets put` read an empty value from stdin; nothing was stored')
|
|
612
|
+
}
|
|
613
|
+
return value
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* A secret's value is write-only: it comes in on stdin, never as a flag a shell history or a process listing
|
|
618
|
+
* keeps, and no verb prints it. Control seals it and keeps only a reference.
|
|
619
|
+
*/
|
|
620
|
+
const runSecrets = async (
|
|
621
|
+
verb: string | undefined,
|
|
622
|
+
flags: Flags,
|
|
623
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
624
|
+
input: SecretValueInput,
|
|
625
|
+
): Promise<void> => {
|
|
626
|
+
const client = controlClient(flags, env)
|
|
627
|
+
const appId = required(flags, 'app')
|
|
628
|
+
const scope = optional(flags, 'env')
|
|
629
|
+
if (verb === 'list') {
|
|
630
|
+
const result = await client.apps.secrets.list({ appId })
|
|
631
|
+
emitList(flags, result, (item) => `${item.env ?? '*'}\t${item.name}\t${item.storage}`, `app ${appId} has no secrets`)
|
|
632
|
+
return
|
|
633
|
+
}
|
|
634
|
+
if (verb === 'put') {
|
|
635
|
+
if (flags.values.has('value')) {
|
|
636
|
+
throw new Error('`apps secrets put` takes no --value: pipe the value in on stdin, so it stays out of shell history and process listings')
|
|
637
|
+
}
|
|
638
|
+
const name = required(flags, 'name')
|
|
639
|
+
const value = await readSecretValue(input, appId, name)
|
|
640
|
+
const secret: PutAppSecretRequest = { name, value, ...(scope === undefined ? {} : { env: scope }) }
|
|
641
|
+
let result: AppSecretDto
|
|
642
|
+
try {
|
|
643
|
+
result = await client.apps.secrets.put({ appId, secret })
|
|
644
|
+
} catch (error) {
|
|
645
|
+
throw new Error(failureMessage(error, value, 'secret value'))
|
|
646
|
+
}
|
|
647
|
+
emit(flags, result, () => `${result.env ?? '*'}\t${result.name}\tok`)
|
|
648
|
+
return
|
|
649
|
+
}
|
|
650
|
+
if (verb === 'delete') {
|
|
651
|
+
const result = await client.apps.secrets.delete({ appId, name: required(flags, 'name'), ...(scope === undefined ? {} : { env: scope }) })
|
|
652
|
+
emit(flags, result, () => (result.ok ? 'deleted' : 'not deleted'))
|
|
653
|
+
return
|
|
654
|
+
}
|
|
655
|
+
throw new Error(`Unknown \`control apps secrets\` verb: ${verb ?? '(missing)'}`)
|
|
656
|
+
}
|
|
657
|
+
|
|
576
658
|
const runApps = async (
|
|
577
659
|
verb: string | undefined,
|
|
578
660
|
flags: Flags,
|
|
579
661
|
provider: string | undefined,
|
|
580
662
|
env: Readonly<Record<string, string | undefined>>,
|
|
663
|
+
input: SecretValueInput,
|
|
581
664
|
): Promise<void> => {
|
|
665
|
+
if (verb === 'secrets') {
|
|
666
|
+
await runSecrets(flags.positional[1], flags, env, input)
|
|
667
|
+
return
|
|
668
|
+
}
|
|
582
669
|
if (verb === 'variables') {
|
|
583
670
|
await runVariables(flags.positional[1], flags, env)
|
|
584
671
|
return
|
|
@@ -791,6 +878,7 @@ export const runControlCli = async (
|
|
|
791
878
|
argv: readonly string[],
|
|
792
879
|
provider?: string,
|
|
793
880
|
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
881
|
+
input: SecretValueInput = processStdin,
|
|
794
882
|
): Promise<void> => {
|
|
795
883
|
const flags = parseControlFlags(argv)
|
|
796
884
|
const verb = flags.positional[0]
|
|
@@ -804,7 +892,7 @@ export const runControlCli = async (
|
|
|
804
892
|
await runKeyIssue(flags, env)
|
|
805
893
|
return
|
|
806
894
|
case 'apps':
|
|
807
|
-
await runApps(verb, flags, provider, env)
|
|
895
|
+
await runApps(verb, flags, provider, env, input)
|
|
808
896
|
return
|
|
809
897
|
case 'runs':
|
|
810
898
|
await runRuns(verb, flags, env)
|