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

bitwarden lookup fix get_field #7061

Merged
merged 7 commits into from
Aug 11, 2023

Conversation

simonLeary42
Copy link
Contributor

@simonLeary42 simonLeary42 commented Aug 3, 2023

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"
    ]
}

@simonLeary42
Copy link
Contributor Author

when a bitwarden record has no custom fields, fields is not an empty list, it doesn't exist at all.

{
    "collectionIds": null,
    "creationDate": null,
    "deletedDate": null,
    "favorite": false,
    "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,
}

@ansibullbot
Copy link
Collaborator

cc @lungj
click here for bot help

@ansibullbot ansibullbot added 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 3, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-6 labels Aug 4, 2023
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

changelogs/fragments/7061-fix-bitwarden-get_field.yml Outdated Show resolved Hide resolved
plugins/lookup/bitwarden.py Outdated Show resolved Hide resolved
plugins/lookup/bitwarden.py Outdated Show resolved Hide resolved
plugins/lookup/bitwarden.py Outdated Show resolved Hide resolved
simonLeary42 and others added 4 commits August 4, 2023 14:18
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
@simonLeary42
Copy link
Contributor Author

suggestions committed

@simonLeary42
Copy link
Contributor Author

#6617

@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this in ~a week.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Aug 11, 2023
@felixfontein felixfontein merged commit e75dc74 into ansible-collections:main Aug 11, 2023
@patchback
Copy link

patchback bot commented Aug 11, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/e75dc74613641ad278a4a1272289dad9179b9b49/pr-7061

Backported as #7089

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Aug 11, 2023
* 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)
@patchback
Copy link

patchback bot commented Aug 11, 2023

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/e75dc74613641ad278a4a1272289dad9179b9b49/pr-7061

Backported as #7090

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Aug 11, 2023
* 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)
@felixfontein
Copy link
Collaborator

@simonLeary42 thanks for your contribution!

felixfontein pushed a commit that referenced this pull request Aug 11, 2023
…d` (#7090)

bitwarden lookup fix `get_field` (#7061)

* 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)

Co-authored-by: simonLeary42 <71396965+simonLeary42@users.noreply.github.com>
felixfontein pushed a commit that referenced this pull request Aug 11, 2023
…d` (#7089)

bitwarden lookup fix `get_field` (#7061)

* 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)

Co-authored-by: simonLeary42 <71396965+simonLeary42@users.noreply.github.com>
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 has_issue 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.

lookup bitwarden field=notes resulting in KeyError
3 participants