https://github.com/canidam/libvault
A lightweight Vault client module written in Go, with no dependencies, that is intuitive and user-friendly
https://github.com/canidam/libvault
go golang hashicorp hashicorp-vault secrets secrets-management vault-api vault-client
Last synced: 5 months ago
JSON representation
A lightweight Vault client module written in Go, with no dependencies, that is intuitive and user-friendly
- Host: GitHub
- URL: https://github.com/canidam/libvault
- Owner: canidam
- License: gpl-3.0
- Created: 2021-05-20T06:28:50.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-16T15:48:01.000Z (about 5 years ago)
- Last Synced: 2024-06-20T15:53:37.932Z (about 2 years ago)
- Topics: go, golang, hashicorp, hashicorp-vault, secrets, secrets-management, vault-api, vault-client
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 74
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libvault
[](https://github.com/canidam/libvault/actions/workflows/ci.yml)   
A *lightweight* Hashicorp Vault client written in Go, with no dependencies.
It aims to provide an *intuitive, simple API* that is easy to use. Just like with the CLI.
Using the module, you currently can only *read* secrets from a Vault engine. This is an *ongoing project*,
feel free to open FRs, PRs or issues.
## Features
- Supported [Auth Methods](https://www.vaultproject.io/docs/auth):
- Tokens
- AppRole
- AwsRole (EC2 method)
- Supported [Secrets Engines](https://www.vaultproject.io/docs/secrets):
- [KV v2.0](https://www.vaultproject.io/docs/secrets/kv/kv-v2)
- Supports self-signed CA certificates
- By default, the Vault API secrets are consumed using environment variables. You can provide them to the client if you prefer. Check the tests file for examples.
## Installation
```bash
go get -d -v github.com/canidam/libvault
```
## Usage
```go
package main
import (
"fmt"
"github.com/canidam/libvault"
"os"
)
func main() {
//
// Example using Token
//
// If env var is not set
os.Setenv("VAULT_TOKEN", "my_token")
tokenClient, err := libvault.NewClient(SetVaultAddr("http://localhost:8200"))
if err != nil {
// handle error
}
var secret_path = "/my.secrets"
secretsUsingToken, err := tokenClient.Read(secret_path)
if err != nil {
// handle error
}
// secrets is of type map[string]string
for k, v := range secretsUsingToken {
fmt.Printf("key %s, secret %s\n", k, v)
}
//
// Example using AppRole
//
// If env var is not set
os.Setenv("VAULT_ROLE_ID", "my_role_id")
os.Setenv("VAULT_SECRET_ID", "my_secret_id")
os.Setenv("VAULT_ADDR", "http://localhost:8200")
approleClient, err := libvault.NewClient(UseApprole())
if err != nil {
// handle error
}
secretsUsingApprole, err := approleClient.Read(secret_path)
if err != nil {
// handle error
}
// secrets is of type map[string]string
for k, v := range secretsUsingApprole {
fmt.Printf("key %s, secret %s\n", k, v)
}
}
```
## Documentation
Can be found [here](docs/DOCS.md)
## Tests
Checkout the project and run
```bash
go test -v ./...
```
`testdata/` is a special directory containing raw data for unit-tests.
`tests/` includes scripts (and it's own README) for starting a dev Vault server for development.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.
Please make sure to update tests as appropriate.
## Roadmap
TBD
## License
[GPLv3.0](https://choosealicense.com/licenses/gpl-3.0/)