Skip to content

Instantly share code, notes, and snippets.

@michelvocks
Created September 20, 2019 09:25
Show Gist options
  • Save michelvocks/7ad88ca886d2b383f9a73850030f9a86 to your computer and use it in GitHub Desktop.
Save michelvocks/7ad88ca886d2b383f9a73850030f9a86 to your computer and use it in GitHub Desktop.
Vault Client API approle login
package main
import (
"fmt"
"log"
"github.com/hashicorp/vault/api"
)
var client *api.Client
func main() {
conf := api.DefaultConfig()
var err error
client, err = api.NewClient(conf)
client.SetAddress("http://localhost:8200")
myRoleID := "287c396a-34f0-9547-a099-98b5b6342866"
mySecretID := "ffa85275-4db8-342e-b5cc-134817e1ea11"
resp, err := client.Logical().Write("auth/approle/login", map[string]interface{}{
"role_id": myRoleID,
"secret_id": mySecretID,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Vault token: %s\n", resp.Auth.ClientToken)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment