mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-19 16:57:40 +07:00
37 lines
791 B
Go
37 lines
791 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
// "crypto/rand"
|
||
|
|
||
|
vault "github.com/hashicorp/vault/api"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
config := vault.DefaultConfig()
|
||
|
|
||
|
config.Address = "http://127.0.0.1:8200"
|
||
|
|
||
|
client, err := vault.NewClient(config)
|
||
|
if err != nil {
|
||
|
log.Fatalf("unable to initialize Vault client: %v", err)
|
||
|
}
|
||
|
|
||
|
// Authenticate
|
||
|
// WARNING: This quickstart uses the root token for our Vault dev server.
|
||
|
// Don't do this in production!
|
||
|
client.SetToken("root") // TODO use secure token
|
||
|
|
||
|
secretData := map[string]interface{}{
|
||
|
"data": map[string]interface{}{
|
||
|
"value": "verystronkpassword",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
_, err = client.Logical().Write("secret/data/gitea/admin-password", secretData)
|
||
|
if err != nil {
|
||
|
log.Fatalf("Unable to write secret: %v", err)
|
||
|
}
|
||
|
log.Println("Secret written successfully.")
|
||
|
}
|