forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigning-key.command.ts
More file actions
68 lines (63 loc) · 2.85 KB
/
Copy pathsigning-key.command.ts
File metadata and controls
68 lines (63 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Layer } from "effect";
import { Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.layer.ts";
import { stdinLayer } from "../../../../shared/runtime/stdin.layer.ts";
import { legacyCliConfigLayer } from "../../../config/legacy-cli-config.layer.ts";
import { legacyDebugLoggerLayer } from "../../../shared/legacy-debug-logger.layer.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyTelemetryStateLayer } from "../../../telemetry/legacy-telemetry-state.layer.ts";
import { legacyGenSigningKey } from "./signing-key.handler.ts";
const ALGORITHM_VALUES = ["ES256", "RS256"] as const;
const config = {
algorithm: Flag.choice("algorithm", ALGORITHM_VALUES).pipe(
Flag.withDescription("Algorithm for signing key generation."),
Flag.withDefault("ES256" as const),
),
append: Flag.boolean("append").pipe(
Flag.withDescription("Append new key to existing keys file instead of overwriting."),
),
} as const;
export type LegacyGenSigningKeyFlags = CliCommand.Command.Config.Infer<typeof config>;
const cliConfig = legacyCliConfigLayer.pipe(Layer.provide(legacyDebugLoggerLayer));
const legacyGenSigningKeyRuntimeLayer = Layer.mergeAll(
legacyDebugLoggerLayer,
cliConfig,
legacyTelemetryStateLayer,
commandRuntimeLayer(["gen", "signing-key"]),
// The overwrite-confirmation prompt reads piped stdin via `legacyPromptYesNo`
// (`stdin.readLine`), same as `config push`, `seed buckets`, `storage rm`, `db pull`,
// and `logout` — all of which merge `stdinLayer` alongside their runtime layer.
stdinLayer,
);
export const legacyGenSigningKeyCommand = Command.make("signing-key", config).pipe(
Command.withDescription(
"Securely generate a private JWT signing key for use in the CLI or to import in the dashboard.\n\n" +
"Supported algorithms:\n" +
" ES256 - ECDSA with P-256 curve and SHA-256 (recommended)\n" +
" RS256 - RSA with SHA-256",
),
Command.withShortDescription("Generate a JWT signing key"),
Command.withExamples([
{
command: "supabase gen signing-key",
description: "Generate an ES256 signing key and print it to stdout",
},
{
command: "supabase gen signing-key --algorithm RS256",
description: "Generate an RSA signing key",
},
{
command: "supabase gen signing-key --append",
description: "Append a new key to the configured signing key file",
},
]),
Command.withHandler((flags) =>
legacyGenSigningKey(flags).pipe(
withLegacyCommandInstrumentation({ flags, config }),
withJsonErrorHandling,
),
),
Command.provide(legacyGenSigningKeyRuntimeLayer),
);