Skip to content

Commit

Permalink
More descriptive comments for keeper package; bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
l50 committed Jun 29, 2023
1 parent 56cc01f commit bff84d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
14 changes: 12 additions & 2 deletions pwmgr/keeper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ Keeper record to retrieve.

**Returns:**

pwmgr.Record: The retrieved Keeper record.
pwmgr.Record: The retrieved Keeper record. This contains the following attributes:
- UID: The unique identifier of the record.
- Title: The title of the record.
- Username: The username associated with the record.
- Password: The password of the record.
- URL: The URL associated with the record.
- TOTP: The one-time password (if any) associated with the record.
- Note: Any additional notes associated with the record.

error: An error if the Keeper record cannot be retrieved.

---
Expand All @@ -105,7 +113,9 @@ searchTerm: A string representing the term to search for in the Keeper records.
**Returns:**

string: The unique identifier (UID) of the first Keeper record
that matches the search term.
that matches the search term. If multiple records match the
search term, only the UID of the first record is returned.

error: An error if the Keeper records cannot be searched or if
the search term does not match any records.

Expand Down
20 changes: 13 additions & 7 deletions pwmgr/keeper/keeperutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import (
"github.com/l50/goutils/v2/sys"
)

// Keeper represents a password manager that uses Keeper Security.
//
// **Attributes:**
//
// Config: KeeperConfig object containing information about the Keeper vault.
// Keeper represents a connection with the Keeper password manager.
type Keeper struct{}

// configPath returns the path of the keeper config file.
Expand Down Expand Up @@ -132,7 +128,15 @@ func (k Keeper) AddRecord(fields map[string]string) error {
//
// **Returns:**
//
// pwmgr.Record: The retrieved Keeper record.
// pwmgr.Record: The retrieved Keeper record. This contains the following attributes:
// - UID: The unique identifier of the record.
// - Title: The title of the record.
// - Username: The username associated with the record.
// - Password: The password of the record.
// - URL: The URL associated with the record.
// - TOTP: The one-time password (if any) associated with the record.
// - Note: Any additional notes associated with the record.
//
// error: An error if the Keeper record cannot be retrieved.
func (k Keeper) RetrieveRecord(uid string) (pwmgr.Record, error) {
var record pwmgr.Record
Expand Down Expand Up @@ -190,7 +194,9 @@ func (k Keeper) RetrieveRecord(uid string) (pwmgr.Record, error) {
// **Returns:**
//
// string: The unique identifier (UID) of the first Keeper record
// that matches the search term.
// that matches the search term. If multiple records match the
// search term, only the UID of the first record is returned.
//
// error: An error if the Keeper records cannot be searched or if
// the search term does not match any records.
func (k Keeper) SearchRecords(searchTerm string) (string, error) {
Expand Down
8 changes: 4 additions & 4 deletions pwmgr/keeper/keeperutils_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
"github.com/l50/goutils/v2/pwmgr/keeper"
)

func ExampleCommanderInstalled() {
func ExampleKeeper_CommanderInstalled() {
k := keeper.Keeper{}
if !k.CommanderInstalled() {
log.Fatal("keeper commander is not installed.")
}
}

func ExampleLoggedIn() {
func ExampleKeeper_LoggedIn() {
k := keeper.Keeper{}
if !k.LoggedIn() {
log.Fatal("not logged into keeper vault.")
}
}

func ExampleRetrieveRecord() {
func ExampleKeeper_RetrieveRecord() {
k := keeper.Keeper{}
record, err := k.RetrieveRecord("1234abcd")
if err != nil {
Expand All @@ -29,7 +29,7 @@ func ExampleRetrieveRecord() {
log.Printf("retrieved record: %+v\n", record)
}

func ExampleSearchRecords() {
func ExampleKeeper_SearchRecords() {
k := keeper.Keeper{}
uid, err := k.SearchRecords("search term")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pwmgr/keeper/keeperutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"os"
"testing"

"github.com/l50/goutils/v2/pwmgr"
"github.com/l50/goutils/v2/pwmgr/keeper"
"github.com/stretchr/testify/assert"
)

var testRecord keeper.Record
var note keeper.Record
var testRecord pwmgr.Record
var note pwmgr.Record

func init() {
testRecord.UID = "hfLu-IbhTTVhE3DjWsS-Eg"
Expand Down

0 comments on commit bff84d2

Please sign in to comment.