Skip to content
Merged
Changes from 2 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
31 changes: 19 additions & 12 deletions scripts/reset_iks_api_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,25 @@ fetch_data() {

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

# Extract next URL and current data
next_url=$(echo "$response" | jq -r '.next')
key_descriptions=$(echo "$response" | jq -r --arg name "${APIKEY_KEY_NAME}" '.apikeys | .[] | select(.name == $name) | .description')
for i in "${key_descriptions[@]}"; do
if [[ "$i" =~ ${REGION} ]] && [[ "$i" =~ ${RESOURCE_GROUP_ID} ]]; then
echo "Found key named ${APIKEY_KEY_NAME} which covers clusters in ${REGION} and resource group ID ${RESOURCE_GROUP_ID}"
reset=false
break
fi
done
response=$(curl -s -w "%{http_code}" "$url" --header "Authorization: $IAM_TOKEN" --header "Content-Type: application/json")
status_code="${response: -3}"
response_body="${response%???}"
if [[ "$status_code" == "200" ]]; then
# Extract next URL and current data
next_url=$(echo "$response_body" | jq -r '.next')
key_descriptions=$(echo "$response_body" | jq -r --arg name "${APIKEY_KEY_NAME}" '.apikeys | .[] | select(.name == $name) | .description')
for i in "${key_descriptions[@]}"; do
if [[ "$i" =~ ${REGION} ]] && [[ "$i" =~ ${RESOURCE_GROUP_ID} ]]; then
echo "Found key named ${APIKEY_KEY_NAME} which covers clusters in ${REGION} and resource group ID ${RESOURCE_GROUP_ID}"
reset=false
break
fi
done
else
echo "Request failed. Status code: $status_code"
echo "Error message: $response_body"
exit 1 # Indicate an error
fi
url=$next_url
done
}
Expand Down