-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupload_env_to_vault.py
More file actions
36 lines (28 loc) · 931 Bytes
/
upload_env_to_vault.py
File metadata and controls
36 lines (28 loc) · 931 Bytes
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
# Python script to transfer key=value pairs from local env file to vault while onboarding
import sys, os
for i in sys.argv:
print(i)
env_file = sys.argv[1]
vault_path = sys.argv[2]
# If vault path does not exists make a one
# This rewrites all the key-value pairs if a vault path exists
os.system(f'vault kv put -mount=kv {vault_path} TEST_ENV=TEST_ENV')
with open(env_file, 'r') as f:
lines = f.readlines()
for l in lines:
try:
key, value = l.split('=')
except ValueError:
print(l)
else:
command = f'vault kv patch -mount=kv {vault_path} {key}={value}'
os.system(command)
with open(env_file, 'r') as f:
lines = f.readlines()
for l in lines:
try:
key, value = l.split('=')
except ValueError:
print(l)
else:
print(f'{key}={{{{ credentials.{key} }}}}')