Skip to content

Commit 813a0c7

Browse files
authored
fix: display error code and error message when api call fails in reset_iks_api_key.sh (#696)
1 parent 21e9aaf commit 813a0c7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scripts/reset_iks_api_key.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ fetch_data() {
4848

4949
while [ "$url" != "null" ]; do
5050
# Fetch data from the API
51-
response=$(curl -s "$url" --header "Authorization: $IAM_TOKEN" --header "Content-Type: application/json")
51+
IAM_RESPONSE=$(curl -s "$url" --header "Authorization: $IAM_TOKEN" --header "Content-Type: application/json")
5252

53-
# Extract next URL and current data
54-
next_url=$(echo "$response" | jq -r '.next')
55-
key_descriptions=$(echo "$response" | jq -r --arg name "${APIKEY_KEY_NAME}" '.apikeys | .[] | select(.name == $name) | .description')
53+
ERROR_MESSAGE=$(echo "${IAM_RESPONSE}" | jq 'has("errors")')
54+
if [[ "${ERROR_MESSAGE}" != false ]]; then
55+
echo "${IAM_RESPONSE}" | jq '.errors'
56+
echo "Could not obtain api keys"
57+
exit 1
58+
fi
59+
60+
next_url=$(echo "${IAM_RESPONSE}" | jq -r '.next')
61+
key_descriptions=$(echo "$IAM_RESPONSE" | jq -r --arg name "${APIKEY_KEY_NAME}" '.apikeys | .[] | select(.name == $name) | .description')
5662
for i in "${key_descriptions[@]}"; do
5763
if [[ "$i" =~ ${REGION} ]] && [[ "$i" =~ ${RESOURCE_GROUP_ID} ]]; then
5864
echo "Found key named ${APIKEY_KEY_NAME} which covers clusters in ${REGION} and resource group ID ${RESOURCE_GROUP_ID}"

0 commit comments

Comments
 (0)