-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathcandle_wrapper.py
36 lines (31 loc) · 1.37 KB
/
candle_wrapper.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
import hashlib
import subprocess
import sys
import uuid
# Wrapper script to substitute GENERATE_UPGRADE_CODE as starlark can't create hashes
candle_args = sys.argv[1:]
generate_code_replace_text = "GENERATE_UPGRADE_CODE"
# If our args contain GENERATE_UPGRADE_CODE we need to generate it, otherwise we can just call candle
if any(generate_code_replace_text in x for x in candle_args):
# We must regenerate upgrade codes for each major release. These upgrade codes must also be
# different for each MSI edition. To generate these we must be passed MongoDBMajorVersion and Edition
# These are are things like -dMongoDBMajorVersion=8.1 and -dEdition=SSL
for i, arg in enumerate(candle_args):
if generate_code_replace_text in arg:
upgrade_code_index = i
if "MongoDBMajorVersion" in arg:
major_version = arg.split("=")[1]
if "Edition" in arg:
msi_edition = arg.split("=")[1]
# Create uuid for upgrade code
m = hashlib.sha256()
hash_str = "{}_{}".format(major_version, msi_edition)
m.update(hash_str.encode())
upgrade_code = str(uuid.UUID(bytes=m.digest()[0:16]))
candle_args[upgrade_code_index] = candle_args[upgrade_code_index].replace(
generate_code_replace_text, upgrade_code
)
# run candle with updated args
subprocess.call(candle_args)
else:
subprocess.call(candle_args)