mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
base64 functions must be given byte strings
The base64 stdlib functions require byte strings. So we have to transform the strings into bytes before handing to the stdlib and then transform them back into text before handing back to ansible. Fixes #22873
This commit is contained in:
parent
d0712b1ec7
commit
589e217278
1 changed files with 10 additions and 2 deletions
|
@ -459,6 +459,14 @@ def do_groupby(environment, value, attribute):
|
|||
return [tuple(t) for t in _do_groupby(environment, value, attribute)]
|
||||
|
||||
|
||||
def b64encode(string):
|
||||
return to_text(base64.b64encode(to_bytes(string, errors='surrogate_then_strict')))
|
||||
|
||||
|
||||
def b64decode(string):
|
||||
return to_text(base64.b64decode(to_bytes(string, errors='surrogate_then_strict')))
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
''' Ansible core jinja2 filters '''
|
||||
|
||||
|
@ -468,8 +476,8 @@ class FilterModule(object):
|
|||
'groupby': do_groupby,
|
||||
|
||||
# base 64
|
||||
'b64decode': partial(unicode_wrap, base64.b64decode),
|
||||
'b64encode': partial(unicode_wrap, base64.b64encode),
|
||||
'b64decode': b64decode,
|
||||
'b64encode': b64encode,
|
||||
|
||||
# uuid
|
||||
'to_uuid': to_uuid,
|
||||
|
|
Loading…
Reference in a new issue