Skip to content

Commit

Permalink
Create a vault client and start using getSecret
Browse files Browse the repository at this point in the history
  • Loading branch information
slarwise committed Aug 3, 2024
1 parent 0d4bd87 commit 01aecb1
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,42 @@ func main() {
IsDir: true,
Name: "mountA",
}
recurse(entry)
vault := VaultClient{
Addr: "http://127.0.0.1:8200",
Token: "dev-only-token",
}
recurse(vault, entry)
}

type DirEnt struct {
IsDir bool
Name string
}

func recurse(entry DirEnt) {
func recurse(vault VaultClient, entry DirEnt) {
if !entry.IsDir {
fmt.Printf("Found secret: %s\n", entry.Name)
secret := vault.getSecret(entry.Name)
fmt.Printf("%s - %s\n", entry.Name, secret)
return
}
entries := listDir(entry.Name)
entries := vault.listDir(entry.Name)
var wg sync.WaitGroup
for _, e := range entries {
wg.Add(1)
go func(entry DirEnt) {
defer wg.Done()
recurse(e)
recurse(vault, e)
}(e)
}
wg.Wait()
}

func listDir(name string) []DirEnt {
type VaultClient struct {
Addr string
Token string
}

func (v VaultClient) listDir(name string) []DirEnt {
if name == "mountA" {
return []DirEnt{
{IsDir: true, Name: "dirA"},
Expand All @@ -60,11 +70,19 @@ func listDir(name string) []DirEnt {
panic(fmt.Sprintf("Unknown dir %s", name))
}

func getSecret(name string) string {
if name == "dirA/secret1" {
func (v VaultClient) getSecret(name string) string {
switch name {
case "dirA/secret1":
return "password1"
} else if name == "secret2" {
case "secret2":
return "password2"
case "dirB/secret3":
return "password3"
case "dirB/dirC/secret4":
return "password4"
case "dirB/dirC/secret5":
return "password5"
default:
panic(fmt.Sprintf("Unknown secret %s", name))
}
panic(fmt.Sprintf("Unknown secret %s", name))
}

0 comments on commit 01aecb1

Please sign in to comment.