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

Fix py3 decoding issues in cyberarkpassword.py #59500

Merged
merged 4 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- cyberarkpassword - fix result decoding issues with Python 3 (https://github.com/ansible/ansible/issues/52625)
21 changes: 11 additions & 10 deletions lib/ansible/plugins/lookup/cyberarkpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.parsing.splitter import parse_kv
from ansible.module_utils._text import to_text
from ansible.module_utils._text import to_bytes, to_text, to_native
from ansible.utils.display import Display

display = Display()
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, appid=None, query=None, output=None, **kwargs):
# output 'keys' will be in lowercase.
self.output = self.output.lower()

self.delimiter = "@#@" # Known delimiter to split output results
self.b_delimiter = b"@#@" # Known delimiter to split output results

def get(self):

Expand All @@ -124,29 +124,30 @@ def get(self):
'-d', self.delimiter]
all_parms.extend(self.extra_parms)

credential = ""
tmp_output, tmp_error = Popen(all_parms, stdout=PIPE, stderr=PIPE, stdin=PIPE).communicate()
b_credential = b""
b_all_params = [to_bytes(v) for v in all_parms]
tmp_output, tmp_error = Popen(b_all_params, stdout=PIPE, stderr=PIPE, stdin=PIPE).communicate()

if tmp_output:
credential = tmp_output
b_credential = to_bytes(tmp_output)

if tmp_error:
raise AnsibleError("ERROR => %s " % (tmp_error))

if credential and credential.endswith(b'\n'):
credential = credential[:-1]
if b_credential and b_credential.endswith(b'\n'):
b_credential = b_credential[:-1]

output_names = self.output.split(",")
output_values = credential.split(self.delimiter)
output_values = b_credential.split(self.b_delimiter)

for i in range(len(output_names)):
if output_names[i].startswith("passprops."):
if "passprops" not in result_dict:
result_dict["passprops"] = {}
output_prop_name = output_names[i][10:]
result_dict["passprops"][output_prop_name] = output_values[i]
result_dict["passprops"][output_prop_name] = to_native(output_values[i])
mback2k marked this conversation as resolved.
Show resolved Hide resolved
else:
result_dict[output_names[i]] = output_values[i]
result_dict[output_names[i]] = to_native(output_values[i])

except subprocess.CalledProcessError as e:
raise AnsibleError(e.output)
Expand Down