Skip to content

Commit 42b5e54

Browse files
authored
🔧 Improve DID bootstrap error handling (#1758)
Enhance the Governance DID bootstrapping script with more robust error handling and improved reliability: * Remove `-e` flag from `set` to allow manual error handling * Add `-f` flag to `curl` commands for fail-fast behavior on HTTP errors * Explicitly check curl command exit codes and exit on failure * Simplify DID existence check by comparing against empty array `[]` * Define `BASE_URL` variable inline instead of using environment variable * Add descriptive error messages for debugging failed operations This prevents silent failures during DID bootstrap and provides clearer feedback when errors occur, making the deployment process more reliable.
1 parent 2987a4d commit 42b5e54

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

helm/acapy-cloud/conf/dev/governance-web.yaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,41 @@ jobs:
241241
- /bin/sh
242242
- -c
243243
- |
244-
set -euo pipefail
244+
set -uo pipefail
245245
246-
# Check if Governance DID already exists
247-
DID=$(curl ${URL}/governance/v1/wallet/dids \
248-
-sX GET \
246+
BASE_URL=http://{{ include "acapy-cloud.fullname" . }}:{{ .Values.service.port }}
247+
248+
# List all Governance DIDs
249+
DIDS=$(curl ${BASE_URL}/governance/v1/wallet/dids \
250+
-fsX GET \
249251
-H "X-API-Key: governance.${API_KEY}")
250-
if echo "${DID}" | grep -q "did:cheqd"; then
251-
echo "Governance DID already exists, skipping bootstrap."
252-
echo "${DID}"
252+
253+
# If listing dids fails, exit with error
254+
if [ $? -ne 0 ]; then
255+
echo "Failed listing Governance DIDs. Exiting."
256+
exit 1
257+
fi
258+
259+
# Check if the list of DIDs is not empty
260+
if [ "${DIDS}" != "[]" ]; then
261+
echo "Governance DID already exists: ${DIDS}"
253262
exit 0
254263
fi
255264
256-
echo "Bootstrapping Governance DID..."
257-
RESULT=$(curl ${URL}/governance/v1/wallet/dids \
258-
-sX POST \
265+
echo "No DIDs found, proceeding with bootstrap."
266+
RESULT=$(curl ${BASE_URL}/governance/v1/wallet/dids \
267+
-fsX POST \
259268
-H "Content-Type: application/json" \
260269
-H "X-API-Key: governance.${API_KEY}" \
261270
-d '{"method": "cheqd", "seed": "'${WALLET_SEED}'"}')
262271
272+
if [ $? -ne 0 ]; then
273+
echo "Failed to create Governance DID. Exiting."
274+
exit 1
275+
fi
276+
263277
echo "DID created: ${RESULT}"
264278
env:
265-
URL: http://{{ include "acapy-cloud.fullname" . }}:{{ .Values.service.port }}
266279
WALLET_SEED:
267280
valueFrom:
268281
secretKeyRef:

helm/acapy-cloud/conf/local/governance-web.yaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,41 @@ jobs:
234234
- /bin/sh
235235
- -c
236236
- |
237-
set -euo pipefail
237+
set -uo pipefail
238238
239-
# Check if Governance DID already exists
240-
DID=$(curl ${URL}/governance/v1/wallet/dids \
241-
-sX GET \
239+
BASE_URL=http://{{ include "acapy-cloud.fullname" . }}:{{ .Values.service.port }}
240+
241+
# List all Governance DIDs
242+
DIDS=$(curl ${BASE_URL}/governance/v1/wallet/dids \
243+
-fsX GET \
242244
-H "X-API-Key: governance.${API_KEY}")
243-
if echo "${DID}" | grep -q "did:cheqd"; then
244-
echo "Governance DID already exists, skipping bootstrap."
245-
echo "${DID}"
245+
246+
# If listing dids fails, exit with error
247+
if [ $? -ne 0 ]; then
248+
echo "Failed listing Governance DIDs. Exiting."
249+
exit 1
250+
fi
251+
252+
# Check if the list of DIDs is not empty
253+
if [ "${DIDS}" != "[]" ]; then
254+
echo "Governance DID already exists: ${DIDS}"
246255
exit 0
247256
fi
248257
249-
echo "Bootstrapping Governance DID..."
250-
RESULT=$(curl ${URL}/governance/v1/wallet/dids \
251-
-sX POST \
258+
echo "No DIDs found, proceeding with bootstrap."
259+
RESULT=$(curl ${BASE_URL}/governance/v1/wallet/dids \
260+
-fsX POST \
252261
-H "Content-Type: application/json" \
253262
-H "X-API-Key: governance.${API_KEY}" \
254263
-d '{"method": "cheqd", "seed": "'${WALLET_SEED}'"}')
255264
265+
if [ $? -ne 0 ]; then
266+
echo "Failed to create Governance DID. Exiting."
267+
exit 1
268+
fi
269+
256270
echo "DID created: ${RESULT}"
257271
env:
258-
URL: http://{{ include "acapy-cloud.fullname" . }}:{{ .Values.service.port }}
259272
WALLET_SEED:
260273
valueFrom:
261274
secretKeyRef:

0 commit comments

Comments
 (0)