Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petems/vault-cert-helpers
Go library for working with PKI with the Vault API
https://github.com/petems/vault-cert-helpers
Last synced: 7 days ago
JSON representation
Go library for working with PKI with the Vault API
- Host: GitHub
- URL: https://github.com/petems/vault-cert-helpers
- Owner: petems
- License: mit
- Created: 2020-03-17T23:40:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-03-25T10:27:22.000Z (over 4 years ago)
- Last Synced: 2024-10-19T23:46:25.763Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vault-cert-helpers
![Run lint and tests on Go code](https://github.com/petems/vault-cert-helpers/workflows/Run%20lint%20and%20tests%20on%20Go%20code/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/petems/vault-cert-helpers)](https://goreportcard.com/report/github.com/petems/vault-cert-helpers)A helper class to iterate through certs from Vault
Mostly an excuse to help me learn [go-vcr](https://github.com/dnaeon/go-vcr/) for testing.
## Usage
```go
package mainimport (
"fmt"
"net/http""github.com/hashicorp/vault/api"
. "github.com/petems/vault-cert-helpers"
)func createVaultClient() *api.Client {
// Create an HTTP client and inject our transport
client := &http.Client{}// Create Vault client with vcr'd http.Client
vaultClient, err := api.NewClient(&api.Config{Address: "http://127.0.0.1:8200", HttpClient: client})
if err != nil {
panic("Failed to get new Vault client")
}// We're using VAULT_DEV_ROOT_TOKEN_ID=ROOT with a vault server -dev
vaultClient.SetToken("ROOT")return vaultClient
}func main() {
vaultClient := createVaultClient()
// Get list of certs from /pki endpoint
listOfCertsSecret, err := GetListOfCerts(vaultClient, "pki")if err != nil {
panic(err)
}arrayOfCerts, err := GetArrayOfCertsFromVault(vaultClient, listOfCertsSecret, "pki")
fmt.Printf("First cert CN is: %s\n", arrayOfCerts[0].Subject.CommonName)
fmt.Printf("Second cert CN is: %s\n", arrayOfCerts[1].Subject.CommonName)}
```