diff --git a/internal/vault/client.go b/internal/vault/client.go index a3905ba..7fbda61 100644 --- a/internal/vault/client.go +++ b/internal/vault/client.go @@ -23,7 +23,7 @@ type dirEnt struct { var cachedKeys = make(map[string][]string) -func GetKeys(client Client, mount string) []string { +func (c Client) GetKeys(mount string) []string { if keys, found := cachedKeys[mount]; found { return keys } @@ -33,7 +33,7 @@ func GetKeys(client Client, mount string) []string { } recv := make(chan string) go func() { - recurse(recv, client, mount, entrypoint) + c.recurse(recv, mount, entrypoint) close(recv) }() keys := []string{} @@ -44,12 +44,12 @@ func GetKeys(client Client, mount string) []string { return keys } -func recurse(recv chan string, client Client, mount string, entry dirEnt) { +func (c Client) recurse(recv chan string, mount string, entry dirEnt) { if !entry.IsDir { recv <- entry.Name return } - relativeEntries, err := client.listDir(mount, entry.Name) + relativeEntries, err := c.listDir(mount, entry.Name) if err != nil { slog.Error("Failed to list directory", "directory", entry.Name, "err", err.Error()) return @@ -66,7 +66,7 @@ func recurse(recv chan string, client Client, mount string, entry dirEnt) { wg.Add(1) go func(entry dirEnt) { defer wg.Done() - recurse(recv, client, mount, e) + c.recurse(recv, mount, e) }(e) } wg.Wait() diff --git a/internal/vault/client_test.go b/internal/vault/client_test.go index cf12559..9eea4b8 100644 --- a/internal/vault/client_test.go +++ b/internal/vault/client_test.go @@ -37,7 +37,7 @@ func TestGetKeys(t *testing.T) { Addr: vaultAddr, Token: token, } - keys := GetKeys(vaultClient, "secret") + keys := vaultClient.GetKeys("secret") if len(keys) != len(secrets) { t.Fatalf("Expected %d keys, got %d", len(secrets), len(keys)) } diff --git a/main.go b/main.go index 2bca2ea..7ef199b 100644 --- a/main.go +++ b/main.go @@ -108,7 +108,7 @@ func main() { drawPrompt(state) drawLoadingScreen(state) screen.Show() - state.Keys = vault.GetKeys(vaultClient, state.Mounts[state.CurrentMount]) + state.Keys = vaultClient.GetKeys(state.Mounts[state.CurrentMount]) newKeysView(&state) for { ev := screen.PollEvent() @@ -373,7 +373,7 @@ func nextMount(s *Ui) { } drawLoadingScreen(*s) s.Screen.Show() - s.Keys = vault.GetKeys(s.Vault, s.Mounts[s.CurrentMount]) + s.Keys = s.Vault.GetKeys(s.Mounts[s.CurrentMount]) s.Prompt = "" newKeysView(s) } @@ -382,7 +382,7 @@ func previousMount(s *Ui) { s.CurrentMount = (s.CurrentMount + 1) % len(s.Mounts) drawLoadingScreen(*s) s.Screen.Show() - s.Keys = vault.GetKeys(s.Vault, s.Mounts[s.CurrentMount]) + s.Keys = s.Vault.GetKeys(s.Mounts[s.CurrentMount]) s.Prompt = "" newKeysView(s) }