gitarsenal-cli 1.1.19 → 1.1.21

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitarsenal-cli",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "CLI tool for creating Modal sandboxes with GitHub repositories",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -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. **modal_token_solution.py**: The main comprehensive solution that combines all approaches.
10
- 2. **modal_auth_patch.py**: A direct patch for Modal's authentication system.
11
- 3. **fix_modal_token.py**: A basic token setup script.
12
- 4. **fix_modal_token_advanced.py**: An advanced version with more approaches.
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. **Environment Variables**: Sets `MODAL_TOKEN_ID` and `MODAL_TOKEN` environment variables.
19
- 2. **Token Files**: Creates token files in various formats and locations that Modal might look for.
20
- 3. **Modal CLI**: Attempts to use the Modal CLI to set the token.
21
- 4. **Direct Patching**: Directly patches Modal's authentication system to always return our token.
22
- 5. **Monkey Patching**: Monkey-patches Modal's import system to inject our token.
23
- 6. **Authentication Testing**: Tests that the authentication works by creating a simple Modal app.
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 token
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 token value is correct (`ak-eNMIXRdfbvpxIXcSHKPFQW`).
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. Try running the scripts manually to see detailed output.
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 Value**: We use a hardcoded token (`ak-eNMIXRdfbvpxIXcSHKPFQW`) that works with our Modal account.
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,183 @@
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
+ import subprocess
13
+ from pathlib import Path
14
+
15
+ # Default tokens to use if we can't fetch from the server
16
+ DEFAULT_TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
17
+ DEFAULT_TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq"
18
+
19
+ def fetch_tokens_from_proxy(proxy_url=None, api_key=None):
20
+ """
21
+ Fetch Modal tokens from the proxy server.
22
+
23
+ Args:
24
+ proxy_url: URL of the proxy server
25
+ api_key: API key for authentication
26
+
27
+ Returns:
28
+ tuple: (token_id, token_secret) if successful, (None, None) otherwise
29
+ """
30
+ # Use environment variables if not provided
31
+ if not proxy_url:
32
+ proxy_url = os.environ.get("MODAL_PROXY_URL")
33
+ if proxy_url:
34
+ print(f"📋 Using proxy URL from environment: {proxy_url}")
35
+
36
+ if not api_key:
37
+ api_key = os.environ.get("MODAL_PROXY_API_KEY")
38
+ if api_key:
39
+ print(f"📋 Using API key from environment (length: {len(api_key)})")
40
+
41
+ # Check if we have the necessary information
42
+ if not proxy_url:
43
+ print("❌ No proxy URL provided or found in environment")
44
+ print("💡 Set MODAL_PROXY_URL environment variable or use --proxy-url argument")
45
+ return None, None
46
+
47
+ if not api_key:
48
+ print("❌ No API key provided or found in environment")
49
+ print("💡 Set MODAL_PROXY_API_KEY environment variable or use --proxy-api-key argument")
50
+ return None, None
51
+
52
+ # Ensure the URL ends with a slash
53
+ if not proxy_url.endswith("/"):
54
+ proxy_url += "/"
55
+
56
+ # Add the endpoint for fetching tokens
57
+ token_url = f"{proxy_url}api/modal-tokens"
58
+
59
+ try:
60
+ # Make the request
61
+ print(f"🔄 Fetching tokens from {token_url}")
62
+ response = requests.get(
63
+ token_url,
64
+ headers={"X-API-Key": api_key}
65
+ )
66
+
67
+ # Check if the request was successful
68
+ if response.status_code == 200:
69
+ data = response.json()
70
+ token_id = data.get("token_id")
71
+ token_secret = data.get("token_secret")
72
+
73
+ if token_id and token_secret:
74
+ print("✅ Successfully fetched tokens from proxy server")
75
+ return token_id, token_secret
76
+ else:
77
+ print("❌ Tokens not found in response")
78
+ return None, None
79
+ else:
80
+ print(f"❌ Failed to fetch tokens: {response.status_code} - {response.text}")
81
+ return None, None
82
+ except Exception as e:
83
+ print(f"❌ Error fetching tokens: {e}")
84
+ return None, None
85
+
86
+ def get_tokens():
87
+ """
88
+ Get Modal tokens, trying to fetch from the proxy server first.
89
+ Also sets the tokens in environment variables.
90
+
91
+ Returns:
92
+ tuple: (token_id, token_secret)
93
+ """
94
+ # Try to fetch from the proxy server
95
+ token_id, token_secret = fetch_tokens_from_proxy()
96
+
97
+ # If we couldn't fetch from the server, use the default tokens
98
+ if not token_id or not token_secret:
99
+ print("⚠️ Using default tokens")
100
+ token_id = DEFAULT_TOKEN_ID
101
+ token_secret = DEFAULT_TOKEN_SECRET
102
+
103
+ # Set the tokens in environment variables
104
+ os.environ["MODAL_TOKEN_ID"] = token_id
105
+ os.environ["MODAL_TOKEN_SECRET"] = token_secret
106
+ print(f"✅ Set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET environment variables")
107
+
108
+ return token_id, token_secret
109
+
110
+ if __name__ == "__main__":
111
+ # Parse command-line arguments if run directly
112
+ import argparse
113
+
114
+ parser = argparse.ArgumentParser(description='Fetch Modal tokens from the proxy server')
115
+ parser.add_argument('--proxy-url', help='URL of the proxy server')
116
+ parser.add_argument('--proxy-api-key', help='API key for the proxy server')
117
+ args = parser.parse_args()
118
+
119
+ # Set proxy URL and API key in environment variables if provided
120
+ if args.proxy_url:
121
+ os.environ["MODAL_PROXY_URL"] = args.proxy_url
122
+ print(f"✅ Set MODAL_PROXY_URL from command line: {args.proxy_url}")
123
+
124
+ if args.proxy_api_key:
125
+ os.environ["MODAL_PROXY_API_KEY"] = args.proxy_api_key
126
+ print(f"✅ Set MODAL_PROXY_API_KEY from command line")
127
+
128
+ # Get tokens
129
+ token_id, token_secret = get_tokens()
130
+ print(f"Token ID: {token_id}")
131
+ print(f"Token Secret: {token_secret}")
132
+
133
+ # Check if tokens are set in environment variables
134
+ print(f"\n🔍 DEBUG: Checking environment variables")
135
+ print(f"🔍 MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
136
+ print(f"🔍 MODAL_TOKEN_SECRET exists: {'Yes' if os.environ.get('MODAL_TOKEN_SECRET') else 'No'}")
137
+ if os.environ.get('MODAL_TOKEN_ID'):
138
+ print(f"🔍 MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
139
+ if os.environ.get('MODAL_TOKEN_SECRET'):
140
+ print(f"🔍 MODAL_TOKEN_SECRET length: {len(os.environ.get('MODAL_TOKEN_SECRET'))}")
141
+
142
+ # Write the tokens to a file for use by other scripts
143
+ tokens_file = Path(__file__).parent / "modal_tokens.json"
144
+ with open(tokens_file, 'w') as f:
145
+ json.dump({
146
+ "token_id": token_id,
147
+ "token_secret": token_secret
148
+ }, f)
149
+ print(f"\n✅ Tokens written to {tokens_file}")
150
+
151
+ # Create token files in standard locations
152
+ modal_dir = Path.home() / ".modal"
153
+ modal_dir.mkdir(exist_ok=True)
154
+ token_file = modal_dir / "token.json"
155
+ with open(token_file, 'w') as f:
156
+ json.dump({
157
+ "token_id": token_id,
158
+ "token_secret": token_secret
159
+ }, f)
160
+ print(f"✅ Created token file at {token_file}")
161
+
162
+ modalconfig_file = Path.home() / ".modalconfig"
163
+ with open(modalconfig_file, 'w') as f:
164
+ f.write(f"token_id = {token_id}\n")
165
+ f.write(f"token_secret = {token_secret}\n")
166
+ print(f"✅ Created .modalconfig file at {modalconfig_file}")
167
+
168
+ # Try to use the Modal CLI to set the token
169
+ try:
170
+ print(f"\n🔄 Setting token via Modal CLI...")
171
+ result = subprocess.run(
172
+ ["modal", "token", "set", "--token-id", token_id, "--token-secret", token_secret, "--profile=fr8mafia", "--no-verify"],
173
+ capture_output=True, text=True
174
+ )
175
+
176
+ if result.returncode == 0:
177
+ print(f"✅ Successfully set token via Modal CLI")
178
+ else:
179
+ print(f"❌ Failed to set token via Modal CLI: {result.stderr}")
180
+ except Exception as e:
181
+ print(f"❌ Error using Modal CLI: {e}")
182
+
183
+ print(f"\n✅ All token setup completed successfully")
@@ -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
- # The token to use
42
- TOKEN = "ak-eNMIXRdfbvpxIXcSHKPFQW"
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"] = TOKEN
48
- os.environ["MODAL_TOKEN"] = TOKEN
49
- print(f"✅ Set MODAL_TOKEN_ID and MODAL_TOKEN environment variables")
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": "{TOKEN}", "token": "{TOKEN}"}}')
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 = {TOKEN}\n")
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
- # The token to use
23
- TOKEN = "ak-eNMIXRdfbvpxIXcSHKPFQW"
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"] = TOKEN
30
- os.environ["MODAL_TOKEN"] = TOKEN
31
- print(f"✅ Set MODAL_TOKEN_ID = {TOKEN}")
32
- print(f"✅ Set MODAL_TOKEN = {TOKEN}")
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": TOKEN,
44
- "token": TOKEN
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": TOKEN,
54
- "secret": TOKEN
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 = {TOKEN}\n")
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
- "token": TOKEN,
70
- "token_id": TOKEN
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
- # Create a temporary token file
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", "--from-file", str(temp_token_file)],
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.token_id
113
+ # Approach 4.1: Set token via _auth_config
128
114
  if hasattr(modal.config, '_auth_config'):
129
- modal.config._auth_config.token_id = TOKEN
130
- print(f"✅ Set token via _auth_config.token_id")
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 token via _auth_config: {e}")
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(TOKEN)
138
- print(f"✅ Set token via set_token()")
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 token via set_token(): {e}")
127
+ print(f"❌ Error setting tokens via set_token(): {e}")
141
128
 
142
129
  try:
143
- # Approach 4.3: Set token via Config.token_id
130
+ # Approach 4.3: Set token via Config
144
131
  if hasattr(modal.config, 'Config'):
145
- modal.config.Config.token_id = TOKEN
146
- print(f"✅ Set token via Config.token_id")
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 token via Config.token_id: {e}")
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, "token") or hasattr(attr, "token_id"):
158
- print(f" - Setting token in {name}")
159
- if hasattr(attr, "token"):
160
- setattr(attr, "token", TOKEN)
161
- if hasattr(attr, "token_id"):
162
- setattr(attr, "token_id", TOKEN)
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 token in {name}: {e}")
152
+ print(f" - Error setting tokens in {name}: {e}")
165
153
  except Exception as e:
166
- print(f"❌ Error setting token in Modal config: {e}")
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() and ("token" in func_name.lower() or "auth" in func_name.lower() or "cred" in func_name.lower()):
191
- try:
192
- original_func = getattr(module, func_name)
193
- if callable(original_func):
194
- print(f" - Patching {name}.{func_name}")
195
-
196
- def patched_func(*args, **kwargs):
197
- print(f" - Patched function called, returning token")
198
- return TOKEN
199
-
200
- setattr(module, func_name, patched_func)
201
- except Exception as e:
202
- print(f" - Error patching {name}.{func_name}: {e}")
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