mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Merge pull request #3060 from ryanpetrello/fix-3043
properly handle AnsibleVaultEncryptedUnicode objects in the callback
This commit is contained in:
commit
c8b2ca7fed
@ -2,6 +2,7 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
# Python
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
@ -12,10 +13,31 @@ from django.conf import settings
|
||||
|
||||
# Kombu
|
||||
from kombu import Connection, Exchange, Producer
|
||||
from kombu.serialization import registry
|
||||
|
||||
__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):
|
||||
|
||||
def __init__(self):
|
||||
@ -41,7 +63,7 @@ class CallbackQueueDispatcher(object):
|
||||
|
||||
producer = Producer(self.connection)
|
||||
producer.publish(obj,
|
||||
serializer='json',
|
||||
serializer='json-ansible',
|
||||
compression='bzip2',
|
||||
exchange=self.exchange,
|
||||
declare=[self.exchange],
|
||||
|
Loading…
Reference in New Issue
Block a user