Last active
December 21, 2022 17:05
-
-
Save sjenning/c44cc63e8c0c20bc2b37e8e6b6e4a1a8 to your computer and use it in GitHub Desktop.
Revisions
-
sjenning revised this gist
Dec 21, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import ( "strings" ) // https://bitwarden.com/help/condition-bitwarden-import/#condition-a-json type BitWardenItems struct { Items []BitWardenItem `json:"items,omitempty"` } -
sjenning created this gist
Dec 21, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ package main import ( "bufio" "encoding/json" "log" "os" "strings" ) type BitWardenItems struct { Items []BitWardenItem `json:"items,omitempty"` } const BitWardenLoginType = 1 type BitWardenItem struct { Type int `json:"type,omitempty"` Name string `json:"name,omitempty"` Login BitWardenLogin `json:"login,omitempty"` } type BitWardenLogin struct { Password string `json:"password,omitempty"` } func main() { // import file is one account per line with account name then password separated by a space file, err := os.Open("pass-export.csv") if err != nil { log.Fatal(err) } defer file.Close() var output BitWardenItems scanner := bufio.NewScanner(file) for scanner.Scan() { line := strings.Split(scanner.Text(), " ") output.Items = append(output.Items, BitWardenItem{ Type: BitWardenLoginType, Name: line[0], Login: BitWardenLogin{ Password: line[1], }, }) } if err := scanner.Err(); err != nil { log.Fatal(err) } jsonBytes, err := json.Marshal(output) if err != nil { log.Fatal(err) } err = os.WriteFile("bitwarden-import.csv", jsonBytes, 0644) if err != nil { log.Fatal(err) } }