|
3 | 3 | # The base URL for your Orion Context Broker
|
4 | 4 | BROKER_URL=${BROKER_URL:-"http://app.local:1026"}
|
5 | 5 |
|
| 6 | +# The bearer token for authentication |
| 7 | +BROKER_TOKEN=${BROKER_TOKEN:-""} |
| 8 | + |
| 9 | +# Define the headers for the cURL commands |
| 10 | +HEADERS=(-H "Accept: application/json") |
| 11 | +if [ -n "$BROKER_TOKEN" ]; then |
| 12 | + HEADERS+=(-H "Authorization: Bearer $BROKER_TOKEN") |
| 13 | +fi |
| 14 | + |
6 | 15 | # Fetch all subscription IDs using a GET request
|
7 |
| -# Include additional headers as needed, e.g., for multi-tenant setups or authentication |
8 |
| -subscription_ids=$(curl -s -X GET "${BROKER_URL}/v2/subscriptions" \ |
9 |
| --H "Accept: application/json" | jq -r '.[].id') |
| 16 | +response=$(curl -s -o /dev/null -w "%{http_code}" -X GET "${BROKER_URL}/v2/subscriptions" "${HEADERS[@]}") |
| 17 | +http_code="$response" |
| 18 | + |
| 19 | +echo "HTTP Code: $http_code" |
| 20 | + |
| 21 | +# Check if the GET request returned a 401 status code |
| 22 | +if [ "$http_code" -eq 401 ]; then |
| 23 | + echo "Unauthorized. Please check your token." |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# If the GET request was successful, fetch the response body and parse it to get the subscription IDs |
| 28 | +if [ "$http_code" -eq 200 ]; then |
| 29 | + response_body=$(curl -s -X GET "${BROKER_URL}/v2/subscriptions" "${HEADERS[@]}") |
| 30 | + subscription_ids=$(echo "$response_body" | jq -r '.[].id') |
| 31 | +fi |
10 | 32 |
|
11 | 33 | # Check if there are any subscriptions to delete
|
12 | 34 | if [ -z "$subscription_ids" ]; then
|
|
16 | 38 |
|
17 | 39 | # Loop through the subscription IDs and delete each one
|
18 | 40 | for id in $subscription_ids; do
|
19 |
| - curl -X DELETE "${BROKER_URL}/v2/subscriptions/${id}" \ |
20 |
| - -H "Accept: application/json" |
21 |
| - echo "Deleted subscription $id" |
| 41 | + response=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE "${BROKER_URL}/v2/subscriptions/${id}" "${HEADERS[@]}") |
| 42 | + http_code="$response" |
| 43 | + |
| 44 | + # Check if the DELETE request returned a 401 status code (optional: just to notify but not to exit) |
| 45 | + if [ "$http_code" -eq 401 ]; then |
| 46 | + echo "Failed to delete subscription $id. Unauthorized. Please check your token." |
| 47 | + continue |
| 48 | + fi |
| 49 | + |
| 50 | + echo "Deleted subscription $id" |
22 | 51 | done
|
23 | 52 |
|
24 | 53 | echo "All subscriptions have been deleted."
|
25 |
| - |
|
0 commit comments