A Go vault client for the rest of us.
vaultapi is a vault client library for Go programs, targeted at the "99% use case". What this means is that while an official Go client provided by Hashicorp exists and exposes the complete functionality of vault, it is often difficult to use and is extremely inconvenient to work with in test cases. This vault library for Go aims to be easily mockable while providing interfaces that are easy to work with.
Like any Go library, just use go get
to install. If the Go team ever officially blesses a package
manager, this library will incorporate that.
go get github.com/shoenig/vaultapi
Creating a vault Client is very simple, just call New
with the desired ClientOptions
.
tracer := log.New(os.Stdout, "vaultapi-", log.LstdFlags)
options := vaultapi.ClientOptions{
Servers: []string{"https://localhost:8200"},
HTTPTimeout: 10 * time.Second, // default
SkipTLSVerification: false, // default
Logger: tracer,
}
tokener := vaultapi.NewStaticToken("abcdefgh-abcd-abcd-abcdefgh")
client, err := vaultapi.New(options, tokener)
// client implements the vaultapi.Client interface
leader, err := client.Leader()
// etc ...