-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgerrit_monitoring.py
executable file
·147 lines (118 loc) · 3.71 KB
/
gerrit_monitoring.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import os.path
from cfgmgr import get_config_manager
from subcommands import encrypt, install, jwt, uninstall
def _run_encrypt(args):
encrypt(
args.enc_method,
os.path.abspath(args.config),
pgp_identifier=args.pgp_identifier,
vault_address=args.vault_address,
engine=args.vault_engine,
key=args.vault_key,
)
def _run_install(args):
install(
get_config_manager(os.path.abspath(args.config)),
os.path.abspath(args.output_dir),
args.dryrun,
args.update_repo,
)
def _run_jwt(args):
jwt(get_config_manager(os.path.abspath(args.config)))
def _run_uninstall(args):
uninstall(get_config_manager(args.config))
def main():
"""Argument parser for the gerrit monitoring installer."""
parser = argparse.ArgumentParser()
parser.add_argument(
"-c",
"--config",
help="Path to configuration file.",
dest="config",
action="store",
required=True,
)
subparsers = parser.add_subparsers()
parser_install = subparsers.add_parser("install", help="Install Gerrit monitoring")
parser_install.set_defaults(func=_run_install)
parser_install.add_argument(
"-o",
"--output",
help="Output directory for generated files.",
dest="output_dir",
action="store",
default="./dist",
)
parser_install.add_argument(
"-d",
"--dryrun",
help="Only generate files, but do not install them.",
dest="dryrun",
action="store_true",
)
parser.add_argument(
"--update-repo",
help="Update the helm repositories.",
dest="update_repo",
action="store_true",
)
parser_uninstall = subparsers.add_parser(
"uninstall", help="Uninstall Gerrit monitoring"
)
parser_uninstall.set_defaults(func=_run_uninstall)
parser_encrypt = subparsers.add_parser("encrypt", help="Encrypt config")
parser_encrypt.set_defaults(func=_run_encrypt)
parser_encrypt.add_argument(
"-m",
"--method",
help="Encryption method used by SOPS.",
dest="enc_method",
action="store",
choices=["pgp", "vault"],
required=True,
)
parser_encrypt.add_argument(
"--pgp-id",
help="PGP fingerpint or associated email.",
dest="pgp_identifier",
action="store",
)
parser_encrypt.add_argument(
"--vault-url",
help="URL of vault instance (incl. protocol).",
dest="vault_address",
action="store",
)
parser_encrypt.add_argument(
"--vault-engine",
help="Secret engine managing the key used for encryption.",
dest="vault_engine",
action="store",
)
parser_encrypt.add_argument(
"--vault-key",
help="Name of the key used for encryption.",
dest="vault_key",
action="store",
)
parser_jwt = subparsers.add_parser("jwt", help="Create JWT token")
parser_jwt.set_defaults(func=_run_jwt)
args = parser.parse_args()
args.func(args)
if __name__ == "__main__":
main()