Skip to content

Commit

Permalink
Merge pull request #17 from c0sco/attachment-fix
Browse files Browse the repository at this point in the history
Fix for attachments if block
  • Loading branch information
c0sco committed May 26, 2021
2 parents 4b3cb99 + 5140595 commit 126a5e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ venv.bak/

# mypy
.mypy_cache/

# IDE
.vscode
10 changes: 6 additions & 4 deletions lookup_plugins/bitwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def _run(self, args):
my_env = os.environ.copy()
if self.session != "":
my_env["BW_SESSION"] = self.session
p = Popen([self.cli_path] + args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=my_env)
p = Popen([self.cli_path] + args, stdin=PIPE,
stdout=PIPE, stderr=STDOUT, env=my_env)
out, _ = p.communicate()
out = out.decode()
rc = p.wait()
Expand All @@ -115,7 +116,7 @@ def _run(self, args):
"Make sure BW_SESSION is set properly.")
elif out.startswith("Not found."):
raise AnsibleError("Error accessing Bitwarden vault. "
"Specified item not found: {}".format(args[-1]))
"Specified item not found: {}".format(args[-1]))
else:
raise AnsibleError("Unknown failure in 'bw' command: "
"{0}".format(out))
Expand Down Expand Up @@ -143,7 +144,8 @@ def get_custom_field(self, key, field):
return next(x for x in data['fields'] if x['name'] == field)['value']

def get_attachments(self, key, itemid, output):
attachment = ['get', 'attachment', '{}'.format(key), '--output={}'.format(output), '--itemid={}'.format(itemid)]
attachment = ['get', 'attachment', '{}'.format(
key), '--output={}'.format(output), '--itemid={}'.format(itemid)]
return self._run(attachment)


Expand All @@ -170,7 +172,7 @@ def run(self, terms, variables=None, **kwargs):
values.append(bw.get_custom_field(term, field))
elif field == 'notes':
values.append(bw.get_notes(term))
if kwargs.get('attachments'):
elif kwargs.get('attachments'):
if kwargs.get('itemid'):
itemid = kwargs.get('itemid')
output = kwargs.get('output', term)
Expand Down

0 comments on commit 126a5e5

Please sign in to comment.