Spaces:
Paused
Paused
File size: 4,697 Bytes
ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 186edf4 ae122c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
#!/bin/bash
# Colors and formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
# Yuga Planner Credential Loading Script
# This script loads credentials from environment variables or creds.py
# Function to load credentials from creds.py if environment variables are not set
load_credentials() {
local creds_file="tests/secrets/creds.py"
if [ -f "$creds_file" ]; then
echo -e "${BLUE}π Loading credentials from $creds_file...${RESET}"
# Extract credentials from creds.py if environment variables are not set
if [ -z "$NEBIUS_API_KEY" ]; then
export NEBIUS_API_KEY=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.NEBIUS_API_KEY)
" 2>/dev/null || echo "")
fi
if [ -z "$NEBIUS_MODEL" ]; then
export NEBIUS_MODEL=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.NEBIUS_MODEL)
" 2>/dev/null || echo "")
fi
if [ -z "$MODAL_TOKEN_ID" ]; then
export MODAL_TOKEN_ID=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.MODAL_TOKEN_ID)
" 2>/dev/null || echo "")
fi
if [ -z "$MODAL_TOKEN_SECRET" ]; then
export MODAL_TOKEN_SECRET=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.MODAL_TOKEN_SECRET)
" 2>/dev/null || echo "")
fi
if [ -z "$HF_MODEL" ]; then
export HF_MODEL=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.HF_MODEL)
" 2>/dev/null || echo "")
fi
if [ -z "$HF_TOKEN" ]; then
export HF_TOKEN=$(python3 -c "
import sys
sys.path.append('tests/secrets')
import creds
print(creds.HF_TOKEN)
" 2>/dev/null || echo "")
fi
else
echo -e "${YELLOW}β οΈ Warning: $creds_file not found${RESET}"
echo -e "${CYAN}π‘ Run '${GREEN}make setup-secrets${CYAN}' to create the template${RESET}"
fi
}
# Function to check and validate required credentials
check_credentials() {
echo -e "${CYAN}π Validating credentials...${RESET}"
local missing_vars=()
local required_vars=("NEBIUS_API_KEY" "NEBIUS_MODEL" "MODAL_TOKEN_ID" "MODAL_TOKEN_SECRET" "HF_MODEL" "HF_TOKEN")
local found_vars=()
# First check what's already available
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
else
found_vars+=("$var")
fi
done
# Show what we found
if [ ${#found_vars[@]} -gt 0 ]; then
echo -e "${GREEN}β
Found environment variables: ${found_vars[*]}${RESET}"
fi
if [ ${#missing_vars[@]} -gt 0 ]; then
echo -e "${YELLOW}π Missing from environment: ${missing_vars[*]}${RESET}"
echo -e "${BLUE}π Attempting to load from creds.py...${RESET}"
load_credentials
# Check again after loading from creds.py
missing_vars=()
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
fi
done
if [ ${#missing_vars[@]} -gt 0 ]; then
echo ""
echo -e "${RED}β Error: Missing required credentials: ${missing_vars[*]}${RESET}"
echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
echo -e "${BOLD}π‘ Setup Instructions:${RESET}"
echo -e " 1. Run: ${GREEN}make setup-secrets${RESET}"
echo -e " 2. Edit: ${CYAN}tests/secrets/creds.py${RESET}"
echo -e " 3. Add your API credentials"
echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
return 1
fi
fi
echo -e "${GREEN}β
All credentials validated successfully${RESET}"
return 0
}
# Main execution when script is run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo -e "${BOLD}π Yuga Planner - Credential Validator${RESET}"
echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}"
check_credentials
exit $?
fi
|