Skip to content
Merged
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
77 changes: 44 additions & 33 deletions tools/postman/scripts/upload-collection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,34 @@ pushd "${OPENAPI_FOLDER}"

current_collection_name="⭐ MongoDB Atlas Administration API ${current_api_revision}"

# Run curl with all the provided arguments
execute_curl() {
# Capture all arguments passed to the function
local args=("$@")

# Add verbose flag if runner debugging is enabled
if [[ "${RUNNER_DEBUG:-0}" == "1" ]]; then
args+=("-v")
echo "Debug mode enabled - using verbose curl output"
fi

# runs curl for provided args without showing sensitive info
curl "${args[@]}" 2>&1 | grep -i -v "api-key\|x-api-key\|PMAK-" || true
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ensuring that when we run the curl with -v, the API key hidden from the logs

}

echo "Fetching list of current collections"
echo "curl -o ${COLLECTIONS_LIST_FILE}
--location 'https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}'
--header 'X-API-Key: **********'"
curl --show-error --fail --silent -o "${COLLECTIONS_LIST_FILE}" \
execute_curl --show-error --fail --silent -o "${COLLECTIONS_LIST_FILE}" \
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
--header "X-API-Key: ${POSTMAN_API_KEY}"

collection_exists=$(jq '.collections | any(.name=="'"${current_collection_name}"'")' "${COLLECTIONS_LIST_FILE}")
# Print the collections list to the console
echo "Current collections in the workspace:"
jq '.collections[] | {id, name}' "${COLLECTIONS_LIST_FILE}"

collection_exists=$(jq '.collections | any(.name=="'"${current_collection_name}"'")' "${COLLECTIONS_LIST_FILE}")

if [ "$collection_exists" = "false" ]; then
# Check if a collection with a star icon already exists
Expand All @@ -46,14 +65,16 @@ if [ "$collection_exists" = "false" ]; then

echo "Removing star icon from the previous collection name"
echo "curl -o ${COLLECTIONS_LIST_FILE}
--location 'https://api.getpostman.com/collections/${previous_star_collection_id}'
--header 'X-API-Key: **********'
--data \"{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}\""
curl --show-error --fail --silent --request PATCH \
--location "https://api.getpostman.com/collections/${previous_star_collection_id}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}"
--location 'https://api.getpostman.com/collections/${previous_star_collection_id}'
--header 'X-API-Key: **********'
--data '{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}'"

execute_curl --show-error --fail --silent --request PATCH \
--location "https://api.getpostman.com/collections/${previous_star_collection_id}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}"

fi

# Create new collection
Expand All @@ -63,17 +84,12 @@ if [ "$collection_exists" = "false" ]; then
--header 'Content-Type: application/json'
--header 'X-API-Key: **********'
--data ${collection_transformed_path}"
curl --show-error \
--retry 7 \
--retry-delay 30 \
--retry-max-time 1200 \
--retry-all-errors \
--fail \
--silent \
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "@${collection_transformed_path}" \
execute_curl --show-error --retry 3 --retry-delay 30 --retry-max-time 1200 \
--retry-all-errors --fail --silent \
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "@${collection_transformed_path}"

else
# Find collection ID and update collection
Expand All @@ -86,18 +102,13 @@ else
--header 'X-API-Key: **********'
--data ${collection_transformed_path}"

curl --show-error \
--retry 7 \
--retry-delay 30 \
--retry-max-time 1200 \
--retry-all-errors \
--fail \
--silent \
--request PUT \
--location "https://api.getpostman.com/collections/${collection_id}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "@${collection_transformed_path}"
execute_curl --request PUT --retry 3 --retry-delay 30 --retry-max-time 1200 \
--show-error --fail --silent \
--location "https://api.getpostman.com/collections/${collection_id}" \
--header "Content-Type: application/json" \
--header "X-API-Key: ${POSTMAN_API_KEY}" \
--data "@${collection_transformed_path}"

fi

popd -0