Skip to content

Commit

Permalink
Make all functions in vault methods
Browse files Browse the repository at this point in the history
  • Loading branch information
slarwise committed Aug 16, 2024
1 parent 6f73d5c commit b854c09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{}
Expand All @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/vault/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit b854c09

Please sign in to comment.