1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix an issue retrieving some types of 1Password items. (#47213)

* Some types of 1Password items have a 'password' field alongside the 'fields' attribute, not inside it, so we need to search there as well.

* Add changelog fragement for onepassword_facts PR #47213.
This commit is contained in:
Ryan Conway 2018-12-05 16:49:26 +00:00 committed by Sam Doran
parent dd004321d4
commit aacd22acc6
2 changed files with 23 additions and 13 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- onepassword_facts - Fix an issue looking up some 1Password items which have a 'password' attribute alongside the 'fields' attribute, not inside it.

View file

@ -192,20 +192,28 @@ class OnePasswordFacts(object):
else: else:
# This is not a document, let's try to find the requested field # This is not a document, let's try to find the requested field
if section_title is None:
for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
return {field_name: field_data.get('value', '')}
# Not found it yet, so now lets see if there are any sections defined # Some types of 1Password items have a 'password' field directly alongside the 'fields' attribute,
# and search through those for the field. If a section was given, we skip # not inside it, so we need to check there first.
# any non-matching sections, otherwise we search them all until we find the field. if (field_name in data['details']):
for section_data in data['details'].get('sections', []): return {field_name: data['details'][field_name]}
if section_title is not None and section_title.lower() != section_data['title'].lower():
continue # Otherwise we continue looking inside the 'fields' attribute for the specified field.
for field_data in section_data.get('fields', []): else:
if field_data.get('t').lower() == field_name.lower(): if section_title is None:
return {field_name: field_data.get('v', '')} for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
return {field_name: field_data.get('value', '')}
# Not found it yet, so now lets see if there are any sections defined
# and search through those for the field. If a section was given, we skip
# any non-matching sections, otherwise we search them all until we find the field.
for section_data in data['details'].get('sections', []):
if section_title is not None and section_title.lower() != section_data['title'].lower():
continue
for field_data in section_data.get('fields', []):
if field_data.get('t').lower() == field_name.lower():
return {field_name: field_data.get('v', '')}
# We will get here if the field could not be found in any section and the item wasn't a document to be downloaded. # We will get here if the field could not be found in any section and the item wasn't a document to be downloaded.
optional_section_title = '' if section_title is None else " in the section '%s'" % section_title optional_section_title = '' if section_title is None else " in the section '%s'" % section_title