Skip to content

Instantly share code, notes, and snippets.

@nnzv
Created January 1, 2023 17:14
Show Gist options
  • Save nnzv/42eb581c132f5909191bafae9febb5e1 to your computer and use it in GitHub Desktop.
Save nnzv/42eb581c132f5909191bafae9febb5e1 to your computer and use it in GitHub Desktop.
Create gopass secrets based on bitwarden JSON vault.
package main
import (
"context"
"log"
"strings"
"io/ioutil"
"encoding/json"
"github.com/gopasspw/gopass/pkg/gopass/api"
"github.com/gopasspw/gopass/pkg/gopass/secrets"
)
type Vault struct {
Items []Items `json:"items"`
}
type Items struct {
Name string `json:"name"`
Login Login `json:"login"`
}
type Login struct {
Password string `json:"password"`
}
func main() {
var vault Vault
ctx := context.Background()
gp, err := api.New(ctx)
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadFile("storage.json")
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(data, &vault)
if err != nil {
log.Fatal(err)
}
for _, i := range vault.Items {
var b strings.Builder
b.WriteString(i.Login.Password)
sec := secrets.New()
sec.SetPassword(b.String())
err = gp.Set(ctx, i.Name, sec)
if err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment