Skip to content

Commit

Permalink
flags: add deprecation warnings to old memstore flag env-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Oct 5, 2024
1 parent d67e5fd commit 4da472e
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions store/generated_key/memstore/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package memstore

import (
"fmt"
"os"
"time"

"github.com/Layr-Labs/eigenda-proxy/verify"
Expand All @@ -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 {

Check failure on line 31 in store/generated_key/memstore/cli.go

View workflow job for this annotation

GitHub Actions / Linter

unused-parameter: parameter 'envPrefix' seems to be unused, consider removing or renaming it as _ (revive)
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,
Expand Down

0 comments on commit 4da472e

Please sign in to comment.