@@ -263,37 +263,54 @@ tasks:
263263 -e REPLICATED_API_TOKEN=$REPLICATED_API_TOKEN \
264264 -e REPLICATED_APP={{.APP_NAME}} \
265265 replicated/vendor-cli:latest \
266- customer inspect --customer "{{.CUSTOMER_NAME}}" --output json > $OUTPUT_FILE 2>&1
266+ customer inspect --customer "{{.CUSTOMER_NAME}}" > $OUTPUT_FILE 2>&1
267267
268- # Check if the output contains valid JSON
269- if ! grep -q "{" $OUTPUT_FILE ; then
270- echo "ERROR: vendor-cli did not return valid JSON . Output:"
268+ # Check if the command succeeded
269+ if [ $? -ne 0 ] ; then
270+ echo "ERROR: vendor-cli command failed . Output:"
271271 cat $OUTPUT_FILE
272272 rm $OUTPUT_FILE
273273 exit 1
274274 fi
275275
276- # Try to extract installationId from the JSON
277- if command -v jq >/dev/null 2>&1; then
278- # If jq is available, use it for proper JSON parsing
279- INSTALLATION_ID=$(cat $OUTPUT_FILE | jq -r '.installationId // empty')
280- else
281- # Fallback to grep/sed if jq is not available
282- INSTALLATION_ID=$(grep -o '"installationId"[[:space:]]*:[[:space:]]*"[^"]*"' $OUTPUT_FILE | sed 's/.*"\([^"]*\)".*/\1/')
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
283287 fi
284288
285289 # Check if we got a valid ID
286290 if [ -z "$INSTALLATION_ID" ]; then
287- echo "Failed to extract installationId from customer JSON"
288- echo "JSON structure:"
289- cat $OUTPUT_FILE
290- rm $OUTPUT_FILE
291- exit 1
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
292303 fi
293304
294305 # Clean up the temporary file
295306 rm $OUTPUT_FILE
296307
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'"
311+ exit 1
312+ fi
313+
297314 # Print the license ID so it can be captured
298315 echo "$INSTALLATION_ID"
299316
0 commit comments