SERVER-113773 Regenerate copybara access token after finishing the dry run (#43858)

GitOrigin-RevId: 9ac7cb334a9d72a30fb32d2438c69eb5d5215c14
This commit is contained in:
Zack Winter 2025-11-11 18:26:31 -08:00 committed by MongoDB Bot
parent 0a3b9f04bb
commit 82255ad39e
1 changed files with 42 additions and 0 deletions

View File

@ -650,6 +650,48 @@ def main():
error_message = f"Copybara failed with error: {err.returncode}"
handle_failure(expansions, error_message, err.output)
# Write newly generated tokens to the config file to make sure
# the token isn't expired by the time the dry-run finishes
token_mongodb_mongo = get_installation_access_token(
expansions["app_id_copybara_syncer"],
expansions["private_key_copybara_syncer"],
expansions["installation_id_copybara_syncer"],
)
token_10gen_mongo = get_installation_access_token(
expansions["app_id_copybara_syncer_10gen"],
expansions["private_key_copybara_syncer_10gen"],
expansions["installation_id_copybara_syncer_10gen"],
)
REDACTED_STRINGS += [token_mongodb_mongo, token_10gen_mongo]
tokens_map = {
"mongodb/mongo.git": token_mongodb_mongo,
"10gen/mongo.git": token_10gen_mongo,
"10gen/mongo-copybara.git": token_10gen_mongo,
}
with fileinput.FileInput(config_file, inplace=True) as file:
for line in file:
token = None
for repo, value in tokens_map.items():
if repo in line:
token = value
break
if token:
print(
re.sub(
r"https://x-access-token:.*@github.com",
f"https://x-access-token:{token}@github.com",
line,
),
end="",
)
else:
print(line, end="")
# dry run successful, time to push
try:
run_command(" ".join(docker_cmd + test_args))