From 4da472e5fe8c6b1b847cd8dd1eb7853768239144 Mon Sep 17 00:00:00 2001 From: Samuel Laferriere Date: Sat, 5 Oct 2024 21:21:48 +0100 Subject: [PATCH] flags: add deprecation warnings to old memstore flag env-vars --- store/generated_key/memstore/cli.go | 38 +++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/store/generated_key/memstore/cli.go b/store/generated_key/memstore/cli.go index 250482e..e65e115 100644 --- a/store/generated_key/memstore/cli.go +++ b/store/generated_key/memstore/cli.go @@ -1,6 +1,8 @@ package memstore import ( + "fmt" + "os" "time" "github.com/Layr-Labs/eigenda-proxy/verify" @@ -19,25 +21,51 @@ func withFlagPrefix(s string) string { } func withEnvPrefix(envPrefix, s string) []string { - return []string{envPrefix + "_MEMSTORE_" + s} + return []string{ + envPrefix + "_MEMSTORE_" + s, + } +} + +// if these deprecated env vars are used, we force the user to update their config +// in the flags' actions +func withDeprecatedEnvPrefix(envPrefix, s string) string { + return "MEMSTORE_" + s } -// CLIFlags ... used for Redis backend configuration +// CLIFlags ... used for memstore backend configuration // category is used to group the flags in the help output (see https://cli.urfave.org/v2/examples/flags/#grouping) func CLIFlags(envPrefix, category string) []cli.Flag { return []cli.Flag{ &cli.BoolFlag{ Name: EnabledFlagName, - Usage: "Whether to use mem-store for DA logic.", - EnvVars: withEnvPrefix(envPrefix, "ENABLED"), + Usage: "Whether to use memstore for DA logic.", + EnvVars: append(withEnvPrefix(envPrefix, "ENABLED"), withDeprecatedEnvPrefix(envPrefix, "ENABLED")), Category: category, + Action: func(_ *cli.Context, _ bool) error { + if _, ok := os.LookupEnv(withDeprecatedEnvPrefix(envPrefix, "ENABLED")); ok { + return fmt.Errorf("env var %s is deprecated for flag %s, use %s instead", + withDeprecatedEnvPrefix(envPrefix, "ENABLED"), + EnabledFlagName, + withEnvPrefix(envPrefix, "ENABLED")[0]) + } + return nil + }, }, &cli.DurationFlag{ Name: ExpirationFlagName, Usage: "Duration that a memstore blob/commitment pair is allowed to live.", Value: 25 * time.Minute, - EnvVars: withEnvPrefix(envPrefix, "EXPIRATION"), + EnvVars: append(withEnvPrefix(envPrefix, "EXPIRATION"), withDeprecatedEnvPrefix(envPrefix, "EXPIRATION")), Category: category, + Action: func(_ *cli.Context, _ time.Duration) error { + if _, ok := os.LookupEnv(withDeprecatedEnvPrefix(envPrefix, "EXPIRATION")); ok { + return fmt.Errorf("env var %s is deprecated for flag %s, use %s instead", + withDeprecatedEnvPrefix(envPrefix, "EXPIRATION"), + ExpirationFlagName, + withEnvPrefix(envPrefix, "EXPIRATION")[0]) + } + return nil + }, }, &cli.DurationFlag{ Name: PutLatencyFlagName,