Fix certificate viewing with array-based file collection for reliable display
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Documentation Validation / validate-docs (push) Has been cancelled
Documentation Validation / validate-policies-strict (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled

This commit is contained in:
aitbc1
2026-05-07 14:33:44 +02:00
parent a36bf78082
commit ff92004ad4

View File

@@ -359,56 +359,55 @@ display_badge() {
view_certificates() {
print_header "Stage Completion Certificates"
# Ensure directory exists
# Ensure CERT_DIR exists
if [ ! -d "$CERT_DIR" ]; then
mkdir -p "$CERT_DIR"
fi
# Debug: Show CERT_DIR
echo "Certificate directory: $CERT_DIR"
# Check for certificates
# Collect certificate files into array
local cert_files=()
local cert_count=0
if [ -d "$CERT_DIR" ]; then
for cert_file in "$CERT_DIR"/stage*_certificate.json; do
if [ -f "$cert_file" ]; then
cert_files+=("$cert_file")
((cert_count++))
fi
done
fi
echo "Found ${#cert_files[@]} certificate file(s)"
if [ ${#cert_files[@]} -eq 0 ]; then
if [ $cert_count -eq 0 ]; then
print_warning "No certificates found yet"
echo "Complete stages to earn certificates"
echo "Directory contents:"
ls -la "$CERT_DIR" 2>/dev/null || echo "Directory not accessible"
return 0
fi
echo -e "${BOLD}📜 Certificates Earned:${NC}"
echo
local cert_count=0
for cert_file in "${cert_files[@]}"; do
if [ -f "$cert_file" ]; then
((cert_count++))
# Display certificates with index
for i in "${!cert_files[@]}"; do
local cert_file="${cert_files[$i]}"
local stage_num=$(echo "$cert_file" | grep -o 'stage[0-9]' | grep -o '[0-9]')
local stage_name=$(get_stage_name $stage_num)
local timestamp=$(python3 -c "import json; print(json.load(open('$cert_file'))['completion_timestamp'])" 2>/dev/null || echo "Unknown")
echo -e "${GREEN}${NC} Stage $stage_num: $stage_name"
echo -e " ${GREEN}$(($i+1))${NC}. Stage $stage_num: $stage_name"
echo " Completed: $timestamp"
echo " File: $cert_file"
echo
fi
done
echo -e "${BOLD}Total certificates: $cert_count${NC}"
echo
echo -n "View certificate details? [1-$cert_count/N]: "
read -r view_choice || view_choice="N"
echo -n "View certificate details? Enter number [1-$cert_count] or N: "
read -r view_choice
if [[ "$view_choice" =~ ^[0-9]+$ ]] && [ "$view_choice" -ge 1 ] && [ "$view_choice" -le "$cert_count" ]; then
local cert_file="${cert_files[$((view_choice-1))]}"
local idx=$(($view_choice - 1))
local cert_file="${cert_files[$idx]}"
if [ -f "$cert_file" ]; then
echo
echo -e "${BOLD}Certificate Details:${NC}"
@@ -1000,7 +999,6 @@ main() {
fi
}
# Handle command line arguments
case "${1:-}" in
--overview)
@@ -1033,11 +1031,10 @@ case "${1:-}" in
echo " --check Check system readiness"
echo " --stage N Run specific stage (0-9)"
echo " --complete Run complete training program"
echo " --playground Run interactive playground mode"
echo " --playground Enter training playground mode"
echo " --help, -h Show this help message"
echo
echo "Without arguments, starts interactive menu"
exit 0
;;
"")
main