1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #3060 from ryanpetrello/fix-3043

properly handle AnsibleVaultEncryptedUnicode objects in the callback
This commit is contained in:
Ryan Petrello 2018-10-12 15:42:11 -04:00 committed by GitHub
commit c8b2ca7fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
# All Rights Reserved. # All Rights Reserved.
# Python # Python
import json
import logging import logging
import os import os
@ -12,10 +13,31 @@ from django.conf import settings
# Kombu # Kombu
from kombu import Connection, Exchange, Producer from kombu import Connection, Exchange, Producer
from kombu.serialization import registry
__all__ = ['CallbackQueueDispatcher'] __all__ = ['CallbackQueueDispatcher']
# use a custom JSON serializer so we can properly handle !unsafe and !vault
# objects that may exist in events emitted by the callback plugin
# see: https://github.com/ansible/ansible/pull/38759
class AnsibleJSONEncoder(json.JSONEncoder):
def default(self, o):
if getattr(o, 'yaml_tag') == '!vault':
return o.data
return super(AnsibleJSONEncoder, self).default(o)
registry.register(
'json-ansible',
lambda obj: json.dumps(obj, cls=AnsibleJSONEncoder),
lambda obj: json.loads(obj),
content_type='application/json',
content_encoding='utf-8'
)
class CallbackQueueDispatcher(object): class CallbackQueueDispatcher(object):
def __init__(self): def __init__(self):
@ -41,7 +63,7 @@ class CallbackQueueDispatcher(object):
producer = Producer(self.connection) producer = Producer(self.connection)
producer.publish(obj, producer.publish(obj,
serializer='json', serializer='json-ansible',
compression='bzip2', compression='bzip2',
exchange=self.exchange, exchange=self.exchange,
declare=[self.exchange], declare=[self.exchange],