Skip to content

Commit

Permalink
Fix onepassword lookup plugin and onepassword_facts module when a fie…
Browse files Browse the repository at this point in the history
…ld has no name. (ansible#58308)

* Fix onepassword lookup plugin crashing on fields with no 'name' or 't' property.

* Fix onepassword_facts module crashing on fields with no 'name' or 't' property.

* Add unit test for onepassword lookup plugin failing on entries without a name.

* Add changelog fragment for onepassword lookup plugin and onepassword_facts module fixes on fields without a name.
  • Loading branch information
oscherler authored and samdoran committed Jun 28, 2019
1 parent 1a5ae36 commit 7ed7d37
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- onepassword - fix onepassword lookup plugin failing on fields without a name or t property (https://github.com/ansible/ansible/pull/58308)
- onepassword_facts - fix onepassword_facts module failing on fields without a name or t property (https://github.com/ansible/ansible/pull/58308)
4 changes: 2 additions & 2 deletions lib/ansible/modules/identity/onepassword_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _parse_field(self, data_json, item_id, field_name, section_title=None):
else:
if section_title is None:
for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
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
Expand All @@ -216,7 +216,7 @@ def _parse_field(self, data_json, item_id, field_name, section_title=None):
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():
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.
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/lookup/onepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ def _parse_field(self, data_json, field_name, section_title=None):
data = json.loads(data_json)
if section_title is None:
for field_data in data['details'].get('fields', []):
if field_data.get('name').lower() == field_name.lower():
if field_data.get('name', '').lower() == field_name.lower():
return field_data.get('value', '')
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():
if field_data.get('t', '').lower() == field_name.lower():
return field_data.get('v', '')
return ''

Expand Down
7 changes: 4 additions & 3 deletions test/units/plugins/lookup/test_onepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
{
'name': 'password',
'value': 'vauxhall'
}
},
{},
]
}
}
Expand All @@ -105,8 +106,8 @@

def get_mock_query_generator(require_field=None):
def _process_field(field, section_title=None):
field_name = field.get('name', field.get('t'))
field_value = field.get('value', field.get('v'))
field_name = field.get('name', field.get('t', ''))
field_value = field.get('value', field.get('v', ''))

if require_field is None or field_name == require_field:
return entry, query, section_title, field_name, field_value
Expand Down

0 comments on commit 7ed7d37

Please sign in to comment.