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
19 changes: 19 additions & 0 deletions scripts/reset_iks_api_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ if [[ -z "${RESOURCE_GROUP_ID}" ]]; then
exit 1
fi

# ENVIRONMENT VARIABLE VALIDATION
if [[ -z "${IAM_TOKEN}" ]]; then
echo "Environment variable IAM_TOKEN is not set." >&2
exit 1
fi

if [[ -z "${ACCOUNT_ID}" ]]; then
echo "Environment variable ACCOUNT_ID is not set." >&2
exit 1
fi


get_cloud_endpoint() {
iam_cloud_endpoint="${IBMCLOUD_IAM_API_ENDPOINT:-"iam.cloud.ibm.com"}"
IBMCLOUD_IAM_API_ENDPOINT=${iam_cloud_endpoint#https://}
Expand Down Expand Up @@ -50,6 +62,13 @@ fetch_data() {
# Fetch data from the API
IAM_RESPONSE=$(curl -s "$url" --header "Authorization: $IAM_TOKEN" --header "Content-Type: application/json")

# check if the response is valid JSON.
if ! echo "${IAM_RESPONSE}" | jq -e . >/dev/null 2>&1; then
echo "Error: API did not return valid JSON." >&2
echo "Response was: ${IAM_RESPONSE}" >&2
exit 1
fi

ERROR_MESSAGE=$(echo "${IAM_RESPONSE}" | jq 'has("errors")')
if [[ "${ERROR_MESSAGE}" != false ]]; then
echo "${IAM_RESPONSE}" | jq '.errors'
Expand Down