@@ -254,60 +254,22 @@ tasks:
254254 exit 1
255255 fi
256256
257- # Create a temporary file to store the vendor-cli output
258- OUTPUT_FILE=$(mktemp)
259-
260- # Run vendor-cli to inspect the customer and get the installation ID
257+ # Run vendor-cli to inspect the customer and get the installation ID as JSON
261258 echo "Running vendor-cli to inspect customer..."
262- docker run --rm \
259+ CUSTOMER_JSON=$( docker run --rm \
263260 -e REPLICATED_API_TOKEN=$REPLICATED_API_TOKEN \
264261 -e REPLICATED_APP={{.APP_NAME}} \
265262 replicated/vendor-cli:latest \
266- customer inspect --customer "{{.CUSTOMER_NAME}}" > $OUTPUT_FILE 2>&1
263+ customer inspect --customer "{{.CUSTOMER_NAME}}" --output json)
267264
268- # Check if the command succeeded
269- if [ $? -ne 0 ]; then
270- echo "ERROR: vendor-cli command failed. Output:"
271- cat $OUTPUT_FILE
272- rm $OUTPUT_FILE
273- exit 1
274- fi
275-
276- # Try direct extraction using grep pattern for the installationId
277- INSTALLATION_ID=$(grep -o '"installationId": *"[^"]*"' $OUTPUT_FILE | grep -o '"[^"]*"$' | tr -d '"' || true)
278-
279- # If grep didn't find it, try as a fallback to parse via jq if the file looks like JSON
280- if [ -z "$INSTALLATION_ID" ] && grep -q "^{" $OUTPUT_FILE; then
281- echo "Attempting to extract installation ID with jq..."
282- set +e # Don't exit on error
283- if command -v jq >/dev/null 2>&1; then
284- INSTALLATION_ID=$(cat $OUTPUT_FILE | jq -r '.installationId // empty' 2>/dev/null || true)
285- fi
286- set -e
287- fi
265+ # Use jq to properly extract the installationId
266+ INSTALLATION_ID=$(echo "$CUSTOMER_JSON" | jq -r '.installationId')
288267
289268 # Check if we got a valid ID
290- if [ -z "$INSTALLATION_ID" ]; then
291- echo "Failed to extract installationId from vendor-cli output"
292- echo "Output content:"
293- cat $OUTPUT_FILE | head -n 20
294-
295- # Special case: If the output appears to be just a plain string already, use that
296- if [ $(wc -l < $OUTPUT_FILE) -eq 1 ] && [ $(wc -w < $OUTPUT_FILE) -eq 1 ]; then
297- echo "Output appears to be a single token, using it directly as the license ID"
298- INSTALLATION_ID=$(cat $OUTPUT_FILE | tr -d '[:space:]')
299- else
300- rm $OUTPUT_FILE
301- exit 1
302- fi
303- fi
304-
305- # Clean up the temporary file
306- rm $OUTPUT_FILE
307-
308- # Validate the ID format (alphanumeric)
309- if ! [[ $INSTALLATION_ID =~ ^[a-zA-Z0-9]+$ ]]; then
310- echo "ERROR: Extracted installation ID doesn't match expected format: '$INSTALLATION_ID'"
269+ if [ -z "$INSTALLATION_ID" ] || [ "$INSTALLATION_ID" = "null" ]; then
270+ echo "Failed to extract installationId from customer JSON"
271+ echo "JSON structure:"
272+ echo "$CUSTOMER_JSON" | jq 'del(.installationId)' # Print JSON without the license ID
311273 exit 1
312274 fi
313275
0 commit comments