forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.command.ts
More file actions
47 lines (43 loc) · 2.4 KB
/
Copy pathget.command.ts
File metadata and controls
47 lines (43 loc) · 2.4 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
import { Effect } 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 { legacyRequireExperimental } from "../../../shared/legacy-experimental-gate.ts";
import { LEGACY_RESOURCE_OUTPUT_FORMATS } from "../../../shared/legacy-go-output-flag.ts";
import { legacyManagementApiRuntimeLayer } from "../../../shared/legacy-management-api-runtime.layer.ts";
import {
legacyValidateOutputFormat,
withLegacyCommandInstrumentation,
} from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacySslEnforcementGet } from "./get.handler.ts";
const config = {
projectRef: Flag.string("project-ref").pipe(
Flag.withDescription("Project ref of the Supabase project."),
Flag.optional,
),
} as const;
export type LegacySslEnforcementGetFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacySslEnforcementGetCommand = Command.make("get", config).pipe(
Command.withDescription("Get the current SSL enforcement configuration."),
Command.withShortDescription("Get SSL enforcement configuration"),
Command.withHandler((flags) =>
Effect.gen(function* () {
// Cobra parses flags — rejecting an out-of-enum `-o` (`internal/utils/enum.go:21-27`)
// — before `PersistentPreRunE` ever runs (`cobra@v1.10.2/command.go:919,985`), so an
// invalid `-o` value must win over a missing `--experimental` flag.
yield* legacyValidateOutputFormat(LEGACY_RESOURCE_OUTPUT_FORMATS);
// Go gates `sslEnforcementCmd` behind `--experimental` in PersistentPreRunE
// (root.go:91-96) BEFORE the `IsManagementAPI` login check (root.go:105-109).
// `legacyManagementApiRuntimeLayer` eagerly resolves an access token as part
// of building its `LegacyPlatformApi` layer, so it must be provided AFTER
// the gate (inline here) rather than via `Command.provide` on the whole
// command — `Command.provide` would build the layer, and fail on a missing
// token, before this generator's first `yield*` ever runs.
yield* legacyRequireExperimental;
return yield* legacySslEnforcementGet(flags).pipe(
withLegacyCommandInstrumentation({ flags }),
Effect.provide(legacyManagementApiRuntimeLayer(["ssl-enforcement", "get"])),
);
}).pipe(withJsonErrorHandling),
),
);