Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
fix the jsonpath item for getting fields
Browse files Browse the repository at this point in the history
  • Loading branch information
blacs30 committed Aug 31, 2023
1 parent a9d20b5 commit a672224
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/bitwarden.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,18 @@ func runGetItem() {
isDecryptSecretFromJsonFailed = true
}
// replace starting bracket with dot as gsub uses a dot for the first group in an array
jsonPath = strings.Replace(jsonPath, "[", ".", -1)
jsonPath = strings.Replace(jsonPath, "]", "", -1)
gjsonPath := strings.Replace(jsonPath, "[", ".", -1)

Check failure on line 254 in src/bitwarden.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to gjsonPath (ineffassign)
gjsonPath = strings.Replace(jsonPath, "]", "", -1)
if totp {
jsonPath = "login.totp"
gjsonPath = "login.totp"
}

var value gjson.Result
if bwData.ActiveUserId != "" {
// different location for version 1.21.1 and above
value = gjson.Get(string(data), fmt.Sprintf("%s.data.ciphers.encrypted.%s.%s", bwData.UserId, id, jsonPath))
value = gjson.Get(string(data), fmt.Sprintf("%s.data.ciphers.encrypted.%s.%s", bwData.UserId, id, gjsonPath))
} else {
value = gjson.Get(string(data), fmt.Sprintf("ciphers_%s.%s.%s", bwData.UserId, id, jsonPath))
value = gjson.Get(string(data), fmt.Sprintf("ciphers_%s.%s.%s", bwData.UserId, id, gjsonPath))
}
if value.Exists() {
encryptedSecret = value.String()
Expand Down Expand Up @@ -322,15 +322,18 @@ func runGetItem() {
} else {
receivedItem = ""
}

if jsonPath != "" && !totp {
log.Println("Sent jsonPath is", jsonPath)
log.Println("Received jsonPath for item is", jsonPath)
// jsonpath operation to get only required part of the item
singleString := strings.Join(result, " ")

var item interface{}
err = json.Unmarshal([]byte(singleString), &item)
if err != nil {
log.Println(err)
}

res, err := jsonpath.JsonPathLookup(item, fmt.Sprintf("$.%s", jsonPath))
if err != nil {
log.Println(err)
Expand Down

0 comments on commit a672224

Please sign in to comment.