This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapply_vault_config.py
99 lines (83 loc) · 2.49 KB
/
apply_vault_config.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
97
98
99
import argparse
import logging
from vault_config.loader import Loader
from vault_config.config import VaultConfig
import dotenv
dotenv.load_dotenv()
CONFIGS = [
"config/global/kv2.jsonnet",
"config/global/oidc.jsonnet",
"config/global/groups.jsonnet",
"config/global/policies.jsonnet",
"config/backup-job.jsonnet",
"config/clusters/hypershift1.jsonnet",
"config/clusters/nerc-ocp-infra.jsonnet",
"config/clusters/nerc-ocp-obs.jsonnet",
"config/clusters/nerc-ocp-prod.jsonnet",
"config/clusters/nerc-ocp-test.jsonnet",
]
def parse_args():
p = argparse.ArgumentParser()
p.add_argument(
"-d",
"--data-directory",
default="data",
help="Path to directory containing secrets",
)
p.add_argument(
"--load-only",
"-l",
action="store_true",
help="Validate configuration files but do not apply configuration",
)
p.add_argument("--verbose", "-v", action="count", default=0)
p.add_argument(
"--clusters",
"-c",
action="append",
default=None,
help="Specify cluster configurations to apply",
)
p.add_argument(
"--no-resources",
action="store_const",
const=True,
default=False,
help="Do not apply resources",
)
p.add_argument(
"--no-groups",
action="store_const",
const=True,
default=False,
help="Do not apply groups",
)
p.add_argument(
"--path",
"-p",
action="append",
help="Only apply resources that match the specified glob patterns",
)
p.add_argument("configs", nargs="*", default=CONFIGS)
return p.parse_args()
def main():
args = parse_args()
loglevel = [logging.INFO, logging.DEBUG][min(args.verbose, 1)]
logging.basicConfig(level=loglevel)
loader = Loader(import_directories=["lib", args.data_directory])
vc = VaultConfig()
with loader:
# Only load files explicitly: no walking directories or wildcards.
# This prevents us from accidentally picking up files that are
# incomplete, inaccurate, or still under development.
for path in args.configs:
loader.load(path)
if not args.load_only:
vc.apply_config(
loader,
path_restrictions=args.path,
config_resources=(not args.no_resources),
config_groups=(not args.no_groups),
)
if __name__ == "__main__":
main()