File size: 3,095 Bytes
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
#!/bin/bash

# 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 "πŸ“‹ Loading credentials from $creds_file..."

        # 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 "⚠️  Warning: $creds_file not found"
    fi
}

# Function to check and validate required credentials
check_credentials() {
    echo "πŸ” Checking for credentials..."

    local missing_vars=()
    local required_vars=("NEBIUS_API_KEY" "NEBIUS_MODEL" "MODAL_TOKEN_ID" "MODAL_TOKEN_SECRET" "HF_MODEL" "HF_TOKEN")

    for var in "${required_vars[@]}"; do
        if [ -z "${!var}" ]; then
            missing_vars+=("$var")
        fi
    done

    if [ ${#missing_vars[@]} -gt 0 ]; then
        echo "πŸ“‚ Missing environment variables: ${missing_vars[*]}"
        echo "πŸ”„ Attempting to load from creds.py..."
        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 "❌ Error: The following required environment variables are not set: ${missing_vars[*]}"
            echo "πŸ’‘ Please set them in your environment or ensure tests/secrets/creds.py exists with the required values."
            return 1
        fi
    fi

    echo "βœ… All credentials found"
    return 0
}

# Main execution when script is run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    check_credentials
    exit $?
fi