feat: each provider can have its own timeout
providers.azure.timeout, providers.databricks.timeout and providers.repos.timeout override providers.timeout for that provider's requests; --timeout still sets them all. lazysecrets share, which reads a key and repo files, waits the longest of them.
This commit is contained in:
11 files changed
+106
-29
No files matched your search
+28
-5
@@ -3,6 +3,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -106,7 +107,7 @@ func run() error {
|
||||
showVersion := flag.Bool("version", false, "print the version and exit")
|
||||
dir := flag.String("dir", "", "start in this directory: its git repo's SOPS files, the ones under it first (default: the current directory)")
|
||||
demo := flag.Bool("demo", false, "browse built-in sample data instead of real backends")
|
||||
timeout := flag.Duration("timeout", 30*time.Second, "timeout for each backend request")
|
||||
timeout := flag.Duration("timeout", 30*time.Second, "timeout for each backend request, every provider's (overrides the config)")
|
||||
icons := flag.Bool("icons", true,
|
||||
"show Nerd Font icons (needs a Nerd Font v3+); disable with --icons=false or LAZYSECRETS_ICONS=0")
|
||||
clipClear := flag.Duration("clipboard-clear", 30*time.Second, "clear copied values from the clipboard after this long (0 disables)")
|
||||
@@ -207,9 +208,24 @@ Flags:
|
||||
// Precedence: flag > environment > config file > default.
|
||||
set := map[string]bool{}
|
||||
flag.Visit(func(f *flag.Flag) { set[f.Name] = true })
|
||||
if !set["timeout"] && cfg.Providers.Timeout > 0 {
|
||||
*timeout = cfg.Providers.Timeout
|
||||
// Each provider's own timeout, unless --timeout sets them all.
|
||||
timeouts := map[provider.Kind]time.Duration{}
|
||||
if !set["timeout"] {
|
||||
if cfg.Providers.Timeout > 0 {
|
||||
*timeout = cfg.Providers.Timeout
|
||||
}
|
||||
for k, d := range map[provider.Kind]time.Duration{
|
||||
provider.KindAzure: cfg.Providers.Azure.Timeout,
|
||||
provider.KindDatabricks: cfg.Providers.Databricks.Timeout,
|
||||
provider.KindRepo: cfg.Providers.Repos.Timeout,
|
||||
} {
|
||||
if d > 0 {
|
||||
timeouts[k] = d
|
||||
}
|
||||
}
|
||||
}
|
||||
// timeoutFor is how long a request to a provider of kind k may take.
|
||||
timeoutFor := func(k provider.Kind) time.Duration { return cmp.Or(timeouts[k], *timeout) }
|
||||
if !set["clipboard-clear"] && cfg.Values.ClipboardClear != nil {
|
||||
*clipClear = *cfg.Values.ClipboardClear
|
||||
}
|
||||
@@ -314,12 +330,18 @@ Flags:
|
||||
log.SetOutput(io.Discard)
|
||||
|
||||
if getRef != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeoutFor(getRef.Kind))
|
||||
defer cancel()
|
||||
return get(ctx, providers, st, *getRef)
|
||||
}
|
||||
if shareArgs != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
||||
// The files from a repo, the key from whichever provider it's
|
||||
// in: the longest timeout.
|
||||
d := *timeout
|
||||
for _, t := range timeouts {
|
||||
d = max(d, t)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), d)
|
||||
defer cancel()
|
||||
return shareFiles(ctx, providers, st, cfg.Sharing.Key, shareRules(cfg), shareArgs, os.Stdout)
|
||||
}
|
||||
@@ -372,6 +394,7 @@ Flags:
|
||||
|
||||
m := app.New(providers, app.Options{
|
||||
Timeout: *timeout,
|
||||
Timeouts: timeouts,
|
||||
Icons: *icons,
|
||||
ClipboardClear: *clipClear,
|
||||
FlatSources: cfg.UI.SourcesView == "flat",
|
||||
|
||||
Reference in new issue
Block a user