nodes.py: demagify toml nodes
This commit is contained in:
parent
70bd7d295d
commit
97307fc6f3
2 changed files with 28 additions and 3 deletions
21
libs/demagify.py
Normal file
21
libs/demagify.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
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
|
10
nodes.py
10
nodes.py
|
@ -7,6 +7,13 @@ import bwpass
|
||||||
from bundlewrap.metadata import atomic
|
from bundlewrap.metadata import atomic
|
||||||
from bundlewrap.utils import error_context
|
from bundlewrap.utils import error_context
|
||||||
|
|
||||||
|
for name, data in nodes.items():
|
||||||
|
data.setdefault('metadata', {})
|
||||||
|
|
||||||
|
if 'password' in data:
|
||||||
|
data['password'] = vault.decrypt(data['password'])
|
||||||
|
data['metadata'].update(libs.demagify.demagify(data['metadata'], vault))
|
||||||
|
|
||||||
for node in Path(join(repo_path, "nodes")).rglob("*.py"):
|
for node in Path(join(repo_path, "nodes")).rglob("*.py"):
|
||||||
with error_context(filename=str(node)):
|
with error_context(filename=str(node)):
|
||||||
with open(node, 'r') as f:
|
with open(node, 'r') as f:
|
||||||
|
@ -15,6 +22,3 @@ for node in Path(join(repo_path, "nodes")).rglob("*.py"):
|
||||||
for name, data in nodes.items():
|
for name, data in nodes.items():
|
||||||
data.setdefault('hostname', '.'.join(reversed(name.split('.'))) + '.kunbox.net')
|
data.setdefault('hostname', '.'.join(reversed(name.split('.'))) + '.kunbox.net')
|
||||||
data.setdefault('metadata', {}).setdefault('hostname', '.'.join(reversed(name.split('.'))) + '.kunbox.net')
|
data.setdefault('metadata', {}).setdefault('hostname', '.'.join(reversed(name.split('.'))) + '.kunbox.net')
|
||||||
|
|
||||||
if 'password' in data:
|
|
||||||
data['password'] = vault.decrypt(data['password'])
|
|
||||||
|
|
Loading…
Reference in a new issue