Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions build/generate-service-account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ if [ -z "$MONGODB_ATLAS_ORG_ID" ]; then
exit 1
fi
if [ -z "$MONGODB_ATLAS_OPS_MANAGER_URL" ]; then
echo "MONGODB_ATLAS_ORG_ID env var is not set"
echo "MONGODB_ATLAS_OPS_MANAGER_URL env var is not set"
exit 1
fi

output=$(
curl --user "${MONGODB_ATLAS_PUBLIC_API_KEY}:${MONGODB_ATLAS_PRIVATE_API_KEY}" \
if ! output=$(
curl --silent --show-error --fail-with-body \
--user "${MONGODB_ATLAS_PUBLIC_API_KEY}:${MONGODB_ATLAS_PRIVATE_API_KEY}" \
--digest \
--header "Accept: application/vnd.atlas.2025-03-12+json" \
--header "Content-Type: application/json" \
Expand All @@ -45,10 +46,17 @@ output=$(
],
"secretExpiresAfterHours": 8
}'
)
); then
echo "Failed to create service account. Response:"
echo "$output"
exit 1
fi

client_id=$(echo "$output" | jq -r '.clientId')
client_secret=$(echo "$output" | jq -r '.secrets[0].secret')
if [ -n "$client_secret" ] && [ "$client_secret" != "null" ]; then
echo "::add-mask::$client_secret"
fi

if [ -z "$client_id" ] || [ "$client_id" = "null" ] || [ -z "$client_secret" ] || [ "$client_secret" = "null" ]; then
echo "Failed to create service account. Response:"
Expand Down
20 changes: 11 additions & 9 deletions build/terminate-service-account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@ if [ -z "$MONGODB_ATLAS_ORG_ID" ]; then
echo "MONGODB_ATLAS_ORG_ID env var is not set"
exit 1
fi
if [ -z "$MONGODB_ATLAS_OPS_MANAGER_URL" ]; then
echo "MONGODB_ATLAS_OPS_MANAGER_URL env var is not set"
exit 1
fi
if [ -z "$CLIENT_ID" ]; then
echo "CLIENT_ID env var is not set"
exit 1
fi

output=$(
curl --user "${MONGODB_ATLAS_PUBLIC_API_KEY}:${MONGODB_ATLAS_PRIVATE_API_KEY}" \
if ! output=$(
curl --silent --show-error --fail-with-body \
--user "${MONGODB_ATLAS_PUBLIC_API_KEY}:${MONGODB_ATLAS_PRIVATE_API_KEY}" \
--digest \
--header "Accept: application/vnd.atlas.2025-03-12+json" \
--header "Content-Type: application/json" \
-X DELETE "https://cloud.mongodb.com/api/atlas/v2/orgs/${MONGODB_ATLAS_ORG_ID}/serviceAccounts/${CLIENT_ID}"
)
error_code=$(echo "$output" | jq -r '.error')

if [ "$error_code" -ge 300 ]; then
-X DELETE "${MONGODB_ATLAS_OPS_MANAGER_URL}api/atlas/v2/orgs/${MONGODB_ATLAS_ORG_ID}/serviceAccounts/${CLIENT_ID}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, I'm suprised that this only started failing lately cuz this bug was implemented (by me oops) nearly a year ago.

Any hypothesis on why this cropped up now?
I thought it might have been that we hit a max number of SAs for the dev org but it doesn't look to be the case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has happened before we just never paid attention

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. We should've been blocked on merging PRs since the bug was introduced.
Either way, just curious :)

); then
echo "Failed to delete service account with Client ID $CLIENT_ID. Response:"
echo "$output"
exit 1
else
echo "Service account with Client ID $CLIENT_ID has been deleted successfully."
fi

echo "Service account with Client ID $CLIENT_ID has been deleted successfully."
Loading