mirror of https://github.com/ansible/ansible.git
[stable-2.7] Support nested JSON decoding in AnsibleJSONDecoder (#45924)
* Support nested JSON decoding in AnsibleJSONDecoder
* Add tests for vault portion of AnsibleJSONDecoder
(cherry picked from commit c0915e2
)
Co-authored-by: Matt Martz <matt@sivel.net>
pull/46289/head
parent
f360df4e10
commit
8da4113ec0
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- Ansible JSON Decoder - Switch from decode to object_hook to support nested use of __ansible_vault and __ansible_unsafe (https://github.com/ansible/ansible/pull/45514)
|
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"password": {
|
||||||
|
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||||
|
},
|
||||||
|
"bar": {
|
||||||
|
"baz": [
|
||||||
|
{
|
||||||
|
"password": {
|
||||||
|
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"foo": {
|
||||||
|
"password": {
|
||||||
|
"__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n34646264306632313333393636316562356435376162633631326264383934326565333633366238\n3863373264326461623132613931346165636465346337310a326434313830316337393263616439\n64653937313463396366633861363266633465663730303633323534363331316164623237363831\n3536333561393238370a313330316263373938326162386433313336613532653538376662306435\n3339\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2018, Matt Martz <matt@sivel.net>
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ansible.parsing.ajson import AnsibleJSONDecoder
|
||||||
|
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
|
||||||
|
|
||||||
|
|
||||||
|
def test_AnsibleJSONDecoder_vault():
|
||||||
|
with open(os.path.join(os.path.dirname(__file__), 'fixtures/ajson.json')) as f:
|
||||||
|
data = json.load(f, cls=AnsibleJSONDecoder)
|
||||||
|
|
||||||
|
assert isinstance(data['password'], AnsibleVaultEncryptedUnicode)
|
||||||
|
assert isinstance(data['bar']['baz'][0]['password'], AnsibleVaultEncryptedUnicode)
|
||||||
|
assert isinstance(data['foo']['password'], AnsibleVaultEncryptedUnicode)
|
Loading…
Reference in New Issue