Created
September 13, 2018 20:21
-
-
Save sivel/2513c72d83c5b23a77c6fb400e9739cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/ansible/parsing/ajson.py b/lib/ansible/parsing/ajson.py | |
index 7444a9f403..36c693dead 100644 | |
--- a/lib/ansible/parsing/ajson.py | |
+++ b/lib/ansible/parsing/ajson.py | |
@@ -20,33 +20,27 @@ class AnsibleJSONDecoder(json.JSONDecoder): | |
_vaults = {} | |
+ def __init__(self, *args, **kwargs): | |
+ kwargs['object_hook'] = self.object_hook | |
+ super(AnsibleJSONDecoder, self).__init__(*args, **kwargs) | |
+ | |
@classmethod | |
def set_secrets(cls, secrets): | |
cls._vaults['default'] = VaultLib(secrets=secrets) | |
- def _decode_map(self, value): | |
- | |
- if value.get('__ansible_unsafe', False): | |
- value = wrap_var(value.get('__ansible_unsafe')) | |
- elif value.get('__ansible_vault', False): | |
- value = AnsibleVaultEncryptedUnicode(value.get('__ansible_vault')) | |
- if self._vaults: | |
- value.vault = self._vaults['default'] | |
- else: | |
- for k in value: | |
- if isinstance(value[k], Mapping): | |
- value[k] = self._decode_map(value[k]) | |
- return value | |
+ def object_hook(self, pairs): | |
+ for key in pairs: | |
+ value = pairs[key] | |
- def decode(self, obj): | |
- ''' use basic json decoding except for specific ansible objects unsafe and vault ''' | |
+ if key == '__ansible_vault': | |
+ value = AnsibleVaultEncryptedUnicode(value) | |
+ if self._vaults: | |
+ value.vault = self._vaults['default'] | |
+ return value | |
+ elif key == '__ansible_unsafe': | |
+ return wrap_var(value.get('__ansible_unsafe')) | |
- value = super(AnsibleJSONDecoder, self).decode(obj) | |
- | |
- if isinstance(value, Mapping): | |
- value = self._decode_map(value) | |
- | |
- return value | |
+ return pairs | |
# TODO: find way to integrate with the encoding modules do in module_utils |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment