Skip to content

Commit af54b0a

Browse files
committed
CLOUDP-315586: Add verbose debug logging to Postman collection upload
1 parent 065ae38 commit af54b0a

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

tools/postman/scripts/upload-collection.sh

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,34 @@ pushd "${OPENAPI_FOLDER}"
2727

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

30+
# Run curl with all the provided arguments
31+
execute_curl() {
32+
# Capture all arguments passed to the function
33+
local args=("$@")
34+
35+
# Add verbose flag if runner debugging is enabled
36+
if [[ "${RUNNER_DEBUG:-0}" == "1" ]]; then
37+
args+=("-v")
38+
echo "Debug mode enabled - using verbose curl output"
39+
fi
40+
41+
# runs curl for provided args without showing sensitive info
42+
curl "${args[@]}" 2>&1 | grep -i -v "api-key\|x-api-key\|PMAK-" || true
43+
}
44+
3045
echo "Fetching list of current collections"
3146
echo "curl -o ${COLLECTIONS_LIST_FILE}
3247
--location 'https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}'
3348
--header 'X-API-Key: **********'"
34-
curl --show-error --fail --silent -o "${COLLECTIONS_LIST_FILE}" \
49+
execute_curl --show-error --fail --silent -o "${COLLECTIONS_LIST_FILE}" \
3550
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
3651
--header "X-API-Key: ${POSTMAN_API_KEY}"
3752

38-
collection_exists=$(jq '.collections | any(.name=="'"${current_collection_name}"'")' "${COLLECTIONS_LIST_FILE}")
53+
# Print the collections list to the console
54+
echo "Current collections in the workspace:"
55+
jq '.collections[] | {id, name}' "${COLLECTIONS_LIST_FILE}"
56+
57+
collection_exists=$(jq '.collections | any(.name=="'"${current_collection_name}"'")' "${COLLECTIONS_LIST_FILE}")
3958

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

4766
echo "Removing star icon from the previous collection name"
4867
echo "curl -o ${COLLECTIONS_LIST_FILE}
49-
--location 'https://api.getpostman.com/collections/${previous_star_collection_id}'
50-
--header 'X-API-Key: **********'
51-
--data \"{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}\""
52-
curl --show-error --fail --silent --request PATCH \
53-
--location "https://api.getpostman.com/collections/${previous_star_collection_id}" \
54-
--header "Content-Type: application/json" \
55-
--header "X-API-Key: ${POSTMAN_API_KEY}" \
56-
--data "{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}"
68+
--location 'https://api.getpostman.com/collections/${previous_star_collection_id}'
69+
--header 'X-API-Key: **********'
70+
--data '{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}'"
71+
72+
execute_curl --show-error --fail --silent --request PATCH \
73+
--location "https://api.getpostman.com/collections/${previous_star_collection_id}" \
74+
--header "Content-Type: application/json" \
75+
--header "X-API-Key: ${POSTMAN_API_KEY}" \
76+
--data "{\"collection\": {\"info\": {\"name\": \"${new_collection_name}\"}}}"
77+
5778
fi
5879

5980
# Create new collection
@@ -63,17 +84,12 @@ if [ "$collection_exists" = "false" ]; then
6384
--header 'Content-Type: application/json'
6485
--header 'X-API-Key: **********'
6586
--data ${collection_transformed_path}"
66-
curl --show-error \
67-
--retry 7 \
68-
--retry-delay 30 \
69-
--retry-max-time 1200 \
70-
--retry-all-errors \
71-
--fail \
72-
--silent \
73-
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
74-
--header "Content-Type: application/json" \
75-
--header "X-API-Key: ${POSTMAN_API_KEY}" \
76-
--data "@${collection_transformed_path}" \
87+
execute_curl --show-error --retry 3 --retry-delay 30 --retry-max-time 1200 \
88+
--retry-all-errors --fail --silent \
89+
--location "https://api.getpostman.com/collections?workspace=${WORKSPACE_ID}" \
90+
--header "Content-Type: application/json" \
91+
--header "X-API-Key: ${POSTMAN_API_KEY}" \
92+
--data "@${collection_transformed_path}"
7793

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

89-
curl --show-error \
90-
--retry 7 \
91-
--retry-delay 30 \
92-
--retry-max-time 1200 \
93-
--retry-all-errors \
94-
--fail \
95-
--silent \
96-
--request PUT \
97-
--location "https://api.getpostman.com/collections/${collection_id}" \
98-
--header "Content-Type: application/json" \
99-
--header "X-API-Key: ${POSTMAN_API_KEY}" \
100-
--data "@${collection_transformed_path}"
105+
execute_curl --request PUT --retry 3 --retry-delay 30 --retry-max-time 1200 \
106+
--show-error --fail --silent \
107+
--location "https://api.getpostman.com/collections/${collection_id}" \
108+
--header "Content-Type: application/json" \
109+
--header "X-API-Key: ${POSTMAN_API_KEY}" \
110+
--data "@${collection_transformed_path}"
111+
101112
fi
102113

103114
popd -0

0 commit comments

Comments
 (0)