Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #7061/e75dc746 backport][stable-6] bitwarden lookup fix get_field #7089

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Aug 11, 2023

This is a backport of PR #7061 as merged into main (e75dc74).

SUMMARY

A bitwarden record without any custom fields will throw a KeyError when you try to search with field='notes'. The code here tries to open match['fields'] without first checking if the key fields exists in match.
It turns out that with the current logic you can't get the notes field. It's either the login fields or custom fields. The new logic looks for your key in custom fields, then in login fields, then in the general fields for that record.

Fixes #6617

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

bitwarden

ADDITIONAL INFORMATION

Here's the structure of a bitwarden record json object:

{
    "collectionIds": null,
    "creationDate": null,
    "deletedDate": null,
    "favorite": false,
    "fields": [
        {
            "linkedId": null,
            "name": "custom-field1",
            "type": null,
            "value": null
        }
        {
            "linkedId": null,
            "name": "custom-field2",
            "type": null,
            "value": null
        }
    ],
    "folderId": null,
    "id": null,
    "login": {
        "password": null,
        "passwordRevisionDate": null,
        "totp": null,
        "username": null
    },
    "name": null,
    "notes": null,
    "object": null,
    "organizationId": null,
    "passwordHistory": null,
    "reprompt": null,
    "revisionDate": null,
    "type": null,
}
BEFORE AND AFTER
- name: print bitwarden value
  debug:
    msg: "{{ lookup('community.general.bitwarden', 'record-name', field='notes') }}"

before:

TASK [hostname : print bitwarden value] ******************************************************************************
fatal: [hostname]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'community.general.bitwarden'. Error was a <class 'KeyError'>, original message: 'fields'. 'fields'"}

after:

ok: [hostname] => {
    "msg": [
        "these are notes"
    ]
}

* bitwarden lookup rewrite `get_field`

* add changelog fragment

* PEP8 add newline

* Update changelogs/fragments/7061-fix-bitwarden-get_field.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/bitwarden.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/bitwarden.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/bitwarden.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Simon <simonleary@umass.edu>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit e75dc74)
@ansibullbot
Copy link
Collaborator

cc @lungj
click here for bot help

@ansibullbot ansibullbot added backport bug This issue/PR relates to a bug lookup lookup plugin new_contributor Help guide this first time contributor plugins plugin (any type) labels Aug 11, 2023
@felixfontein felixfontein merged commit bcfcdd1 into stable-6 Aug 11, 2023
@felixfontein felixfontein deleted the patchback/backports/stable-6/e75dc74613641ad278a4a1272289dad9179b9b49/pr-7061 branch August 11, 2023 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug lookup lookup plugin new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants