bundlewrap/libs/demagify.py

22 lines
881 B
Python
Raw Normal View History

2023-07-13 18:28:09 +00:00
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