bundlewrap/libs/demagify.py

22 lines
882 B
Python

import bwpass
def demagify(something, vault):
if isinstance(something, str):
if something.startswith('!bwpass:'):
return bwpass.password(something[8:])
elif something.startswith('!bwpass_attr:'):
identifier, attribute = something[13:].split(':', 1)
return bwpass.attr(identifier, attribute)
elif something.startswith('!decrypt:'):
return vault.decrypt(something[9:])
return something
elif isinstance(something, dict):
return {k:demagify(v, vault) for k,v in something.items()}
elif isinstance(something, list):
return [demagify(i, vault) for i in something]
elif isinstance(something, set):
return {demagify(i, vault) for i in something}
elif isinstance(something, tuple):
return tuple([demagify(i, vault) for i in something])
return something