gitarsenal-cli 1.1.18 → 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.
@@ -11,56 +11,82 @@ import secrets
11
11
  import string
12
12
  from pathlib import Path
13
13
 
14
- # Set up Modal token directly before importing modal
14
+ # First, try to fetch tokens from the proxy server
15
15
  try:
16
- # Create the token file directly in the expected location
17
- modal_dir = Path.home() / ".modal"
18
- modal_dir.mkdir(exist_ok=True)
19
-
20
- # Use the token from environment or a default one
21
- # Modal tokens are in the format: ak-xxxxxxxxxxxxxxxxxx
22
- token = os.environ.get("MODAL_TOKEN_ID") or os.environ.get("MODAL_TOKEN") or "ak-eNMIXRdfbvpxIXcSHKPFQW"
23
-
24
- # Set both environment variables
25
- os.environ["MODAL_TOKEN_ID"] = token
26
- os.environ["MODAL_TOKEN"] = token
27
-
28
- # Create the token file that Modal expects
29
- token_file = modal_dir / "token.json"
30
- with open(token_file, 'w') as f:
31
- f.write(f'{{"token_id": "{token}", "token": "{token}"}}')
32
- print(f"✅ Created Modal token file at {token_file}")
33
-
34
- # Print debug info
35
- print(f"🔍 DEBUG: Checking environment variables")
36
- print(f"🔍 MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
37
- print(f"🔍 MODAL_TOKEN exists: {'Yes' if os.environ.get('MODAL_TOKEN') else 'No'}")
38
- if os.environ.get('MODAL_TOKEN_ID'):
39
- print(f"🔍 MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
40
- if os.environ.get('MODAL_TOKEN'):
41
- print(f"🔍 MODAL_TOKEN length: {len(os.environ.get('MODAL_TOKEN'))}")
42
- print(f"✅ Modal token found (length: {len(token)})")
43
-
44
- # Create a .modalconfig file as an alternative method
45
- modalconfig_file = Path.home() / ".modalconfig"
46
- with open(modalconfig_file, 'w') as f:
47
- f.write(f"token_id = {token}\n")
48
- print(f"✅ Created .modalconfig file at {modalconfig_file}")
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
49
24
  except Exception as e:
50
- print(f"⚠️ Error setting up Modal token: {e}")
25
+ print(f"⚠️ Error fetching Modal tokens: {e}")
26
+
27
+ # Apply the comprehensive Modal token solution as fallback
28
+ try:
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
36
+ except Exception as e:
37
+ print(f"⚠️ Error applying comprehensive Modal token solution: {e}")
38
+
39
+ # Fall back to the authentication patch
40
+ try:
41
+ # Import the patch module
42
+ print("🔄 Falling back to Modal authentication patch...")
43
+ import modal_auth_patch
44
+ print("✅ Modal authentication patch applied")
45
+
46
+ # Set token variables for later use
47
+ token = modal_auth_patch.TOKEN_ID # For backward compatibility
48
+ except Exception as e:
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
76
+
77
+ # Print debug info
78
+ print(f"🔍 DEBUG: Checking environment variables")
79
+ print(f"🔍 MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
80
+ print(f"🔍 MODAL_TOKEN exists: {'Yes' if os.environ.get('MODAL_TOKEN') else 'No'}")
81
+ if os.environ.get('MODAL_TOKEN_ID'):
82
+ print(f"🔍 MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
83
+ if os.environ.get('MODAL_TOKEN'):
84
+ print(f"🔍 MODAL_TOKEN length: {len(os.environ.get('MODAL_TOKEN'))}")
85
+ print(f"✅ Modal token setup completed")
51
86
 
52
87
  # Import modal after token setup
53
88
  import modal
54
89
 
55
- # Explicitly set the token in Modal's config
56
- try:
57
- # Try to directly configure Modal with the token
58
- import modal.config
59
- modal.config._auth_config.token_id = token
60
- print(f"✅ Explicitly set token in Modal config")
61
- except Exception as e:
62
- print(f"⚠️ Error setting token in Modal config: {e}")
63
-
64
90
  def handle_interactive_input(prompt, is_password=False):
65
91
  """Handle interactive input from the user with optional password masking"""
66
92
  print("\n" + "="*60)
@@ -2147,36 +2173,28 @@ def create_modal_ssh_container(gpu_type, repo_url=None, repo_name=None, setup_co
2147
2173
  if modal_token_id:
2148
2174
  print(f"✅ Modal token found (length: {len(modal_token_id)})")
2149
2175
 
2150
- # Set up Modal token using multiple approaches
2176
+ # Use the comprehensive fix_modal_token script
2151
2177
  try:
2152
- # 1. Create token file
2153
- from pathlib import Path
2154
- modal_dir = Path.home() / ".modal"
2155
- modal_dir.mkdir(exist_ok=True)
2156
- token_file = modal_dir / "token.json"
2178
+ # Execute the fix_modal_token.py script
2179
+ import subprocess
2180
+ print(f"🔄 Running fix_modal_token.py to set up Modal token...")
2181
+ result = subprocess.run(
2182
+ ["python", os.path.join(os.path.dirname(__file__), "fix_modal_token.py")],
2183
+ capture_output=True,
2184
+ text=True
2185
+ )
2157
2186
 
2158
- print(f"🔄 Creating Modal token file (token length: {len(modal_token_id)})")
2159
- with open(token_file, 'w') as f:
2160
- f.write(f'{{"token_id": "{modal_token_id}", "token": "{modal_token_id}"}}')
2161
- print(f"✅ Modal token file created at {token_file}")
2187
+ # Print the output
2188
+ print(result.stdout)
2162
2189
 
2163
- # 2. Create .modalconfig file
2164
- modalconfig_file = Path.home() / ".modalconfig"
2165
- with open(modalconfig_file, 'w') as f:
2166
- f.write(f"token_id = {modal_token_id}\n")
2167
- print(f"✅ Created .modalconfig file at {modalconfig_file}")
2168
-
2169
- # 3. Try to directly configure Modal
2170
- import modal.config
2171
- modal.config._auth_config.token_id = modal_token_id
2172
- print(f"✅ Explicitly set token in Modal config")
2173
-
2174
- # 4. Set environment variables again to be sure
2175
- os.environ["MODAL_TOKEN_ID"] = modal_token_id
2176
- os.environ["MODAL_TOKEN"] = modal_token_id
2177
- print(f"✅ Reset environment variables with token")
2190
+ if result.returncode != 0:
2191
+ print(f"⚠️ Warning: fix_modal_token.py exited with code {result.returncode}")
2192
+ if result.stderr:
2193
+ print(f"Error: {result.stderr}")
2194
+
2195
+ print(f"✅ Modal token setup completed")
2178
2196
  except Exception as e:
2179
- print(f"⚠️ Error setting up Modal token: {e}")
2197
+ print(f"⚠️ Error running fix_modal_token.py: {e}")
2180
2198
  else:
2181
2199
  print("❌ No Modal token found in environment variables")
2182
2200
  # Try to get from file as a last resort
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test Modal Authentication
4
+
5
+ This script tests different approaches to authenticate with Modal.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import json
11
+ from pathlib import Path
12
+ import time
13
+
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
29
+
30
+ # Print environment variables
31
+ print(f"Environment variables:")
32
+ print(f"MODAL_TOKEN_ID = {os.environ.get('MODAL_TOKEN_ID')}")
33
+ print(f"MODAL_TOKEN_SECRET = {os.environ.get('MODAL_TOKEN_SECRET')}")
34
+
35
+ # Create token file
36
+ modal_dir = Path.home() / ".modal"
37
+ modal_dir.mkdir(exist_ok=True)
38
+ token_file = modal_dir / "token.json"
39
+ with open(token_file, 'w') as f:
40
+ # Use the correct format with token_id and token_secret
41
+ token_data = {
42
+ "token_id": TOKEN_ID,
43
+ "token_secret": TOKEN_SECRET
44
+ }
45
+ json.dump(token_data, f)
46
+ print(f"Created token file at {token_file}")
47
+ print(f"Token file contents: {json.dumps(token_data)}")
48
+
49
+ # Create .modalconfig file
50
+ modalconfig_file = Path.home() / ".modalconfig"
51
+ with open(modalconfig_file, 'w') as f:
52
+ f.write(f"token_id = {TOKEN_ID}\n")
53
+ f.write(f"token_secret = {TOKEN_SECRET}\n")
54
+ print(f"Created .modalconfig file at {modalconfig_file}")
55
+
56
+ # Try to import Modal
57
+ print("\nTrying to import Modal...")
58
+ try:
59
+ import modal
60
+ print("✅ Successfully imported Modal")
61
+ except Exception as e:
62
+ print(f"❌ Error importing Modal: {e}")
63
+
64
+ # Try to create a simple Modal app
65
+ print("\nTrying to create a Modal app...")
66
+ try:
67
+ app = modal.App("test-auth")
68
+ print("✅ Successfully created Modal app")
69
+ except Exception as e:
70
+ print(f"❌ Error creating Modal app: {e}")
71
+
72
+ # Try to create a simple Modal function
73
+ print("\nTrying to create a Modal function...")
74
+ try:
75
+ @app.function()
76
+ def hello():
77
+ return "Hello, world!"
78
+
79
+ print("✅ Successfully created Modal function")
80
+ except Exception as e:
81
+ print(f"❌ Error creating Modal function: {e}")
82
+
83
+ # Try to run the function
84
+ print("\nTrying to run the Modal function...")
85
+ try:
86
+ with app.run():
87
+ result = hello.remote()
88
+ print(f"✅ Successfully ran Modal function: {result}")
89
+ except Exception as e:
90
+ print(f"❌ Error running Modal function: {e}")
91
+
92
+ print("\nDone testing Modal authentication.")