Skip to content

Commit

Permalink
fix extended list issue when vault namespace is set
Browse files Browse the repository at this point in the history
  • Loading branch information
tianhaopx committed Aug 6, 2020
1 parent acc09e6 commit 8b8f7ce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"regexp"
"sync"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -58,6 +59,11 @@ func extendedList() error {
return errors.Wrap(err, "Failed to read tokens from backend storage")
}

re, err := regexp.Compile(`^(http[s]?://[^:/\s]+)/?(.*)$`)
if err != nil {
return errors.Wrap(err, "Failed to compile regexp for vault address")
}

// fan-out parallel token lookups, fan-in to result channels. Output and Error
// channels are rendered separately to ensure correct aligntment in the outputted table
w := &tabwriter.Writer{}
Expand Down Expand Up @@ -85,12 +91,16 @@ func extendedList() error {
vcfg := vault.DefaultConfig() // VAULT_ env vars
vcfg.Timeout = 5 * time.Second
vcfg.MaxRetries = 1
vcfg.Address = addr
addrSlice := re.FindStringSubmatch(addr)
vcfg.Address = addrSlice[1]
client, err := vault.NewClient(vcfg)
if err != nil {
errCh <- fmt.Errorf("%s\t** ERROR **\t%s", addr, err)
return
}
if addrSlice[2] != "" {
client.SetNamespace(addrSlice[2])
}
client.SetToken(token.Token)
s, err := client.Auth().Token().LookupSelf()
if err != nil {
Expand Down

0 comments on commit 8b8f7ce

Please sign in to comment.