Last active
April 20, 2018 18:21
-
-
Save Rukenshia/8e8dbf95a36f0928d77e01e41387651f to your computer and use it in GitHub Desktop.
Vault library basic usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/hashicorp/vault/api" | |
) | |
func main() { | |
// Create the client | |
cfg := api.DefaultConfig() | |
cfg.Address = "http://myVaultAddress:8200" | |
client, err := api.NewClient(cfg) | |
if err != nil { | |
log.Fatal(err) | |
} | |
client.SetToken("abcdefg-mytoken") | |
// Example: Write | |
_, err = client.Logical().Write("secrets/my-secret", map[string]interface{}{ | |
"value": "hello there", | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Example: Read | |
mySecret, err := client.Logical().Read("secrets/my-secret") | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("My Secret Value is %v", mySecret.Data["value"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment