forked from toolness/hackasaurus-puppet-data
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsecrets.py
34 lines (28 loc) · 1 KB
/
secrets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import json
from distutils.dir_util import mkpath
ROOT = os.path.abspath(os.path.dirname(__file__))
def path(*x):
return os.path.join(ROOT, *x)
def load_secrets(host=None):
secrets = json.load(open(path('..', 'secrets.json')))
if host is not None:
host_filename = path('..', 'secrets.%s.json' % host)
if os.path.exists(host_filename):
secrets.update(json.load(open(host_filename)))
return secrets
def _make_manifest_text(secrets):
lines = ["class secrets {"]
for name, secret in secrets.items():
lines.append(" $%s = %s" % (name, repr(str(secret))))
lines.append("}")
return "\n".join(lines)
def build_secrets_manifest(host=None):
dirname = path("..", "modules", "secrets", "manifests")
filename = os.path.join(dirname, "init.pp")
mkpath(dirname)
secrets = load_secrets(host)
open(filename, 'w').write(_make_manifest_text(secrets))
print "generated %s" % filename
if __name__ == '__main__':
build_secrets_manifest()