gitarsenal-cli 1.1.19 → 1.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/python/MODAL_TOKEN_README.md +27 -14
- package/python/credentials_manager.py +0 -0
- package/python/fetch_modal_tokens.py +108 -0
- package/python/fix_modal_token.py +17 -7
- package/python/fix_modal_token_advanced.py +71 -72
- package/python/gitarsenal_proxy_client.py +0 -0
- package/python/modal_auth_patch.py +57 -30
- package/python/modal_proxy_service.py +108 -33
- package/python/modal_token_solution.py +84 -76
- package/python/test_modalSandboxScript.py +53 -31
- package/python/test_modal_auth.py +21 -9
package/package.json
CHANGED
@@ -6,21 +6,23 @@ This directory contains several scripts to solve the Modal token authentication
|
|
6
6
|
|
7
7
|
We've implemented a comprehensive solution that uses multiple approaches to ensure Modal can authenticate properly:
|
8
8
|
|
9
|
-
1. **
|
10
|
-
2. **
|
11
|
-
3. **
|
12
|
-
4. **
|
9
|
+
1. **fetch_modal_tokens.py**: Fetches tokens from the proxy server.
|
10
|
+
2. **modal_token_solution.py**: The main comprehensive solution that combines all approaches.
|
11
|
+
3. **modal_auth_patch.py**: A direct patch for Modal's authentication system.
|
12
|
+
4. **fix_modal_token.py**: A basic token setup script.
|
13
|
+
5. **fix_modal_token_advanced.py**: An advanced version with more approaches.
|
13
14
|
|
14
15
|
## How It Works
|
15
16
|
|
16
17
|
Our solution uses multiple approaches to ensure Modal authentication works:
|
17
18
|
|
18
|
-
1. **
|
19
|
-
2. **
|
20
|
-
3. **
|
21
|
-
4. **
|
22
|
-
5. **
|
23
|
-
6. **
|
19
|
+
1. **Token Fetching**: Tries to fetch tokens from the proxy server.
|
20
|
+
2. **Environment Variables**: Sets `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET` environment variables.
|
21
|
+
3. **Token Files**: Creates token files in various formats and locations that Modal might look for.
|
22
|
+
4. **Modal CLI**: Attempts to use the Modal CLI to set the token with the correct profile.
|
23
|
+
5. **Direct Patching**: Directly patches Modal's authentication system to always return our tokens.
|
24
|
+
6. **Monkey Patching**: Monkey-patches Modal's import system to inject our tokens.
|
25
|
+
7. **Authentication Testing**: Tests that the authentication works by creating a simple Modal app.
|
24
26
|
|
25
27
|
## Usage
|
26
28
|
|
@@ -36,27 +38,38 @@ In most cases, you should simply import `modal_token_solution` before importing
|
|
36
38
|
import modal_token_solution
|
37
39
|
import modal
|
38
40
|
|
39
|
-
# Now Modal will use our
|
41
|
+
# Now Modal will use our tokens
|
40
42
|
```
|
41
43
|
|
44
|
+
## Proxy Server Integration
|
45
|
+
|
46
|
+
The solution now integrates with the proxy server to fetch tokens:
|
47
|
+
|
48
|
+
1. **fetch_modal_tokens.py**: This script fetches tokens from the proxy server using the `MODAL_PROXY_URL` and `MODAL_PROXY_API_KEY` environment variables.
|
49
|
+
2. If the proxy server is not available, it falls back to hardcoded tokens.
|
50
|
+
3. All other scripts try to use the fetch_modal_tokens module first before falling back to hardcoded tokens.
|
51
|
+
|
42
52
|
## Troubleshooting
|
43
53
|
|
44
54
|
If you still encounter token issues:
|
45
55
|
|
46
|
-
1. Check that the
|
56
|
+
1. Check that the tokens are correct (token ID: `ak-sLhYqCjkvixiYcb9LAuCHp`, token secret: `as-fPzD0Zm0dl6IFAEkhaH9pq`).
|
47
57
|
2. Verify that the token files are created in the correct locations:
|
48
58
|
- `~/.modal/token.json`
|
49
59
|
- `~/.modalconfig`
|
50
|
-
3.
|
60
|
+
3. Check if the proxy server is accessible and returning valid tokens.
|
61
|
+
4. Try running the scripts manually to see detailed output.
|
51
62
|
|
52
63
|
## Implementation Details
|
53
64
|
|
54
|
-
- **Token
|
65
|
+
- **Token Values**: We try to fetch tokens from the proxy server, with fallback to hardcoded values.
|
55
66
|
- **File Locations**: Token files are created in the user's home directory under `~/.modal/`.
|
56
67
|
- **Patching**: We use Python's dynamic nature to patch Modal's authentication system at runtime.
|
68
|
+
- **Profile**: We use the `fr8mafia` profile when setting tokens via the CLI.
|
57
69
|
|
58
70
|
## Files
|
59
71
|
|
72
|
+
- **fetch_modal_tokens.py**: Fetches tokens from the proxy server.
|
60
73
|
- **modal_token_solution.py**: Comprehensive solution combining all approaches.
|
61
74
|
- **modal_auth_patch.py**: Direct patch for Modal's authentication system.
|
62
75
|
- **fix_modal_token.py**: Basic token setup script.
|
File without changes
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
Fetch Modal Tokens
|
4
|
+
|
5
|
+
This script fetches Modal tokens from the proxy server.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
import json
|
11
|
+
import requests
|
12
|
+
from pathlib import Path
|
13
|
+
|
14
|
+
# Default tokens to use if we can't fetch from the server
|
15
|
+
DEFAULT_TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
16
|
+
DEFAULT_TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq"
|
17
|
+
|
18
|
+
def fetch_tokens_from_proxy(proxy_url=None, api_key=None):
|
19
|
+
"""
|
20
|
+
Fetch Modal tokens from the proxy server.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
proxy_url: URL of the proxy server
|
24
|
+
api_key: API key for authentication
|
25
|
+
|
26
|
+
Returns:
|
27
|
+
tuple: (token_id, token_secret) if successful, (None, None) otherwise
|
28
|
+
"""
|
29
|
+
# Use environment variables if not provided
|
30
|
+
if not proxy_url:
|
31
|
+
proxy_url = os.environ.get("MODAL_PROXY_URL")
|
32
|
+
|
33
|
+
if not api_key:
|
34
|
+
api_key = os.environ.get("MODAL_PROXY_API_KEY")
|
35
|
+
|
36
|
+
# Check if we have the necessary information
|
37
|
+
if not proxy_url:
|
38
|
+
print("❌ No proxy URL provided or found in environment")
|
39
|
+
return None, None
|
40
|
+
|
41
|
+
if not api_key:
|
42
|
+
print("❌ No API key provided or found in environment")
|
43
|
+
return None, None
|
44
|
+
|
45
|
+
# Ensure the URL ends with a slash
|
46
|
+
if not proxy_url.endswith("/"):
|
47
|
+
proxy_url += "/"
|
48
|
+
|
49
|
+
# Add the endpoint for fetching tokens
|
50
|
+
token_url = f"{proxy_url}api/modal-tokens"
|
51
|
+
|
52
|
+
try:
|
53
|
+
# Make the request
|
54
|
+
print(f"🔄 Fetching tokens from {token_url}")
|
55
|
+
response = requests.get(
|
56
|
+
token_url,
|
57
|
+
headers={"X-API-Key": api_key}
|
58
|
+
)
|
59
|
+
|
60
|
+
# Check if the request was successful
|
61
|
+
if response.status_code == 200:
|
62
|
+
data = response.json()
|
63
|
+
token_id = data.get("token_id")
|
64
|
+
token_secret = data.get("token_secret")
|
65
|
+
|
66
|
+
if token_id and token_secret:
|
67
|
+
print("✅ Successfully fetched tokens from proxy server")
|
68
|
+
return token_id, token_secret
|
69
|
+
else:
|
70
|
+
print("❌ Tokens not found in response")
|
71
|
+
return None, None
|
72
|
+
else:
|
73
|
+
print(f"❌ Failed to fetch tokens: {response.status_code} - {response.text}")
|
74
|
+
return None, None
|
75
|
+
except Exception as e:
|
76
|
+
print(f"❌ Error fetching tokens: {e}")
|
77
|
+
return None, None
|
78
|
+
|
79
|
+
def get_tokens():
|
80
|
+
"""
|
81
|
+
Get Modal tokens, trying to fetch from the proxy server first.
|
82
|
+
|
83
|
+
Returns:
|
84
|
+
tuple: (token_id, token_secret)
|
85
|
+
"""
|
86
|
+
# Try to fetch from the proxy server
|
87
|
+
token_id, token_secret = fetch_tokens_from_proxy()
|
88
|
+
|
89
|
+
# If we couldn't fetch from the server, use the default tokens
|
90
|
+
if not token_id or not token_secret:
|
91
|
+
print("⚠️ Using default tokens")
|
92
|
+
return DEFAULT_TOKEN_ID, DEFAULT_TOKEN_SECRET
|
93
|
+
|
94
|
+
return token_id, token_secret
|
95
|
+
|
96
|
+
if __name__ == "__main__":
|
97
|
+
token_id, token_secret = get_tokens()
|
98
|
+
print(f"Token ID: {token_id}")
|
99
|
+
print(f"Token Secret: {token_secret}")
|
100
|
+
|
101
|
+
# Write the tokens to a file for use by other scripts
|
102
|
+
tokens_file = Path(__file__).parent / "modal_tokens.json"
|
103
|
+
with open(tokens_file, 'w') as f:
|
104
|
+
json.dump({
|
105
|
+
"token_id": token_id,
|
106
|
+
"token_secret": token_secret
|
107
|
+
}, f)
|
108
|
+
print(f"✅ Tokens written to {tokens_file}")
|
@@ -38,28 +38,38 @@ except Exception as e:
|
|
38
38
|
print(f"❌ Error running advanced Modal token fixer: {e}")
|
39
39
|
print("🔄 Falling back to basic implementation")
|
40
40
|
|
41
|
-
#
|
42
|
-
|
41
|
+
# Try to get tokens from the proxy server
|
42
|
+
try:
|
43
|
+
# First, try to import the fetch_modal_tokens module
|
44
|
+
from fetch_modal_tokens import get_tokens
|
45
|
+
TOKEN_ID, TOKEN_SECRET = get_tokens()
|
46
|
+
print(f"✅ Using tokens from proxy server or defaults")
|
47
|
+
except ImportError:
|
48
|
+
# If the module is not available, use hardcoded tokens
|
49
|
+
TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
50
|
+
TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
|
51
|
+
print(f"⚠️ Using hardcoded tokens")
|
43
52
|
|
44
53
|
print("🔧 Fixing Modal token (basic implementation)...")
|
45
54
|
|
46
55
|
# Set environment variables
|
47
|
-
os.environ["MODAL_TOKEN_ID"] =
|
48
|
-
os.environ["
|
49
|
-
print(f"✅ Set MODAL_TOKEN_ID and
|
56
|
+
os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
|
57
|
+
os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
|
58
|
+
print(f"✅ Set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET environment variables")
|
50
59
|
|
51
60
|
# Create token file
|
52
61
|
modal_dir = Path.home() / ".modal"
|
53
62
|
modal_dir.mkdir(exist_ok=True)
|
54
63
|
token_file = modal_dir / "token.json"
|
55
64
|
with open(token_file, 'w') as f:
|
56
|
-
f.write(f'{{"token_id": "{
|
65
|
+
f.write(f'{{"token_id": "{TOKEN_ID}", "token_secret": "{TOKEN_SECRET}"}}')
|
57
66
|
print(f"✅ Created token file at {token_file}")
|
58
67
|
|
59
68
|
# Create .modalconfig file
|
60
69
|
modalconfig_file = Path.home() / ".modalconfig"
|
61
70
|
with open(modalconfig_file, 'w') as f:
|
62
|
-
f.write(f"token_id = {
|
71
|
+
f.write(f"token_id = {TOKEN_ID}\n")
|
72
|
+
f.write(f"token_secret = {TOKEN_SECRET}\n")
|
63
73
|
print(f"✅ Created .modalconfig file at {modalconfig_file}")
|
64
74
|
|
65
75
|
print("\n✅ Done fixing Modal token. Please try your command again.")
|
@@ -19,17 +19,26 @@ import inspect
|
|
19
19
|
from pathlib import Path
|
20
20
|
import time
|
21
21
|
|
22
|
-
#
|
23
|
-
|
22
|
+
# Try to get tokens from the proxy server
|
23
|
+
try:
|
24
|
+
# First, try to import the fetch_modal_tokens module
|
25
|
+
from fetch_modal_tokens import get_tokens
|
26
|
+
TOKEN_ID, TOKEN_SECRET = get_tokens()
|
27
|
+
print(f"✅ Using tokens from proxy server or defaults")
|
28
|
+
except ImportError:
|
29
|
+
# If the module is not available, use hardcoded tokens
|
30
|
+
TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
31
|
+
TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
|
32
|
+
print(f"⚠️ Using hardcoded tokens")
|
24
33
|
|
25
34
|
print("🔧 Advanced Modal Token Fixer")
|
26
35
|
|
27
36
|
# Approach 1: Set environment variables
|
28
37
|
print("\n📋 Approach 1: Setting environment variables")
|
29
|
-
os.environ["MODAL_TOKEN_ID"] =
|
30
|
-
os.environ["
|
31
|
-
print(f"✅ Set MODAL_TOKEN_ID = {
|
32
|
-
print(f"✅ Set
|
38
|
+
os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
|
39
|
+
os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
|
40
|
+
print(f"✅ Set MODAL_TOKEN_ID = {TOKEN_ID}")
|
41
|
+
print(f"✅ Set MODAL_TOKEN_SECRET = {TOKEN_SECRET}")
|
33
42
|
|
34
43
|
# Approach 2: Create token files in various formats
|
35
44
|
print("\n📋 Approach 2: Creating token files in various formats")
|
@@ -40,8 +49,8 @@ modal_dir.mkdir(exist_ok=True)
|
|
40
49
|
token_file = modal_dir / "token.json"
|
41
50
|
with open(token_file, 'w') as f:
|
42
51
|
token_data = {
|
43
|
-
"token_id":
|
44
|
-
"
|
52
|
+
"token_id": TOKEN_ID,
|
53
|
+
"token_secret": TOKEN_SECRET
|
45
54
|
}
|
46
55
|
json.dump(token_data, f)
|
47
56
|
print(f"✅ Created token file at {token_file}")
|
@@ -50,8 +59,8 @@ print(f"✅ Created token file at {token_file}")
|
|
50
59
|
token_file_alt = modal_dir / "token_alt.json"
|
51
60
|
with open(token_file_alt, 'w') as f:
|
52
61
|
token_data_alt = {
|
53
|
-
"id":
|
54
|
-
"secret":
|
62
|
+
"id": TOKEN_ID,
|
63
|
+
"secret": TOKEN_SECRET
|
55
64
|
}
|
56
65
|
json.dump(token_data_alt, f)
|
57
66
|
print(f"✅ Created alternative token file at {token_file_alt}")
|
@@ -59,15 +68,16 @@ print(f"✅ Created alternative token file at {token_file_alt}")
|
|
59
68
|
# Format 3: Create .modalconfig file
|
60
69
|
modalconfig_file = Path.home() / ".modalconfig"
|
61
70
|
with open(modalconfig_file, 'w') as f:
|
62
|
-
f.write(f"token_id = {
|
71
|
+
f.write(f"token_id = {TOKEN_ID}\n")
|
72
|
+
f.write(f"token_secret = {TOKEN_SECRET}\n")
|
63
73
|
print(f"✅ Created .modalconfig file at {modalconfig_file}")
|
64
74
|
|
65
75
|
# Format 4: Create config.json file
|
66
76
|
config_file = modal_dir / "config.json"
|
67
77
|
with open(config_file, 'w') as f:
|
68
78
|
config_data = {
|
69
|
-
"
|
70
|
-
"
|
79
|
+
"token_id": TOKEN_ID,
|
80
|
+
"token_secret": TOKEN_SECRET
|
71
81
|
}
|
72
82
|
json.dump(config_data, f)
|
73
83
|
print(f"✅ Created config.json file at {config_file}")
|
@@ -75,40 +85,16 @@ print(f"✅ Created config.json file at {config_file}")
|
|
75
85
|
# Approach 3: Use Modal CLI to set token
|
76
86
|
print("\n📋 Approach 3: Using Modal CLI")
|
77
87
|
try:
|
78
|
-
#
|
79
|
-
temp_token_file = Path("/tmp/modal_token.txt")
|
80
|
-
with open(temp_token_file, 'w') as f:
|
81
|
-
f.write(TOKEN)
|
82
|
-
|
83
|
-
# Use the token file with Modal CLI
|
88
|
+
# Use the CLI to set the token directly
|
84
89
|
result = subprocess.run(
|
85
|
-
["modal", "token", "set", "--
|
90
|
+
["modal", "token", "set", "--token-id", TOKEN_ID, "--token-secret", TOKEN_SECRET, "--profile=fr8mafia", "--no-verify"],
|
86
91
|
capture_output=True, text=True
|
87
92
|
)
|
88
93
|
|
89
|
-
# Clean up
|
90
|
-
temp_token_file.unlink()
|
91
|
-
|
92
94
|
if result.returncode == 0:
|
93
95
|
print(f"✅ Successfully set token via Modal CLI")
|
94
96
|
else:
|
95
97
|
print(f"❌ Failed to set token via Modal CLI: {result.stderr}")
|
96
|
-
|
97
|
-
# Try alternative approach with stdin
|
98
|
-
print("🔄 Trying alternative approach with stdin")
|
99
|
-
process = subprocess.Popen(
|
100
|
-
["modal", "token", "set"],
|
101
|
-
stdin=subprocess.PIPE,
|
102
|
-
stdout=subprocess.PIPE,
|
103
|
-
stderr=subprocess.PIPE,
|
104
|
-
text=True
|
105
|
-
)
|
106
|
-
stdout, stderr = process.communicate(input=TOKEN)
|
107
|
-
|
108
|
-
if process.returncode == 0:
|
109
|
-
print(f"✅ Successfully set token via Modal CLI (stdin)")
|
110
|
-
else:
|
111
|
-
print(f"❌ Failed to set token via Modal CLI (stdin): {stderr}")
|
112
98
|
except Exception as e:
|
113
99
|
print(f"❌ Error using Modal CLI: {e}")
|
114
100
|
|
@@ -124,28 +110,30 @@ try:
|
|
124
110
|
|
125
111
|
# Try different approaches to set the token
|
126
112
|
try:
|
127
|
-
# Approach 4.1: Set token via _auth_config
|
113
|
+
# Approach 4.1: Set token via _auth_config
|
128
114
|
if hasattr(modal.config, '_auth_config'):
|
129
|
-
modal.config._auth_config.token_id =
|
130
|
-
|
115
|
+
modal.config._auth_config.token_id = TOKEN_ID
|
116
|
+
modal.config._auth_config.token_secret = TOKEN_SECRET
|
117
|
+
print(f"✅ Set tokens via _auth_config")
|
131
118
|
except Exception as e:
|
132
|
-
print(f"❌ Error setting
|
119
|
+
print(f"❌ Error setting tokens via _auth_config: {e}")
|
133
120
|
|
134
121
|
try:
|
135
|
-
# Approach 4.2: Set token via set_token()
|
122
|
+
# Approach 4.2: Set token via set_token() if it exists
|
136
123
|
if hasattr(modal.config, 'set_token'):
|
137
|
-
modal.config.set_token(
|
138
|
-
print(f"✅ Set
|
124
|
+
modal.config.set_token(TOKEN_ID, TOKEN_SECRET)
|
125
|
+
print(f"✅ Set tokens via set_token()")
|
139
126
|
except Exception as e:
|
140
|
-
print(f"❌ Error setting
|
127
|
+
print(f"❌ Error setting tokens via set_token(): {e}")
|
141
128
|
|
142
129
|
try:
|
143
|
-
# Approach 4.3: Set token via Config
|
130
|
+
# Approach 4.3: Set token via Config
|
144
131
|
if hasattr(modal.config, 'Config'):
|
145
|
-
modal.config.Config.token_id =
|
146
|
-
|
132
|
+
modal.config.Config.token_id = TOKEN_ID
|
133
|
+
modal.config.Config.token_secret = TOKEN_SECRET
|
134
|
+
print(f"✅ Set tokens via Config")
|
147
135
|
except Exception as e:
|
148
|
-
print(f"❌ Error setting
|
136
|
+
print(f"❌ Error setting tokens via Config: {e}")
|
149
137
|
|
150
138
|
# Approach 4.4: Inspect modal.config and try to find token-related attributes
|
151
139
|
print("\n🔍 Inspecting modal.config for token-related attributes...")
|
@@ -154,16 +142,16 @@ try:
|
|
154
142
|
print(f"Found potential token-related attribute: {name}")
|
155
143
|
try:
|
156
144
|
attr = getattr(modal.config, name)
|
157
|
-
if hasattr(attr, "
|
158
|
-
print(f" - Setting
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
145
|
+
if hasattr(attr, "token_id"):
|
146
|
+
print(f" - Setting token_id in {name}")
|
147
|
+
setattr(attr, "token_id", TOKEN_ID)
|
148
|
+
if hasattr(attr, "token_secret"):
|
149
|
+
print(f" - Setting token_secret in {name}")
|
150
|
+
setattr(attr, "token_secret", TOKEN_SECRET)
|
163
151
|
except Exception as e:
|
164
|
-
print(f" - Error setting
|
152
|
+
print(f" - Error setting tokens in {name}: {e}")
|
165
153
|
except Exception as e:
|
166
|
-
print(f"❌ Error setting
|
154
|
+
print(f"❌ Error setting tokens in Modal config: {e}")
|
167
155
|
except Exception as e:
|
168
156
|
print(f"❌ Error importing Modal: {e}")
|
169
157
|
|
@@ -172,6 +160,13 @@ print("\n📋 Approach 5: Monkey-patching Modal's authentication system")
|
|
172
160
|
try:
|
173
161
|
import modal
|
174
162
|
|
163
|
+
# Define functions that will always return our tokens
|
164
|
+
def get_token_id(*args, **kwargs):
|
165
|
+
return TOKEN_ID
|
166
|
+
|
167
|
+
def get_token_secret(*args, **kwargs):
|
168
|
+
return TOKEN_SECRET
|
169
|
+
|
175
170
|
# Find all authentication-related classes and functions
|
176
171
|
auth_related = []
|
177
172
|
for module_name in dir(modal):
|
@@ -187,19 +182,23 @@ try:
|
|
187
182
|
for name, module in auth_related:
|
188
183
|
if inspect.ismodule(module):
|
189
184
|
for func_name in dir(module):
|
190
|
-
if "get" in func_name.lower()
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
185
|
+
if "get" in func_name.lower():
|
186
|
+
if "token_id" in func_name.lower():
|
187
|
+
try:
|
188
|
+
original_func = getattr(module, func_name)
|
189
|
+
if callable(original_func):
|
190
|
+
print(f" - Patching {name}.{func_name} to return token_id")
|
191
|
+
setattr(module, func_name, get_token_id)
|
192
|
+
except Exception as e:
|
193
|
+
print(f" - Error patching {name}.{func_name}: {e}")
|
194
|
+
elif "token_secret" in func_name.lower() or "token" in func_name.lower():
|
195
|
+
try:
|
196
|
+
original_func = getattr(module, func_name)
|
197
|
+
if callable(original_func):
|
198
|
+
print(f" - Patching {name}.{func_name} to return token_secret")
|
199
|
+
setattr(module, func_name, get_token_secret)
|
200
|
+
except Exception as e:
|
201
|
+
print(f" - Error patching {name}.{func_name}: {e}")
|
203
202
|
except Exception as e:
|
204
203
|
print(f"❌ Error monkey-patching Modal: {e}")
|
205
204
|
|
File without changes
|
@@ -18,27 +18,40 @@ import types
|
|
18
18
|
import json
|
19
19
|
from pathlib import Path
|
20
20
|
|
21
|
-
#
|
22
|
-
|
21
|
+
# Try to get tokens from the proxy server
|
22
|
+
try:
|
23
|
+
# First, try to import the fetch_modal_tokens module
|
24
|
+
from fetch_modal_tokens import get_tokens
|
25
|
+
TOKEN_ID, TOKEN_SECRET = get_tokens()
|
26
|
+
print(f"✅ Using tokens from proxy server or defaults")
|
27
|
+
except ImportError:
|
28
|
+
# If the module is not available, use hardcoded tokens
|
29
|
+
TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
30
|
+
TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
|
31
|
+
print(f"⚠️ Using hardcoded tokens")
|
23
32
|
|
24
33
|
# Set environment variables
|
25
|
-
os.environ["MODAL_TOKEN_ID"] =
|
26
|
-
os.environ["
|
34
|
+
os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
|
35
|
+
os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
|
27
36
|
|
28
37
|
# Create token files
|
29
38
|
modal_dir = Path.home() / ".modal"
|
30
39
|
modal_dir.mkdir(exist_ok=True)
|
31
40
|
token_file = modal_dir / "token.json"
|
32
41
|
with open(token_file, 'w') as f:
|
33
|
-
f.write(f'{{"token_id": "{
|
42
|
+
f.write(f'{{"token_id": "{TOKEN_ID}", "token_secret": "{TOKEN_SECRET}"}}')
|
34
43
|
|
35
44
|
modalconfig_file = Path.home() / ".modalconfig"
|
36
45
|
with open(modalconfig_file, 'w') as f:
|
37
|
-
f.write(f"token_id = {
|
46
|
+
f.write(f"token_id = {TOKEN_ID}\n")
|
47
|
+
f.write(f"token_secret = {TOKEN_SECRET}\n")
|
48
|
+
|
49
|
+
# Define functions that will always return our tokens
|
50
|
+
def get_token_id(*args, **kwargs):
|
51
|
+
return TOKEN_ID
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
return TOKEN
|
53
|
+
def get_token_secret(*args, **kwargs):
|
54
|
+
return TOKEN_SECRET
|
42
55
|
|
43
56
|
# Patch Modal's authentication system
|
44
57
|
try:
|
@@ -47,25 +60,32 @@ try:
|
|
47
60
|
|
48
61
|
# Create a fake auth config object
|
49
62
|
class FakeAuthConfig:
|
50
|
-
token_id =
|
51
|
-
|
63
|
+
token_id = TOKEN_ID
|
64
|
+
token_secret = TOKEN_SECRET
|
52
65
|
|
53
|
-
def get_token(self, *args, **kwargs):
|
54
|
-
return TOKEN
|
55
|
-
|
56
66
|
def get_token_id(self, *args, **kwargs):
|
57
|
-
return
|
67
|
+
return TOKEN_ID
|
68
|
+
|
69
|
+
def get_token_secret(self, *args, **kwargs):
|
70
|
+
return TOKEN_SECRET
|
58
71
|
|
59
72
|
# Replace Modal's auth config with our fake one
|
60
73
|
modal.config._auth_config = FakeAuthConfig()
|
61
74
|
|
62
75
|
# Also patch any token-related functions
|
63
76
|
for name in dir(modal.config):
|
64
|
-
if "
|
77
|
+
if "token_id" in name.lower():
|
65
78
|
try:
|
66
79
|
attr = getattr(modal.config, name)
|
67
80
|
if callable(attr):
|
68
|
-
setattr(modal.config, name,
|
81
|
+
setattr(modal.config, name, get_token_id)
|
82
|
+
except:
|
83
|
+
pass
|
84
|
+
elif "token_secret" in name.lower() or "token" in name.lower():
|
85
|
+
try:
|
86
|
+
attr = getattr(modal.config, name)
|
87
|
+
if callable(attr):
|
88
|
+
setattr(modal.config, name, get_token_secret)
|
69
89
|
except:
|
70
90
|
pass
|
71
91
|
|
@@ -92,34 +112,41 @@ except ImportError:
|
|
92
112
|
# Create a fake auth config object if needed
|
93
113
|
if not hasattr(config, "_auth_config"):
|
94
114
|
class FakeAuthConfig:
|
95
|
-
token_id =
|
96
|
-
|
115
|
+
token_id = TOKEN_ID
|
116
|
+
token_secret = TOKEN_SECRET
|
97
117
|
|
98
|
-
def get_token(self, *args, **kwargs):
|
99
|
-
return TOKEN
|
100
|
-
|
101
118
|
def get_token_id(self, *args, **kwargs):
|
102
|
-
return
|
119
|
+
return TOKEN_ID
|
120
|
+
|
121
|
+
def get_token_secret(self, *args, **kwargs):
|
122
|
+
return TOKEN_SECRET
|
103
123
|
|
104
124
|
config._auth_config = FakeAuthConfig()
|
105
125
|
else:
|
106
126
|
# Patch existing auth config
|
107
|
-
config._auth_config.token_id =
|
108
|
-
config._auth_config.
|
127
|
+
config._auth_config.token_id = TOKEN_ID
|
128
|
+
config._auth_config.token_secret = TOKEN_SECRET
|
109
129
|
|
110
130
|
# Patch methods
|
111
|
-
if hasattr(config._auth_config, "get_token"):
|
112
|
-
config._auth_config.get_token = get_token
|
113
131
|
if hasattr(config._auth_config, "get_token_id"):
|
114
|
-
config._auth_config.get_token_id =
|
132
|
+
config._auth_config.get_token_id = get_token_id
|
133
|
+
if hasattr(config._auth_config, "get_token_secret"):
|
134
|
+
config._auth_config.get_token_secret = get_token_secret
|
115
135
|
|
116
136
|
# Also patch any token-related functions
|
117
137
|
for name in dir(config):
|
118
|
-
if "
|
138
|
+
if "token_id" in name.lower():
|
139
|
+
try:
|
140
|
+
attr = getattr(config, name)
|
141
|
+
if callable(attr):
|
142
|
+
setattr(config, name, get_token_id)
|
143
|
+
except:
|
144
|
+
pass
|
145
|
+
elif "token_secret" in name.lower() or "token" in name.lower():
|
119
146
|
try:
|
120
147
|
attr = getattr(config, name)
|
121
148
|
if callable(attr):
|
122
|
-
setattr(config, name,
|
149
|
+
setattr(config, name, get_token_secret)
|
123
150
|
except:
|
124
151
|
pass
|
125
152
|
|
@@ -111,7 +111,50 @@ def generate_random_password(length=16):
|
|
111
111
|
|
112
112
|
def setup_modal_auth():
|
113
113
|
"""Set up Modal authentication using the server's token"""
|
114
|
-
#
|
114
|
+
# First, try to fetch tokens from the proxy server
|
115
|
+
try:
|
116
|
+
# Import the fetch_modal_tokens module
|
117
|
+
logger.info("Fetching Modal tokens from proxy server...")
|
118
|
+
from fetch_modal_tokens import get_tokens
|
119
|
+
token_id, token_secret = get_tokens()
|
120
|
+
logger.info("Modal tokens fetched successfully")
|
121
|
+
|
122
|
+
# Set the tokens in environment variables
|
123
|
+
os.environ["MODAL_TOKEN_ID"] = token_id
|
124
|
+
os.environ["MODAL_TOKEN_SECRET"] = token_secret
|
125
|
+
|
126
|
+
# Create token files
|
127
|
+
modal_dir = Path.home() / ".modal"
|
128
|
+
modal_dir.mkdir(exist_ok=True)
|
129
|
+
token_file = modal_dir / "token.json"
|
130
|
+
with open(token_file, 'w') as f:
|
131
|
+
json.dump({
|
132
|
+
"token_id": token_id,
|
133
|
+
"token_secret": token_secret
|
134
|
+
}, f)
|
135
|
+
logger.info(f"Created token file at {token_file}")
|
136
|
+
|
137
|
+
# Create .modalconfig file
|
138
|
+
modalconfig_file = Path.home() / ".modalconfig"
|
139
|
+
with open(modalconfig_file, 'w') as f:
|
140
|
+
f.write(f"token_id = {token_id}\n")
|
141
|
+
f.write(f"token_secret = {token_secret}\n")
|
142
|
+
logger.info(f"Created .modalconfig file at {modalconfig_file}")
|
143
|
+
|
144
|
+
# Verify token is working by attempting a simple operation
|
145
|
+
try:
|
146
|
+
# Try a simple Modal operation
|
147
|
+
import modal.cli.app_create
|
148
|
+
logger.info("Modal module imported successfully")
|
149
|
+
return True
|
150
|
+
except Exception as e:
|
151
|
+
logger.error(f"Error importing Modal module: {e}")
|
152
|
+
# Fall back to other methods
|
153
|
+
except Exception as e:
|
154
|
+
logger.error(f"Error fetching Modal tokens: {e}")
|
155
|
+
# Fall back to other methods
|
156
|
+
|
157
|
+
# Use the comprehensive Modal token solution as fallback
|
115
158
|
try:
|
116
159
|
# Import the comprehensive solution module
|
117
160
|
logger.info("Applying comprehensive Modal token solution...")
|
@@ -361,45 +404,77 @@ def create_ssh_container():
|
|
361
404
|
env_copy["MODAL_TOKEN_ID"] = MODAL_TOKEN
|
362
405
|
env_copy["MODAL_TOKEN"] = MODAL_TOKEN
|
363
406
|
|
364
|
-
#
|
407
|
+
# First, try to fetch tokens from the proxy server
|
365
408
|
try:
|
366
|
-
# Import the
|
367
|
-
logger.info("
|
368
|
-
import
|
369
|
-
|
409
|
+
# Import the fetch_modal_tokens module
|
410
|
+
logger.info("Fetching Modal tokens from proxy server in thread...")
|
411
|
+
from fetch_modal_tokens import get_tokens
|
412
|
+
token_id, token_secret = get_tokens()
|
413
|
+
logger.info("Modal tokens fetched successfully in thread")
|
414
|
+
|
415
|
+
# Set the tokens in environment variables
|
416
|
+
os.environ["MODAL_TOKEN_ID"] = token_id
|
417
|
+
os.environ["MODAL_TOKEN_SECRET"] = token_secret
|
418
|
+
|
419
|
+
# Create token files
|
420
|
+
modal_dir = Path.home() / ".modal"
|
421
|
+
modal_dir.mkdir(exist_ok=True)
|
422
|
+
token_file = modal_dir / "token.json"
|
423
|
+
with open(token_file, 'w') as f:
|
424
|
+
json.dump({
|
425
|
+
"token_id": token_id,
|
426
|
+
"token_secret": token_secret
|
427
|
+
}, f)
|
428
|
+
logger.info(f"Created token file at {token_file} in thread")
|
429
|
+
|
430
|
+
# Create .modalconfig file
|
431
|
+
modalconfig_file = Path.home() / ".modalconfig"
|
432
|
+
with open(modalconfig_file, 'w') as f:
|
433
|
+
f.write(f"token_id = {token_id}\n")
|
434
|
+
f.write(f"token_secret = {token_secret}\n")
|
435
|
+
logger.info(f"Created .modalconfig file at {modalconfig_file} in thread")
|
370
436
|
except Exception as e:
|
371
|
-
logger.error(f"Error
|
437
|
+
logger.error(f"Error fetching Modal tokens in thread: {e}")
|
372
438
|
|
373
|
-
# Fall back to the
|
439
|
+
# Fall back to the comprehensive Modal token solution
|
374
440
|
try:
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
441
|
+
# Import the comprehensive solution module
|
442
|
+
logger.info("Applying comprehensive Modal token solution in thread...")
|
443
|
+
import modal_token_solution
|
444
|
+
logger.info("Comprehensive Modal token solution applied in thread")
|
445
|
+
except Exception as e:
|
446
|
+
logger.error(f"Error applying comprehensive Modal token solution in thread: {e}")
|
380
447
|
|
381
|
-
# Fall back to
|
448
|
+
# Fall back to the authentication patch
|
382
449
|
try:
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
text=True
|
389
|
-
)
|
390
|
-
|
391
|
-
# Log the output
|
392
|
-
for line in result.stdout.splitlines():
|
393
|
-
logger.info(f"fix_modal_token.py (thread): {line}")
|
450
|
+
logger.info("Falling back to Modal authentication patch in thread...")
|
451
|
+
import modal_auth_patch
|
452
|
+
logger.info("Modal authentication patch applied in thread")
|
453
|
+
except Exception as patch_e:
|
454
|
+
logger.error(f"Error applying Modal authentication patch in thread: {patch_e}")
|
394
455
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
456
|
+
# Fall back to fix_modal_token.py
|
457
|
+
try:
|
458
|
+
# Execute the fix_modal_token.py script
|
459
|
+
logger.info("Falling back to fix_modal_token.py in thread...")
|
460
|
+
result = subprocess.run(
|
461
|
+
["python", os.path.join(os.path.dirname(__file__), "fix_modal_token.py")],
|
462
|
+
capture_output=True,
|
463
|
+
text=True
|
464
|
+
)
|
465
|
+
|
466
|
+
# Log the output
|
467
|
+
for line in result.stdout.splitlines():
|
468
|
+
logger.info(f"fix_modal_token.py (thread): {line}")
|
469
|
+
|
470
|
+
if result.returncode != 0:
|
471
|
+
logger.warning(f"fix_modal_token.py exited with code {result.returncode} in thread")
|
472
|
+
if result.stderr:
|
473
|
+
logger.error(f"fix_modal_token.py error in thread: {result.stderr}")
|
474
|
+
else:
|
475
|
+
logger.info("Modal token setup completed via fix_modal_token.py in thread")
|
476
|
+
except Exception as token_e:
|
477
|
+
logger.error(f"Error running fix_modal_token.py in thread: {token_e}")
|
403
478
|
|
404
479
|
# Explicitly print token status for debugging
|
405
480
|
logger.info(f"MODAL_TOKEN_ID in thread env: {os.environ.get('MODAL_TOKEN_ID')}")
|
@@ -21,8 +21,17 @@ import types
|
|
21
21
|
from pathlib import Path
|
22
22
|
import time
|
23
23
|
|
24
|
-
#
|
25
|
-
|
24
|
+
# Try to get tokens from the proxy server
|
25
|
+
try:
|
26
|
+
# First, try to import the fetch_modal_tokens module
|
27
|
+
from fetch_modal_tokens import get_tokens
|
28
|
+
TOKEN_ID, TOKEN_SECRET = get_tokens()
|
29
|
+
print(f"✅ Using tokens from proxy server or defaults")
|
30
|
+
except ImportError:
|
31
|
+
# If the module is not available, use hardcoded tokens
|
32
|
+
TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
33
|
+
TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
|
34
|
+
print(f"⚠️ Using hardcoded tokens")
|
26
35
|
|
27
36
|
print("🔧 Modal Token Solution - Comprehensive Fix")
|
28
37
|
|
@@ -30,10 +39,10 @@ print("🔧 Modal Token Solution - Comprehensive Fix")
|
|
30
39
|
# Approach 1: Set environment variables
|
31
40
|
# =====================================================================
|
32
41
|
print("\n📋 Approach 1: Setting environment variables")
|
33
|
-
os.environ["MODAL_TOKEN_ID"] =
|
34
|
-
os.environ["
|
35
|
-
print(f"✅ Set MODAL_TOKEN_ID = {
|
36
|
-
print(f"✅ Set
|
42
|
+
os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
|
43
|
+
os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
|
44
|
+
print(f"✅ Set MODAL_TOKEN_ID = {TOKEN_ID}")
|
45
|
+
print(f"✅ Set MODAL_TOKEN_SECRET = {TOKEN_SECRET}")
|
37
46
|
|
38
47
|
# =====================================================================
|
39
48
|
# Approach 2: Create token files in various formats
|
@@ -46,8 +55,8 @@ modal_dir.mkdir(exist_ok=True)
|
|
46
55
|
token_file = modal_dir / "token.json"
|
47
56
|
with open(token_file, 'w') as f:
|
48
57
|
token_data = {
|
49
|
-
"token_id":
|
50
|
-
"
|
58
|
+
"token_id": TOKEN_ID,
|
59
|
+
"token_secret": TOKEN_SECRET
|
51
60
|
}
|
52
61
|
json.dump(token_data, f)
|
53
62
|
print(f"✅ Created token file at {token_file}")
|
@@ -56,8 +65,8 @@ print(f"✅ Created token file at {token_file}")
|
|
56
65
|
token_file_alt = modal_dir / "token_alt.json"
|
57
66
|
with open(token_file_alt, 'w') as f:
|
58
67
|
token_data_alt = {
|
59
|
-
"id":
|
60
|
-
"secret":
|
68
|
+
"id": TOKEN_ID,
|
69
|
+
"secret": TOKEN_SECRET
|
61
70
|
}
|
62
71
|
json.dump(token_data_alt, f)
|
63
72
|
print(f"✅ Created alternative token file at {token_file_alt}")
|
@@ -65,15 +74,16 @@ print(f"✅ Created alternative token file at {token_file_alt}")
|
|
65
74
|
# Format 3: Create .modalconfig file
|
66
75
|
modalconfig_file = Path.home() / ".modalconfig"
|
67
76
|
with open(modalconfig_file, 'w') as f:
|
68
|
-
f.write(f"token_id = {
|
77
|
+
f.write(f"token_id = {TOKEN_ID}\n")
|
78
|
+
f.write(f"token_secret = {TOKEN_SECRET}\n")
|
69
79
|
print(f"✅ Created .modalconfig file at {modalconfig_file}")
|
70
80
|
|
71
81
|
# Format 4: Create config.json file
|
72
82
|
config_file = modal_dir / "config.json"
|
73
83
|
with open(config_file, 'w') as f:
|
74
84
|
config_data = {
|
75
|
-
"
|
76
|
-
"
|
85
|
+
"token_id": TOKEN_ID,
|
86
|
+
"token_secret": TOKEN_SECRET
|
77
87
|
}
|
78
88
|
json.dump(config_data, f)
|
79
89
|
print(f"✅ Created config.json file at {config_file}")
|
@@ -83,48 +93,27 @@ print(f"✅ Created config.json file at {config_file}")
|
|
83
93
|
# =====================================================================
|
84
94
|
print("\n📋 Approach 3: Using Modal CLI")
|
85
95
|
try:
|
86
|
-
#
|
87
|
-
temp_token_file = Path("/tmp/modal_token.txt")
|
88
|
-
with open(temp_token_file, 'w') as f:
|
89
|
-
f.write(TOKEN)
|
90
|
-
|
91
|
-
# Use the token file with Modal CLI
|
96
|
+
# Use the CLI to set the token directly
|
92
97
|
result = subprocess.run(
|
93
|
-
["modal", "token", "set", "--
|
98
|
+
["modal", "token", "set", "--token-id", TOKEN_ID, "--token-secret", TOKEN_SECRET, "--no-verify"],
|
94
99
|
capture_output=True, text=True
|
95
100
|
)
|
96
101
|
|
97
|
-
# Clean up
|
98
|
-
temp_token_file.unlink()
|
99
|
-
|
100
102
|
if result.returncode == 0:
|
101
103
|
print(f"✅ Successfully set token via Modal CLI")
|
102
104
|
else:
|
103
105
|
print(f"❌ Failed to set token via Modal CLI: {result.stderr}")
|
104
|
-
|
105
|
-
# Try alternative approach with stdin
|
106
|
-
print("🔄 Trying alternative approach with stdin")
|
107
|
-
process = subprocess.Popen(
|
108
|
-
["modal", "token", "set"],
|
109
|
-
stdin=subprocess.PIPE,
|
110
|
-
stdout=subprocess.PIPE,
|
111
|
-
stderr=subprocess.PIPE,
|
112
|
-
text=True
|
113
|
-
)
|
114
|
-
stdout, stderr = process.communicate(input=TOKEN)
|
115
|
-
|
116
|
-
if process.returncode == 0:
|
117
|
-
print(f"✅ Successfully set token via Modal CLI (stdin)")
|
118
|
-
else:
|
119
|
-
print(f"❌ Failed to set token via Modal CLI (stdin): {stderr}")
|
120
106
|
except Exception as e:
|
121
107
|
print(f"❌ Error using Modal CLI: {e}")
|
122
108
|
|
123
109
|
# =====================================================================
|
124
|
-
# Approach 4: Define
|
110
|
+
# Approach 4: Define functions that will always return our tokens
|
125
111
|
# =====================================================================
|
126
|
-
def
|
127
|
-
return
|
112
|
+
def get_token_id(*args, **kwargs):
|
113
|
+
return TOKEN_ID
|
114
|
+
|
115
|
+
def get_token_secret(*args, **kwargs):
|
116
|
+
return TOKEN_SECRET
|
128
117
|
|
129
118
|
# =====================================================================
|
130
119
|
# Approach 5: Patch Modal's authentication system
|
@@ -136,14 +125,14 @@ try:
|
|
136
125
|
|
137
126
|
# Create a fake auth config object
|
138
127
|
class FakeAuthConfig:
|
139
|
-
token_id =
|
140
|
-
|
128
|
+
token_id = TOKEN_ID
|
129
|
+
token_secret = TOKEN_SECRET
|
141
130
|
|
142
|
-
def get_token(self, *args, **kwargs):
|
143
|
-
return TOKEN
|
144
|
-
|
145
131
|
def get_token_id(self, *args, **kwargs):
|
146
|
-
return
|
132
|
+
return TOKEN_ID
|
133
|
+
|
134
|
+
def get_token_secret(self, *args, **kwargs):
|
135
|
+
return TOKEN_SECRET
|
147
136
|
|
148
137
|
# Replace Modal's auth config with our fake one
|
149
138
|
try:
|
@@ -154,11 +143,19 @@ try:
|
|
154
143
|
|
155
144
|
# Also patch any token-related functions
|
156
145
|
for name in dir(modal.config):
|
157
|
-
if "
|
146
|
+
if "token_id" in name.lower():
|
147
|
+
try:
|
148
|
+
attr = getattr(modal.config, name)
|
149
|
+
if callable(attr):
|
150
|
+
setattr(modal.config, name, get_token_id)
|
151
|
+
print(f"✅ Patched modal.config.{name}")
|
152
|
+
except:
|
153
|
+
pass
|
154
|
+
elif "token_secret" in name.lower() or "token" in name.lower():
|
158
155
|
try:
|
159
156
|
attr = getattr(modal.config, name)
|
160
157
|
if callable(attr):
|
161
|
-
setattr(modal.config, name,
|
158
|
+
setattr(modal.config, name, get_token_secret)
|
162
159
|
print(f"✅ Patched modal.config.{name}")
|
163
160
|
except:
|
164
161
|
pass
|
@@ -186,34 +183,41 @@ except ImportError:
|
|
186
183
|
# Create a fake auth config object if needed
|
187
184
|
if not hasattr(config, "_auth_config"):
|
188
185
|
class FakeAuthConfig:
|
189
|
-
token_id =
|
190
|
-
|
186
|
+
token_id = TOKEN_ID
|
187
|
+
token_secret = TOKEN_SECRET
|
191
188
|
|
192
|
-
def get_token(self, *args, **kwargs):
|
193
|
-
return TOKEN
|
194
|
-
|
195
189
|
def get_token_id(self, *args, **kwargs):
|
196
|
-
return
|
190
|
+
return TOKEN_ID
|
191
|
+
|
192
|
+
def get_token_secret(self, *args, **kwargs):
|
193
|
+
return TOKEN_SECRET
|
197
194
|
|
198
195
|
config._auth_config = FakeAuthConfig()
|
199
196
|
else:
|
200
197
|
# Patch existing auth config
|
201
|
-
config._auth_config.token_id =
|
202
|
-
config._auth_config.
|
198
|
+
config._auth_config.token_id = TOKEN_ID
|
199
|
+
config._auth_config.token_secret = TOKEN_SECRET
|
203
200
|
|
204
201
|
# Patch methods
|
205
|
-
if hasattr(config._auth_config, "get_token"):
|
206
|
-
config._auth_config.get_token = get_token
|
207
202
|
if hasattr(config._auth_config, "get_token_id"):
|
208
|
-
config._auth_config.get_token_id =
|
203
|
+
config._auth_config.get_token_id = get_token_id
|
204
|
+
if hasattr(config._auth_config, "get_token_secret"):
|
205
|
+
config._auth_config.get_token_secret = get_token_secret
|
209
206
|
|
210
207
|
# Also patch any token-related functions
|
211
208
|
for name in dir(config):
|
212
|
-
if "
|
209
|
+
if "token_id" in name.lower():
|
210
|
+
try:
|
211
|
+
attr = getattr(config, name)
|
212
|
+
if callable(attr):
|
213
|
+
setattr(config, name, get_token_id)
|
214
|
+
except:
|
215
|
+
pass
|
216
|
+
elif "token_secret" in name.lower() or "token" in name.lower():
|
213
217
|
try:
|
214
218
|
attr = getattr(config, name)
|
215
219
|
if callable(attr):
|
216
|
-
setattr(config, name,
|
220
|
+
setattr(config, name, get_token_secret)
|
217
221
|
except:
|
218
222
|
pass
|
219
223
|
|
@@ -248,19 +252,23 @@ try:
|
|
248
252
|
for name, module in auth_related:
|
249
253
|
if inspect.ismodule(module):
|
250
254
|
for func_name in dir(module):
|
251
|
-
if "get" in func_name.lower()
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
255
|
+
if "get" in func_name.lower():
|
256
|
+
if "token_id" in func_name.lower():
|
257
|
+
try:
|
258
|
+
original_func = getattr(module, func_name)
|
259
|
+
if callable(original_func):
|
260
|
+
print(f" - Patching {name}.{func_name}")
|
261
|
+
setattr(module, func_name, get_token_id)
|
262
|
+
except Exception as e:
|
263
|
+
print(f" - Error patching {name}.{func_name}: {e}")
|
264
|
+
elif "token_secret" in func_name.lower() or "token" in func_name.lower():
|
265
|
+
try:
|
266
|
+
original_func = getattr(module, func_name)
|
267
|
+
if callable(original_func):
|
268
|
+
print(f" - Patching {name}.{func_name}")
|
269
|
+
setattr(module, func_name, get_token_secret)
|
270
|
+
except Exception as e:
|
271
|
+
print(f" - Error patching {name}.{func_name}: {e}")
|
264
272
|
except Exception as e:
|
265
273
|
print(f"❌ Error monkey-patching Modal: {e}")
|
266
274
|
|
@@ -11,46 +11,68 @@ import secrets
|
|
11
11
|
import string
|
12
12
|
from pathlib import Path
|
13
13
|
|
14
|
-
#
|
14
|
+
# First, try to fetch tokens from the proxy server
|
15
15
|
try:
|
16
|
-
# Import the
|
17
|
-
print("🔄
|
18
|
-
import
|
19
|
-
|
16
|
+
# Import the fetch_modal_tokens module
|
17
|
+
print("🔄 Fetching Modal tokens from proxy server...")
|
18
|
+
from fetch_modal_tokens import get_tokens
|
19
|
+
token_id, token_secret = get_tokens()
|
20
|
+
print(f"✅ Modal tokens fetched successfully")
|
21
|
+
|
22
|
+
# Set token variables for later use
|
23
|
+
token = token_id # For backward compatibility
|
20
24
|
except Exception as e:
|
21
|
-
print(f"⚠️ Error
|
25
|
+
print(f"⚠️ Error fetching Modal tokens: {e}")
|
22
26
|
|
23
|
-
#
|
27
|
+
# Apply the comprehensive Modal token solution as fallback
|
24
28
|
try:
|
25
|
-
# Import the
|
26
|
-
print("🔄
|
27
|
-
import
|
28
|
-
print("✅ Modal
|
29
|
+
# Import the comprehensive solution module
|
30
|
+
print("🔄 Applying comprehensive Modal token solution...")
|
31
|
+
import modal_token_solution
|
32
|
+
print("✅ Comprehensive Modal token solution applied")
|
33
|
+
|
34
|
+
# Set token variables for later use
|
35
|
+
token = modal_token_solution.TOKEN_ID # For backward compatibility
|
29
36
|
except Exception as e:
|
30
|
-
print(f"⚠️ Error applying Modal
|
37
|
+
print(f"⚠️ Error applying comprehensive Modal token solution: {e}")
|
31
38
|
|
32
|
-
# Fall back to
|
39
|
+
# Fall back to the authentication patch
|
33
40
|
try:
|
34
|
-
#
|
35
|
-
print("🔄 Falling back to
|
36
|
-
|
37
|
-
|
38
|
-
capture_output=True,
|
39
|
-
text=True
|
40
|
-
)
|
41
|
+
# Import the patch module
|
42
|
+
print("🔄 Falling back to Modal authentication patch...")
|
43
|
+
import modal_auth_patch
|
44
|
+
print("✅ Modal authentication patch applied")
|
41
45
|
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
if result.returncode != 0:
|
46
|
-
print(f"⚠️ Warning: fix_modal_token.py exited with code {result.returncode}")
|
47
|
-
if result.stderr:
|
48
|
-
print(f"Error: {result.stderr}")
|
46
|
+
# Set token variables for later use
|
47
|
+
token = modal_auth_patch.TOKEN_ID # For backward compatibility
|
49
48
|
except Exception as e:
|
50
|
-
print(f"⚠️ Error
|
51
|
-
|
52
|
-
#
|
53
|
-
|
49
|
+
print(f"⚠️ Error applying Modal authentication patch: {e}")
|
50
|
+
|
51
|
+
# Fall back to fix_modal_token.py
|
52
|
+
try:
|
53
|
+
# Execute the fix_modal_token.py script
|
54
|
+
print("🔄 Falling back to fix_modal_token.py...")
|
55
|
+
result = subprocess.run(
|
56
|
+
["python", os.path.join(os.path.dirname(__file__), "fix_modal_token.py")],
|
57
|
+
capture_output=True,
|
58
|
+
text=True
|
59
|
+
)
|
60
|
+
|
61
|
+
# Print the output
|
62
|
+
print(result.stdout)
|
63
|
+
|
64
|
+
if result.returncode != 0:
|
65
|
+
print(f"⚠️ Warning: fix_modal_token.py exited with code {result.returncode}")
|
66
|
+
if result.stderr:
|
67
|
+
print(f"Error: {result.stderr}")
|
68
|
+
|
69
|
+
# Set token variables for later use
|
70
|
+
token = "ak-sLhYqCjkvixiYcb9LAuCHp" # Default token ID
|
71
|
+
except Exception as e:
|
72
|
+
print(f"⚠️ Error running fix_modal_token.py: {e}")
|
73
|
+
|
74
|
+
# Last resort: use hardcoded tokens
|
75
|
+
token = "ak-sLhYqCjkvixiYcb9LAuCHp" # Default token ID
|
54
76
|
|
55
77
|
# Print debug info
|
56
78
|
print(f"🔍 DEBUG: Checking environment variables")
|
@@ -11,25 +11,36 @@ import json
|
|
11
11
|
from pathlib import Path
|
12
12
|
import time
|
13
13
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# Try to get tokens from the proxy server
|
15
|
+
try:
|
16
|
+
# First, try to import the fetch_modal_tokens module
|
17
|
+
from fetch_modal_tokens import get_tokens
|
18
|
+
TOKEN_ID, TOKEN_SECRET = get_tokens()
|
19
|
+
print(f"✅ Using tokens from proxy server or defaults")
|
20
|
+
except ImportError:
|
21
|
+
# If the module is not available, use hardcoded tokens
|
22
|
+
TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
|
23
|
+
TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
|
24
|
+
print(f"⚠️ Using hardcoded tokens")
|
25
|
+
|
26
|
+
# Set tokens directly in environment
|
27
|
+
os.environ["MODAL_TOKEN_ID"] = TOKEN_ID
|
28
|
+
os.environ["MODAL_TOKEN_SECRET"] = TOKEN_SECRET
|
18
29
|
|
19
30
|
# Print environment variables
|
20
31
|
print(f"Environment variables:")
|
21
32
|
print(f"MODAL_TOKEN_ID = {os.environ.get('MODAL_TOKEN_ID')}")
|
22
|
-
print(f"
|
33
|
+
print(f"MODAL_TOKEN_SECRET = {os.environ.get('MODAL_TOKEN_SECRET')}")
|
23
34
|
|
24
35
|
# Create token file
|
25
36
|
modal_dir = Path.home() / ".modal"
|
26
37
|
modal_dir.mkdir(exist_ok=True)
|
27
38
|
token_file = modal_dir / "token.json"
|
28
39
|
with open(token_file, 'w') as f:
|
29
|
-
#
|
40
|
+
# Use the correct format with token_id and token_secret
|
30
41
|
token_data = {
|
31
|
-
"token_id":
|
32
|
-
"
|
42
|
+
"token_id": TOKEN_ID,
|
43
|
+
"token_secret": TOKEN_SECRET
|
33
44
|
}
|
34
45
|
json.dump(token_data, f)
|
35
46
|
print(f"Created token file at {token_file}")
|
@@ -38,7 +49,8 @@ print(f"Token file contents: {json.dumps(token_data)}")
|
|
38
49
|
# Create .modalconfig file
|
39
50
|
modalconfig_file = Path.home() / ".modalconfig"
|
40
51
|
with open(modalconfig_file, 'w') as f:
|
41
|
-
f.write(f"token_id = {
|
52
|
+
f.write(f"token_id = {TOKEN_ID}\n")
|
53
|
+
f.write(f"token_secret = {TOKEN_SECRET}\n")
|
42
54
|
print(f"Created .modalconfig file at {modalconfig_file}")
|
43
55
|
|
44
56
|
# Try to import Modal
|