This package uses the Bitwarden CLI to get bitwarden secrets.
It can be used in scripts where you need passwords/secrets but don't want to hardcode them in your code.
- Install the bitwarden CLI
- Run
bw login
to login
That's it! You can now use this package to retreive passwords from code.
package main
import (
"context"
"fmt"
"log"
"syscall"
"github.com/floriaanpost/go-bitwarden-client"
"golang.org/x/term"
)
const itemID = "b2bccebf-7ec2-436e-8d2c-ad4700783d83"
func main() {
// start the Bitwarden server
bw := bitwarden.New()
defer bw.Close()
// get your master password from the command line
fmt.Printf("Enter your master password: ")
masterPassword, err := term.ReadPassword(syscall.Stdin)
if err != nil {
return "", err
}
fmt.Println()
// unlock your vault
if err := bw.Unlock(context.TODO(), string(masterPassword)); err != nil {
fmt.Println("failed unlocking vault:", err)
return
}
defer bw.Lock(context.TODO())
// get a secure note
note, err := bw.GetSecureNote(context.TODO(), itemID)
if err != nil {
fmt.Println("failed getting secure note:", err)
return
}
fmt.Println(note)
}
- Improve go docs