Skip to content

Commit be3c522

Browse files
authored
refactor: replace * value with other more bash friendly value (#8491)
**Motivation** Using `*` as a CLI flag value is not bash-friendly **Description** Add backward-compatible support for the bash-friendly value `all` as an alternative to `*` for the following CLI flags: - `--rest.namespace` - now accepts both `*` and `all` to enable all API namespaces - `--rest.cors` - now accepts both `*` and `all` to allow all origins - `--keymanager.cors` - now accepts both `*` and `all` to allow all origins Closes #5963
1 parent c9deb9b commit be3c522

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/cli/src/cmds/validator/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {WireFormat, defaultInit} from "@lodestar/api";
22
import {CliCommandOptions} from "@lodestar/utils";
33
import {defaultOptions} from "@lodestar/validator";
4+
import {coerceCors, enabledAllBashFriendly} from "../../options/beaconNodeOptions/api.js";
45
import {LogArgs, logOptions} from "../../options/logOptions.js";
56
import {ensure0xPrefix} from "../../util/index.js";
67
import {keymanagerRestApiServerOptsDefault} from "./keymanager/server.js";
@@ -128,9 +129,10 @@ export const keymanagerOptions: CliCommandOptions<KeymanagerArgs> = {
128129
},
129130
"keymanager.cors": {
130131
type: "string",
131-
description: "Configures the Access-Control-Allow-Origin CORS header for key manager API",
132+
description: `Configures the Access-Control-Allow-Origin CORS header for key manager API. Use '${enabledAllBashFriendly}' to allow all origins`,
132133
defaultDescription: keymanagerRestApiServerOptsDefault.cors,
133134
group: "keymanager",
135+
coerce: coerceCors,
134136
},
135137
"keymanager.headerLimit": {
136138
hidden: true,

packages/cli/src/options/beaconNodeOptions/api.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import {IBeaconNodeOptions, allNamespaces, defaultOptions} from "@lodestar/beacon-node";
22
import {CliCommandOptions} from "@lodestar/utils";
33

4-
const enabledAll = "*";
4+
export const enabledAll = "*";
5+
export const enabledAllBashFriendly = "all";
6+
7+
/**
8+
* Coerce function to transform bash-friendly 'all' to CORS spec '*'
9+
*/
10+
export function coerceCors(cors: string): string {
11+
return cors === enabledAllBashFriendly ? enabledAll : cors;
12+
}
513

614
export type ApiArgs = {
715
"api.maxGindicesInProof"?: number;
@@ -51,23 +59,25 @@ export const options: CliCommandOptions<ApiArgs> = {
5159

5260
"rest.namespace": {
5361
type: "array",
54-
choices: [...allNamespaces, enabledAll],
55-
description: `Pick namespaces to expose for HTTP API. Set to '${enabledAll}' to enable all namespaces`,
62+
choices: [...allNamespaces, enabledAll, enabledAllBashFriendly],
63+
description: `Pick namespaces to expose for HTTP API. Set to '${enabledAllBashFriendly}' (or '${enabledAll}') to enable all namespaces`,
5664
defaultDescription: JSON.stringify(defaultOptions.api.rest.api),
5765
group: "api",
5866
coerce: (namespaces: string[]): string[] => {
59-
// Enable all
60-
if (namespaces.includes(enabledAll)) return allNamespaces;
67+
if (namespaces.includes(enabledAll) || namespaces.includes(enabledAllBashFriendly)) {
68+
return allNamespaces;
69+
}
6170
// Parse ["debug,lodestar"] to ["debug", "lodestar"]
6271
return namespaces.flatMap((val) => val.split(","));
6372
},
6473
},
6574

6675
"rest.cors": {
6776
type: "string",
68-
description: "Configures the Access-Control-Allow-Origin CORS header for HTTP API",
77+
description: `Configures the Access-Control-Allow-Origin CORS header for HTTP API. Use '${enabledAllBashFriendly}' to allow all origins`,
6978
defaultDescription: defaultOptions.api.rest.cors,
7079
group: "api",
80+
coerce: coerceCors,
7181
},
7282

7383
"rest.address": {

0 commit comments

Comments
 (0)