feat: config grouped by area, with per-provider timeouts and an update interval #60
No files matched your search
+28
-5
@@ -3,6 +3,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -106,7 +107,7 @@ func run() error {
|
|||||||
showVersion := flag.Bool("version", false, "print the version and exit")
|
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)")
|
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")
|
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,
|
icons := flag.Bool("icons", true,
|
||||||
"show Nerd Font icons (needs a Nerd Font v3+); disable with --icons=false or LAZYSECRETS_ICONS=0")
|
"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)")
|
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.
|
// Precedence: flag > environment > config file > default.
|
||||||
set := map[string]bool{}
|
set := map[string]bool{}
|
||||||
flag.Visit(func(f *flag.Flag) { set[f.Name] = true })
|
flag.Visit(func(f *flag.Flag) { set[f.Name] = true })
|
||||||
if !set["timeout"] && cfg.Providers.Timeout > 0 {
|
// Each provider's own timeout, unless --timeout sets them all.
|
||||||
*timeout = cfg.Providers.Timeout
|
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 {
|
if !set["clipboard-clear"] && cfg.Values.ClipboardClear != nil {
|
||||||
*clipClear = *cfg.Values.ClipboardClear
|
*clipClear = *cfg.Values.ClipboardClear
|
||||||
}
|
}
|
||||||
@@ -314,12 +330,18 @@ Flags:
|
|||||||
log.SetOutput(io.Discard)
|
log.SetOutput(io.Discard)
|
||||||
|
|
||||||
if getRef != nil {
|
if getRef != nil {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeoutFor(getRef.Kind))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return get(ctx, providers, st, *getRef)
|
return get(ctx, providers, st, *getRef)
|
||||||
}
|
}
|
||||||
if shareArgs != nil {
|
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()
|
defer cancel()
|
||||||
return shareFiles(ctx, providers, st, cfg.Sharing.Key, shareRules(cfg), shareArgs, os.Stdout)
|
return shareFiles(ctx, providers, st, cfg.Sharing.Key, shareRules(cfg), shareArgs, os.Stdout)
|
||||||
}
|
}
|
||||||
@@ -372,6 +394,7 @@ Flags:
|
|||||||
|
|
||||||
m := app.New(providers, app.Options{
|
m := app.New(providers, app.Options{
|
||||||
Timeout: *timeout,
|
Timeout: *timeout,
|
||||||
|
Timeouts: timeouts,
|
||||||
Icons: *icons,
|
Icons: *icons,
|
||||||
ClipboardClear: *clipClear,
|
ClipboardClear: *clipClear,
|
||||||
FlatSources: cfg.UI.SourcesView == "flat",
|
FlatSources: cfg.UI.SourcesView == "flat",
|
||||||
|
|||||||
+4
-1
@@ -27,17 +27,20 @@ updates:
|
|||||||
- https://github.com/karleinarb/lazysecrets
|
- https://github.com/karleinarb/lazysecrets
|
||||||
- https://git.kebcloud.no/keb/lazysecrets
|
- https://git.kebcloud.no/keb/lazysecrets
|
||||||
providers:
|
providers:
|
||||||
timeout: 30s # per backend request
|
timeout: 30s # per backend request; a provider's own timeout overrides it
|
||||||
azure: # applies to every az account
|
azure: # applies to every az account
|
||||||
enabled: true # default
|
enabled: true # default
|
||||||
|
timeout: 30s
|
||||||
hideSubscriptions: [platform-mgmt] # by name or ID
|
hideSubscriptions: [platform-mgmt] # by name or ID
|
||||||
vaults: # listed under "Pinned vaults", for vaults
|
vaults: # listed under "Pinned vaults", for vaults
|
||||||
- https://kv-foo.vault.azure.net/ # you can read but not discover
|
- https://kv-foo.vault.azure.net/ # you can read but not discover
|
||||||
databricks:
|
databricks:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
timeout: 30s
|
||||||
hideProfiles: [test]
|
hideProfiles: [test]
|
||||||
repos:
|
repos:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
timeout: 30s
|
||||||
roots: [~/git]
|
roots: [~/git]
|
||||||
paths: [~/work/infra]
|
paths: [~/work/infra]
|
||||||
include: ["secrets/**"]
|
include: ["secrets/**"]
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ type KeyRules struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Providers struct {
|
type Providers struct {
|
||||||
// Timeout bounds each backend request; defaults to 30s.
|
// Timeout bounds each backend request; defaults to 30s. Each
|
||||||
|
// provider's own timeout overrides it for that provider.
|
||||||
Timeout time.Duration `yaml:"timeout"`
|
Timeout time.Duration `yaml:"timeout"`
|
||||||
Azure Azure `yaml:"azure"`
|
Azure Azure `yaml:"azure"`
|
||||||
Databricks Databricks `yaml:"databricks"`
|
Databricks Databricks `yaml:"databricks"`
|
||||||
@@ -134,6 +135,8 @@ type Providers struct {
|
|||||||
// that repo is the only one shown; elsewhere, the ones in Paths and under
|
// that repo is the only one shown; elsewhere, the ones in Paths and under
|
||||||
// Roots.
|
// Roots.
|
||||||
type Repos struct {
|
type Repos struct {
|
||||||
|
// Timeout overrides providers.timeout for these requests.
|
||||||
|
Timeout time.Duration `yaml:"timeout"`
|
||||||
// Enabled defaults to true.
|
// Enabled defaults to true.
|
||||||
Enabled *bool `yaml:"enabled"`
|
Enabled *bool `yaml:"enabled"`
|
||||||
Paths []string `yaml:"paths"`
|
Paths []string `yaml:"paths"`
|
||||||
@@ -148,6 +151,8 @@ type Repos struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Azure struct {
|
type Azure struct {
|
||||||
|
// Timeout overrides providers.timeout for these requests.
|
||||||
|
Timeout time.Duration `yaml:"timeout"`
|
||||||
// Enabled defaults to true.
|
// Enabled defaults to true.
|
||||||
Enabled *bool `yaml:"enabled"`
|
Enabled *bool `yaml:"enabled"`
|
||||||
// HideSubscriptions lists subscriptions to leave out, by name or ID.
|
// HideSubscriptions lists subscriptions to leave out, by name or ID.
|
||||||
@@ -158,6 +163,8 @@ type Azure struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Databricks struct {
|
type Databricks struct {
|
||||||
|
// Timeout overrides providers.timeout for these requests.
|
||||||
|
Timeout time.Duration `yaml:"timeout"`
|
||||||
// Enabled defaults to true.
|
// Enabled defaults to true.
|
||||||
Enabled *bool `yaml:"enabled"`
|
Enabled *bool `yaml:"enabled"`
|
||||||
HideProfiles []string `yaml:"hideProfiles"`
|
HideProfiles []string `yaml:"hideProfiles"`
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ storage:
|
|||||||
providers:
|
providers:
|
||||||
timeout: 1m
|
timeout: 1m
|
||||||
azure:
|
azure:
|
||||||
|
timeout: 2m
|
||||||
hideSubscriptions: [platform-mgmt]
|
hideSubscriptions: [platform-mgmt]
|
||||||
vaults:
|
vaults:
|
||||||
- https://kv-foo.vault.azure.net/
|
- https://kv-foo.vault.azure.net/
|
||||||
@@ -40,7 +41,7 @@ providers:
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if c.UI.Icons == nil || *c.UI.Icons || c.Values.ClipboardClear == nil || *c.Values.ClipboardClear != 45*time.Second ||
|
if c.UI.Icons == nil || *c.UI.Icons || c.Values.ClipboardClear == nil || *c.Values.ClipboardClear != 45*time.Second ||
|
||||||
c.Providers.Timeout != time.Minute || len(c.Providers.Azure.Vaults) != 1 || c.Providers.Databricks.HideProfiles[0] != "test" {
|
c.Providers.Timeout != time.Minute || c.Providers.Azure.Timeout != 2*time.Minute || len(c.Providers.Azure.Vaults) != 1 || c.Providers.Databricks.HideProfiles[0] != "test" {
|
||||||
t.Errorf("config = %+v", c)
|
t.Errorf("config = %+v", c)
|
||||||
}
|
}
|
||||||
if c.UI.SourcesView != "flat" || On(c.Storage.History) || !On(c.Storage.Cache) {
|
if c.UI.SourcesView != "flat" || On(c.Storage.History) || !On(c.Storage.Cache) {
|
||||||
|
|||||||
+31
-14
@@ -65,6 +65,8 @@ const (
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
// Timeout bounds every provider call. Defaults to 30s.
|
// Timeout bounds every provider call. Defaults to 30s.
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
// Timeouts override Timeout for the providers of a kind.
|
||||||
|
Timeouts map[provider.Kind]time.Duration
|
||||||
// Icons shows Nerd Font glyphs next to backends.
|
// Icons shows Nerd Font glyphs next to backends.
|
||||||
Icons bool
|
Icons bool
|
||||||
// Clipboard defaults to the system clipboard, or OSC52 over SSH.
|
// Clipboard defaults to the system clipboard, or OSC52 over SSH.
|
||||||
@@ -146,7 +148,7 @@ type Clipboard interface {
|
|||||||
type Model struct {
|
type Model struct {
|
||||||
providers []provider.Provider
|
providers []provider.Provider
|
||||||
byID map[string]provider.Provider
|
byID map[string]provider.Provider
|
||||||
timeout time.Duration
|
timeout timeouts
|
||||||
|
|
||||||
keys keys.Map
|
keys keys.Map
|
||||||
st styles.Styles
|
st styles.Styles
|
||||||
@@ -378,7 +380,7 @@ func New(providers []provider.Provider, opts Options) Model {
|
|||||||
m := Model{
|
m := Model{
|
||||||
providers: providers,
|
providers: providers,
|
||||||
byID: map[string]provider.Provider{},
|
byID: map[string]provider.Provider{},
|
||||||
timeout: opts.Timeout,
|
timeout: timeouts{def: opts.Timeout, byKind: opts.Timeouts},
|
||||||
keys: keys.Default(),
|
keys: keys.Default(),
|
||||||
st: styles.Default(),
|
st: styles.Default(),
|
||||||
spin: spinner.New(spinner.WithSpinner(spinner.Dot)),
|
spin: spinner.New(spinner.WithSpinner(spinner.Dot)),
|
||||||
@@ -1246,7 +1248,7 @@ func (m *Model) showVersions(o provider.Object, key string) tea.Cmd {
|
|||||||
}
|
}
|
||||||
m.secrets.SetLoading()
|
m.secrets.SetLoading()
|
||||||
p := m.providerFor(o.Container.Source)
|
p := m.providerFor(o.Container.Source)
|
||||||
ctx, req := m.begin(slotObjects)
|
ctx, req := m.begin(slotObjects, o.Container.Source.Kind)
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
items, err := p.Versions(ctx, o)
|
items, err := p.Versions(ctx, o)
|
||||||
for i := range items {
|
for i := range items {
|
||||||
@@ -1276,7 +1278,7 @@ func (m *Model) countVersions(o provider.Object) tea.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p := m.providerFor(o.Container.Source)
|
p := m.providerFor(o.Container.Source)
|
||||||
ctx, req := m.begin(slotVersions)
|
ctx, req := m.begin(slotVersions, o.Container.Source.Kind)
|
||||||
return m.settled(ctx, func() tea.Msg {
|
return m.settled(ctx, func() tea.Msg {
|
||||||
items, err := p.Versions(ctx, o)
|
items, err := p.Versions(ctx, o)
|
||||||
for i := range items {
|
for i := range items {
|
||||||
@@ -1427,11 +1429,26 @@ func (m *Model) autoLoad(msg sourcesMsg) tea.Cmd {
|
|||||||
return m.crawlStart()
|
return m.crawlStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin starts a cancellable request for pane p, cancelling any in flight.
|
// timeouts bound each provider request: its kind's, else the default.
|
||||||
func (m *Model) begin(p slot) (context.Context, int) {
|
type timeouts struct {
|
||||||
|
def time.Duration
|
||||||
|
byKind map[provider.Kind]time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// of is how long a request to a provider of kind k may take.
|
||||||
|
func (t timeouts) of(k provider.Kind) time.Duration {
|
||||||
|
if d, ok := t.byKind[k]; ok {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
return t.def
|
||||||
|
}
|
||||||
|
|
||||||
|
// begin starts a cancellable request for pane p to a provider of kind k,
|
||||||
|
// cancelling any in flight.
|
||||||
|
func (m *Model) begin(p slot, k provider.Kind) (context.Context, int) {
|
||||||
m.cancelReq(p)
|
m.cancelReq(p)
|
||||||
m.seq++
|
m.seq++
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), m.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), m.timeout.of(k))
|
||||||
m.reqID[p], m.cancel[p] = m.seq, cancel
|
m.reqID[p], m.cancel[p] = m.seq, cancel
|
||||||
return ctx, m.seq
|
return ctx, m.seq
|
||||||
}
|
}
|
||||||
@@ -1485,7 +1502,7 @@ func (m Model) sourcesCmd() tea.Cmd {
|
|||||||
gen := m.sourcesGen
|
gen := m.sourcesGen
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
for _, p := range m.providers {
|
for _, p := range m.providers {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), m.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), m.timeout.of(p.Kind()))
|
||||||
cmds = append(cmds, func() tea.Msg {
|
cmds = append(cmds, func() tea.Msg {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
s, err := p.Sources(ctx)
|
s, err := p.Sources(ctx)
|
||||||
@@ -1496,7 +1513,7 @@ func (m Model) sourcesCmd() tea.Cmd {
|
|||||||
})
|
})
|
||||||
// The source it started in, quickly, on its own.
|
// The source it started in, quickly, on its own.
|
||||||
if c, ok := p.(provider.Current); ok {
|
if c, ok := p.(provider.Current); ok {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), m.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), m.timeout.of(p.Kind()))
|
||||||
cmds = append(cmds, func() tea.Msg {
|
cmds = append(cmds, func() tea.Msg {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
src, ok := c.Current(ctx)
|
src, ok := c.Current(ctx)
|
||||||
@@ -1513,7 +1530,7 @@ func (m Model) sourcesCmd() tea.Cmd {
|
|||||||
|
|
||||||
func (m *Model) loadContainers(src provider.Source, key string) tea.Cmd {
|
func (m *Model) loadContainers(src provider.Source, key string) tea.Cmd {
|
||||||
p := m.providerFor(src)
|
p := m.providerFor(src)
|
||||||
ctx, req := m.begin(slotContainers)
|
ctx, req := m.begin(slotContainers, src.Kind)
|
||||||
return m.settled(ctx, func() tea.Msg {
|
return m.settled(ctx, func() tea.Msg {
|
||||||
items, err := p.Containers(ctx, src)
|
items, err := p.Containers(ctx, src)
|
||||||
// Carry the source as given, with its provider ID, so later
|
// Carry the source as given, with its provider ID, so later
|
||||||
@@ -1532,7 +1549,7 @@ func (m *Model) loadContainers(src provider.Source, key string) tea.Cmd {
|
|||||||
func (m *Model) loadObjects(c provider.Container, t provider.ObjectType, key string) tea.Cmd {
|
func (m *Model) loadObjects(c provider.Container, t provider.ObjectType, key string) tea.Cmd {
|
||||||
cands := m.candidates(c.Source)
|
cands := m.candidates(c.Source)
|
||||||
known := len(cands) == 1 && cands[0].ID() == c.Source.Provider
|
known := len(cands) == 1 && cands[0].ID() == c.Source.Provider
|
||||||
ctx, req := m.begin(slotObjects)
|
ctx, req := m.begin(slotObjects, c.Source.Kind)
|
||||||
return m.settled(ctx, func() tea.Msg {
|
return m.settled(ctx, func() tea.Msg {
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, p := range cands {
|
for _, p := range cands {
|
||||||
@@ -1560,7 +1577,7 @@ func (m *Model) loadObjects(c provider.Container, t provider.ObjectType, key str
|
|||||||
|
|
||||||
func (m *Model) fetchValue(s provider.Object) tea.Cmd {
|
func (m *Model) fetchValue(s provider.Object) tea.Cmd {
|
||||||
p := m.providerFor(s.Container.Source)
|
p := m.providerFor(s.Container.Source)
|
||||||
ctx, req := m.begin(slotValue)
|
ctx, req := m.begin(slotValue, s.Container.Source.Kind)
|
||||||
m.detail.SetLoading()
|
m.detail.SetLoading()
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
v, err := p.Value(ctx, s)
|
v, err := p.Value(ctx, s)
|
||||||
@@ -1579,7 +1596,7 @@ func (m *Model) describe(o provider.Object) tea.Cmd {
|
|||||||
m.detail.SetDescribing()
|
m.detail.SetDescribing()
|
||||||
}
|
}
|
||||||
p := m.providerFor(o.Container.Source)
|
p := m.providerFor(o.Container.Source)
|
||||||
ctx, req := m.begin(slotDescribe)
|
ctx, req := m.begin(slotDescribe, o.Container.Source.Kind)
|
||||||
return m.settled(ctx, func() tea.Msg {
|
return m.settled(ctx, func() tea.Msg {
|
||||||
obj, err := p.Describe(ctx, o)
|
obj, err := p.Describe(ctx, o)
|
||||||
return describeMsg{req: req, key: key, obj: obj, err: err}
|
return describeMsg{req: req, key: key, obj: obj, err: err}
|
||||||
@@ -1607,7 +1624,7 @@ func (m *Model) copyValue() tea.Cmd {
|
|||||||
return m.copyText(o.Name, v.Reveal(), true)
|
return m.copyText(o.Name, v.Reveal(), true)
|
||||||
}
|
}
|
||||||
p := m.providerFor(o.Container.Source)
|
p := m.providerFor(o.Container.Source)
|
||||||
ctx, req := m.begin(slotCopy)
|
ctx, req := m.begin(slotCopy, o.Container.Source.Kind)
|
||||||
m.flash = flash{text: "copying " + o.Name + "…"}
|
m.flash = flash{text: "copying " + o.Name + "…"}
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
v, err := p.Value(ctx, o)
|
v, err := p.Value(ctx, o)
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func (m *Model) runCommand(c commands.Command, rendered string, obj *provider.Ob
|
|||||||
o := *obj
|
o := *obj
|
||||||
p := m.providerFor(o.Container.Source)
|
p := m.providerFor(o.Container.Source)
|
||||||
m.flash = flash{text: "fetching " + o.Name + " for " + c.Description + "…"}
|
m.flash = flash{text: "fetching " + o.Name + " for " + c.Description + "…"}
|
||||||
timeout := m.timeout
|
timeout := m.timeout.of(o.Container.Source.Kind)
|
||||||
m.usedObject(o)
|
m.usedObject(o)
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ func (m *Model) loadDetails(c provider.Container) tea.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.details[key] = detailsState{loading: true}
|
m.details[key] = detailsState{loading: true}
|
||||||
ctx, req := m.begin(slotDetails)
|
ctx, req := m.begin(slotDetails, c.Source.Kind)
|
||||||
return m.settled(ctx, func() tea.Msg {
|
return m.settled(ctx, func() tea.Msg {
|
||||||
attrs, err := d.Details(ctx, c)
|
attrs, err := d.Details(ctx, c)
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ func (m *Model) copyFromRef(r ref.Ref) tea.Cmd {
|
|||||||
m.flash = flash{text: "copy: no account or profile for " + describeRef(r), isErr: true}
|
m.flash = flash{text: "copy: no account or profile for " + describeRef(r), isErr: true}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx, req := m.begin(slotCopy)
|
ctx, req := m.begin(slotCopy, r.Kind)
|
||||||
m.flash = flash{text: "copying " + r.Name + "…"}
|
m.flash = flash{text: "copying " + r.Name + "…"}
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|||||||
@@ -295,10 +295,10 @@ func (m *Model) crawlNext() tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) crawlCmd(job crawlJob) tea.Cmd {
|
func (m *Model) crawlCmd(job crawlJob) tea.Cmd {
|
||||||
timeout := m.timeout
|
|
||||||
if job.src != nil {
|
if job.src != nil {
|
||||||
p := m.providerFor(*job.src)
|
p := m.providerFor(*job.src)
|
||||||
src := *job.src
|
src := *job.src
|
||||||
|
timeout := m.timeout.of(src.Kind)
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
ctx, cancel := contextWithTimeout(timeout)
|
ctx, cancel := contextWithTimeout(timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -311,6 +311,7 @@ func (m *Model) crawlCmd(job crawlJob) tea.Cmd {
|
|||||||
}
|
}
|
||||||
c := *job.container
|
c := *job.container
|
||||||
p := m.providerFor(c.Source)
|
p := m.providerFor(c.Source)
|
||||||
|
timeout := m.timeout.of(c.Source.Kind)
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
ctx, cancel := contextWithTimeout(timeout)
|
ctx, cancel := contextWithTimeout(timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (m *Model) shareFiles(src provider.Source, cs []provider.Container) tea.Cmd
|
|||||||
m.flash = warning("these files can't be shared")
|
m.flash = warning("these files can't be shared")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
general, timeout := m.shareKey, m.timeout
|
general, timeout := m.shareKey, m.timeout.of(src.Kind)
|
||||||
m.flash = flash{text: "reading the files…"}
|
m.flash = flash{text: "reading the files…"}
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
@@ -216,7 +216,7 @@ func (m *Model) handleSealed(msg sealedMsg) tea.Cmd {
|
|||||||
func (m *Model) keyReader() func(ref.Ref) (provider.SecretValue, string, error) {
|
func (m *Model) keyReader() func(ref.Ref) (provider.SecretValue, string, error) {
|
||||||
providers, st, timeout := m.providers, m.store, m.timeout
|
providers, st, timeout := m.providers, m.store, m.timeout
|
||||||
return func(key ref.Ref) (provider.SecretValue, string, error) {
|
return func(key ref.Ref) (provider.SecretValue, string, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout.of(key.Kind))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
k := key
|
k := key
|
||||||
k.Version = ""
|
k.Version = ""
|
||||||
@@ -258,7 +258,7 @@ func (m *Model) offerShare(r ref.Ref) tea.Cmd {
|
|||||||
// openShare reads the key, decrypts the files and finds the repo's clone.
|
// openShare reads the key, decrypts the files and finds the repo's clone.
|
||||||
func (m *Model) openShare(s share.Sealed) tea.Cmd {
|
func (m *Model) openShare(s share.Sealed) tea.Cmd {
|
||||||
read := m.keyReader()
|
read := m.keyReader()
|
||||||
providers, timeout := m.providers, m.timeout
|
providers, timeout := m.providers, m.timeout.of(provider.KindRepo)
|
||||||
m.flash = flash{text: "decrypting with " + s.Key.Name + "…"}
|
m.flash = flash{text: "decrypting with " + s.Key.Name + "…"}
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
msg := shareOpenedMsg{sealed: s}
|
msg := shareOpenedMsg{sealed: s}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kebcloud.no/keb/lazysecrets/internal/provider"
|
||||||
|
"git.kebcloud.no/keb/lazysecrets/internal/provider/fake"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A provider's own timeout applies to it alone.
|
||||||
|
func TestTimeoutPerProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
d := newDriverOpts(t, Options{Timeout: 5 * time.Second, Timeouts: map[provider.Kind]time.Duration{provider.KindAzure: 10 * time.Millisecond}},
|
||||||
|
fake.Azure(300*time.Millisecond), fake.Databricks(300*time.Millisecond))
|
||||||
|
scr := d.screen()
|
||||||
|
if !strings.Contains(scr, "✗ Azure: context deadline exceeded") || !strings.Contains(scr, "Databricks (…)") ||
|
||||||
|
strings.Contains(scr, "Databricks: context deadline") {
|
||||||
|
t.Errorf("want Azure timed out and Databricks still loading:\n%s", scr)
|
||||||
|
}
|
||||||
|
if got := (timeouts{def: time.Minute}).of(provider.KindRepo); got != time.Minute {
|
||||||
|
t.Errorf("no override: %s, want the default", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user