Skip to content

Commit

Permalink
Go 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Joibel committed Feb 18, 2023
1 parent 7e301be commit 228a231
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ You can just call GetItem and GetFolder if you're happy to do something with the

Basically because this is security related and reimplementation of anything is riskier than just using an existing tool for the purpose for which I needed it.

Bitwarden is GPL, and their [swagger.json](https://bitwarden.com/help/api/) is AGPL, which makes it hard to include in other projects. An executable boundary to the GPL licensed binary makes this easier to consume.
13 changes: 11 additions & 2 deletions getfolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ import (
"fmt"
)

// GetFolder finds a bitwarden folder by name and returns it or nil and error if it cannot
func GetFolder(folderName string) (*BwFolder, error) {
// ListAllFolder returns all bitwarden folders
func ListAllFolders() ([]BwFolder, error) {
folderjson, err := runBw("list", "folders")
if err != nil {
return nil, err
}
folders := make([]BwFolder, 0)
json.Unmarshal([]byte(folderjson), &folders)
return folders, nil
}

// GetFolder finds a bitwarden folder by name and returns it or nil and error if it cannot
func GetFolder(folderName string) (*BwFolder, error) {
folders, err := ListAllFolders()
if err != nil {
return nil, err
}
for _, folder := range folders {
if folder.Name == folderName {
return &folder, nil
Expand Down
6 changes: 6 additions & 0 deletions getitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bitwardenwrapper
import (
"encoding/json"
"fmt"
"path/filepath"
)

// GetItem finds a bitwarden item by name within a given bitwarden folder and returns it or nil and error if it cannot
Expand Down Expand Up @@ -33,3 +34,8 @@ func GetItemFromFolder(itemName string, folderName string) (*BwItem, error) {
}
return item, nil
}

func GetItemByPath(path string) (*BwItem, error) {
folder, itemName := filepath.Split(path)
return GetItemFromFolder(folder, itemName)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/crumbhole/bitwardenwrapper

go 1.15
go 1.20

0 comments on commit 228a231

Please sign in to comment.