-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSopsSecret
executable file
·47 lines (39 loc) · 1.14 KB
/
SopsSecret
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import os
import subprocess
import sys
import yaml
with open(sys.argv[1]) as f:
cfg = yaml.safe_load(f)
output = {
"apiVersion": "v1",
"kind": "Secret",
"metadata": cfg.get("metadata"),
"stringData": {},
}
type_ = cfg.get("type")
if type_:
output["type"] = type_
data = output["stringData"]
for filename in cfg.get("envs", []):
decrypted = subprocess.check_output(
["sops", "--input-type", "dotenv", "--decrypt", filename]
).decode()
for line in decrypted.splitlines():
if line.startswith('#') or not line.strip():
continue
k, v = line.split("=", 1)
data[k] = v
for filename in cfg.get("files", []):
if "=" in filename:
key, filename = filename.split("=", 1)
else:
key = filename
key = os.path.basename(key)
data[key] = subprocess.check_output(
["sops", "--decrypt", filename]
)
for line in cfg.get("literals", []):
k, v = line.split("=", 1)
data[k] = v
print(yaml.dump(output))