-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfi.py
96 lines (78 loc) · 2.76 KB
/
confi.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import argparse
"""
Cli Options:
--backend:
- ssm
- keyvault
- file
-f (required if backend file selected):
- Backend file path
- File should be in yaml
--temp-dir:
- Templates directory
- Required for windows and optional for linux
- default template directory for linux is /opt/confd
--config(optional if role based access provided):
- Configuration file for backends
- Should be in yaml
"""
import utils.utils as util
import backends.file.file as fileback
import backends.ssm.ssm as ssm
import backends.keyvault.keyvault as keyvault
def main():
parser = argparse.ArgumentParser(
description="Cross platform Configuration management tool")
parser.add_argument('--backend', help="backend for configurations",
choices=["file", "ssm", "keyvault"], required=True)
parser.add_argument(
'-f', help="file path for backend if backend is set to file. File should be yaml")
parser.add_argument(
'--temp_dir', help="configurations template directory path Required for Windows and Optional for *nix")
parser.add_argument(
'--config', help="configuration file for backends 'ssm/keyvault', can be omitted if role based access provided")
args = parser.parse_args()
if args.backend == "file":
if args.f and os.path.isfile(args.f):
pass
else:
print("-f backend file required")
exit()
# Test data
template_dir = args.temp_dir
# template_dir = "D:/ASPIRE/scripts/confd/confd/Source/test"
backend = args.backend
# Checking for valid directory
if not os.path.isdir(template_dir):
print("Enter a valid directory")
exit()
# Parsing the tmpl files
template_keys = util.process_tmpl_files(template_dir)
# Parsing the toml files
toml_keys = util.process_toml_files(template_dir)
# Checking for key existance
util.check_template_and_keys_existance(
template_keys, toml_keys)
key_values = {}
keys_existance = True
key_list = []
for file in toml_keys:
key = toml_keys[file]["template"]["keys"]
key_list.extend(key)
if backend == "file":
key_values = fileback.fetch_key_values(args.f)
keys_existance = util.key_existance_checker(key_list, key_values)
elif backend == "ssm":
key_values = ssm.get_params(key_list)
# elif backend == "keyvault":
# key_values = fileback.fetch_key_values()
# keys_existance = util.key_existance_checker(key_list, key_values)
else:
return
if not keys_existance:
return
else:
util.key_value_replace(template_dir, key_values, toml_keys)
if __name__ == "__main__":
main()