Files
query-orchestration/scripts/manual_tests/queues/list.all.docs.for.client.sh
T
Jay Brown 6dccf494f8 Merged in feature/permit-policy-cleanup (pull request #210)
cleanup permit policies and correct documentation

* docs

* policy cleanup

* refactor

* Merge remote-tracking branch 'origin/feature/permit-policy-cleanup' into feature/permit-policy-cleanup

* docs and edits
2026-02-19 20:22:59 +00:00

109 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Check if client ID parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 <client_id>"
echo "Example: $0 test_client_1758574881"
exit 1
fi
CLIENT_ID="$1"
# API configuration
# local host version of the test
#BASE_URL="http://localhost:8080"
# cloud version http://queryo-query-rtxkppcxpjsb-742555588.us-east-2.elb.amazonaws.com/
BASE_URL="http://queryo-query-rtxkppcxpjsb-742555588.us-east-2.elb.amazonaws.com"
ENDPOINT="/client/${CLIENT_ID}/document"
# Color codes for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo "================================================"
echo -e "${BLUE}Document List for Client${NC}"
echo "================================================"
echo -e "Client ID: ${YELLOW}$CLIENT_ID${NC}"
echo -e "API Endpoint: ${CYAN}${BASE_URL}${ENDPOINT}${NC}"
echo "================================================"
echo ""
# Make API request
echo -e "${BLUE}Fetching documents...${NC}"
RESPONSE=$(curl -s -w "\n%{http_code}" "${BASE_URL}${ENDPOINT}")
# Extract HTTP status code (last line)
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
# Extract response body (all lines except last) - using sed for portability
RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d')
# Check HTTP status
if [ "$HTTP_STATUS" -eq 200 ]; then
echo -e "${GREEN}✓ API Request Successful${NC}"
echo ""
# Check if jq is available for JSON parsing
if command -v jq >/dev/null 2>&1; then
# Parse and display with jq
DOCUMENT_COUNT=$(echo "$RESPONSE_BODY" | jq '. | length' 2>/dev/null || echo "0")
if [ -z "$DOCUMENT_COUNT" ] || [ "$DOCUMENT_COUNT" = "null" ]; then
DOCUMENT_COUNT=0
fi
if [ "$DOCUMENT_COUNT" -eq 0 ]; then
echo -e "${YELLOW}No documents found for client: $CLIENT_ID${NC}"
else
echo -e "${GREEN}Found $DOCUMENT_COUNT document(s)${NC}"
echo ""
echo -e "${BLUE}Document Details:${NC}"
echo "------------------------------------------------"
# Display each document with formatting
echo "$RESPONSE_BODY" | jq -r '.[] |
"Document ID: \(.id)\n" +
"Hash: \(.hash)\n" +
"---"'
fi
else
# Fallback to basic formatting without jq
echo -e "${YELLOW}Note: jq not found, displaying raw JSON response${NC}"
echo ""
echo -e "${BLUE}Raw Response:${NC}"
echo "$RESPONSE_BODY" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE_BODY"
fi
elif [ "$HTTP_STATUS" -eq 401 ]; then
echo -e "${RED}✗ Unauthorized (401)${NC}"
echo -e "${YELLOW}Authentication required. This endpoint requires JWT authentication.${NC}"
echo ""
echo -e "${BLUE}Response:${NC}"
echo "$RESPONSE_BODY"
elif [ "$HTTP_STATUS" -eq 404 ]; then
echo -e "${RED}✗ Not Found (404)${NC}"
echo -e "${YELLOW}Client '$CLIENT_ID' not found or no documents exist.${NC}"
echo ""
echo -e "${BLUE}Response:${NC}"
echo "$RESPONSE_BODY"
else
echo -e "${RED}✗ API Request Failed (HTTP $HTTP_STATUS)${NC}"
echo ""
echo -e "${BLUE}Response:${NC}"
echo "$RESPONSE_BODY"
fi
echo ""
echo "================================================"
# Exit with appropriate code
if [ "$HTTP_STATUS" -eq 200 ]; then
exit 0
else
exit 1
fi