gitarsenal-cli 1.4.3 → 1.4.4

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.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "CLI tool for creating Modal sandboxes with GitHub repositories",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -2,7 +2,7 @@
2
2
  """
3
3
  Fetch Modal Tokens
4
4
 
5
- This script fetches Modal tokens from the GitArsenal API.
5
+ This script fetches Modal tokens from the proxy server.
6
6
  """
7
7
 
8
8
  import os
@@ -12,108 +12,144 @@ import requests
12
12
  import subprocess
13
13
  from pathlib import Path
14
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"
15
+ def fetch_default_tokens_from_gitarsenal():
16
+ """
17
+ Fetch default Modal tokens from gitarsenal.dev API.
18
+
19
+ Returns:
20
+ tuple: (token_id, token_secret) if successful, (None, None) otherwise
21
+ """
22
+ endpoint = "https://gitarsenal.dev/api/credentials"
23
+
24
+ try:
25
+ headers = {
26
+ 'User-Agent': 'Python-Modal-Token-Fetcher/1.0',
27
+ 'Accept': 'application/json'
28
+ }
29
+
30
+ print(f"šŸ”— Fetching default tokens from: {endpoint}")
31
+
32
+ response = requests.get(endpoint, headers=headers, timeout=30)
33
+
34
+ print(f"šŸ“Š Status: {response.status_code}")
35
+
36
+ if response.status_code == 200:
37
+ try:
38
+ data = response.json()
39
+ token_id = data.get("modalTokenId")
40
+ token_secret = data.get("modalTokenSecret")
41
+
42
+ if token_id and token_secret:
43
+ print("āœ… Successfully fetched default tokens from gitarsenal.dev")
44
+ return token_id, token_secret
45
+ else:
46
+ print("āŒ Modal tokens not found in gitarsenal.dev response")
47
+ return None, None
48
+ except json.JSONDecodeError:
49
+ print("āŒ Invalid JSON response from gitarsenal.dev")
50
+ return None, None
51
+ else:
52
+ print(f"āŒ Failed to fetch from gitarsenal.dev: {response.status_code} - {response.text[:200]}")
53
+ return None, None
54
+
55
+ except requests.exceptions.Timeout:
56
+ print("āŒ Request timeout when fetching from gitarsenal.dev")
57
+ return None, None
58
+ except requests.exceptions.ConnectionError:
59
+ print("āŒ Connection failed to gitarsenal.dev")
60
+ return None, None
61
+ except requests.exceptions.RequestException as e:
62
+ print(f"āŒ Request failed to gitarsenal.dev: {e}")
63
+ return None, None
18
64
 
19
- def fetch_credentials_from_api(api_url=None, api_key=None, credential_id=None):
65
+ def fetch_tokens_from_proxy(proxy_url=None, api_key=None):
20
66
  """
21
- Fetch credentials from the GitArsenal API.
67
+ Fetch Modal tokens from the proxy server.
22
68
 
23
69
  Args:
24
- api_url: Base URL of the API (default: gitarsenal.dev)
70
+ proxy_url: URL of the proxy server
25
71
  api_key: API key for authentication
26
- credential_id: Optional ID of specific credentials to fetch
27
72
 
28
73
  Returns:
29
- dict: Credentials containing modalTokenId and modalTokenSecret if successful, None otherwise
74
+ tuple: (token_id, token_secret) if successful, (None, None) otherwise
30
75
  """
31
76
  # Use environment variables if not provided
32
- if not api_url:
33
- api_url = os.environ.get("GITARSENAL_API_URL", "https://gitarsenal.dev")
34
- if api_url:
35
- print(f"šŸ“‹ Using API URL from environment")
77
+ if not proxy_url:
78
+ proxy_url = os.environ.get("MODAL_PROXY_URL")
79
+ if proxy_url:
80
+ print(f"šŸ“‹ Using proxy URL from environment")
36
81
 
37
82
  if not api_key:
38
- api_key = os.environ.get("GITARSENAL_API_KEY")
83
+ api_key = os.environ.get("MODAL_PROXY_API_KEY")
39
84
  if api_key:
40
85
  print(f"šŸ“‹ Using API key from environment (length: {len(api_key)})")
41
86
 
42
87
  # Check if we have the necessary information
88
+ if not proxy_url:
89
+ # print("āŒ No proxy URL provided or found in environment")
90
+ print("šŸ’” Set MODAL_PROXY_URL environment variable or use --proxy-url argument")
91
+ return None, None
92
+
43
93
  if not api_key:
44
94
  print("āŒ No API key provided or found in environment")
45
- print("šŸ’” Set GITARSENAL_API_KEY environment variable or use --api-key argument")
46
- return None
95
+ print("šŸ’” Set MODAL_PROXY_API_KEY environment variable or use --proxy-api-key argument")
96
+ return None, None
47
97
 
48
98
  # Ensure the URL ends with a slash
49
- if not api_url.endswith("/"):
50
- api_url += "/"
99
+ if not proxy_url.endswith("/"):
100
+ proxy_url += "/"
51
101
 
52
- # Add the endpoint for fetching credentials
53
- credentials_url = f"{api_url}api/credentials"
54
-
55
- # Add credential ID if provided
56
- if credential_id:
57
- credentials_url += f"?id={credential_id}"
102
+ # Add the endpoint for fetching tokens
103
+ token_url = f"{proxy_url}api/modal-tokens"
58
104
 
59
105
  try:
60
106
  # Make the request
61
- print(f"šŸ”„ Fetching credentials from GitArsenal API")
107
+ print(f"šŸ”„ Fetching tokens from proxy server")
62
108
  response = requests.get(
63
- credentials_url,
109
+ token_url,
64
110
  headers={"X-API-Key": api_key}
65
111
  )
66
112
 
67
113
  # Check if the request was successful
68
114
  if response.status_code == 200:
69
115
  data = response.json()
70
- token_id = data.get("modalTokenId")
71
- token_secret = data.get("modalTokenSecret")
72
- openai_api_key = data.get("openaiApiKey")
116
+ token_id = data.get("token_id")
117
+ token_secret = data.get("token_secret")
73
118
 
74
119
  if token_id and token_secret:
75
- print("āœ… Successfully fetched credentials from GitArsenal API")
76
- return {
77
- "token_id": token_id,
78
- "token_secret": token_secret,
79
- "openai_api_key": openai_api_key
80
- }
120
+ print("āœ… Successfully fetched tokens from proxy server")
121
+ return token_id, token_secret
81
122
  else:
82
- print("āŒ Modal tokens not found in response")
83
- return None
123
+ print("āŒ Tokens not found in response")
124
+ return None, None
84
125
  else:
85
- print(f"āŒ Failed to fetch credentials: {response.status_code} - {response.text}")
86
- return None
126
+ print(f"āŒ Failed to fetch tokens: {response.status_code} - {response.text}")
127
+ return None, None
87
128
  except Exception as e:
88
- print(f"āŒ Error fetching credentials: {e}")
89
- return None
129
+ print(f"āŒ Error fetching tokens: {e}")
130
+ return None, None
90
131
 
91
132
  def get_tokens():
92
133
  """
93
- Get Modal tokens, trying to fetch from the GitArsenal API first.
134
+ Get Modal tokens, trying to fetch from the proxy server first.
94
135
  Also sets the tokens in environment variables.
95
136
 
96
137
  Returns:
97
138
  tuple: (token_id, token_secret)
98
139
  """
99
- # Try to fetch from the API
100
- credentials = fetch_credentials_from_api()
101
-
102
- # If we couldn't fetch from the API, use the default tokens
103
- if not credentials:
104
- print("āš ļø Using default tokens")
105
- token_id = DEFAULT_TOKEN_ID
106
- token_secret = DEFAULT_TOKEN_SECRET
107
- openai_api_key = None
108
- else:
109
- token_id = credentials["token_id"]
110
- token_secret = credentials["token_secret"]
111
- openai_api_key = credentials.get("openai_api_key")
112
-
113
- # Set OpenAI API key if available
114
- if openai_api_key:
115
- os.environ["OPENAI_API_KEY"] = openai_api_key
116
- print(f"āœ… Set OPENAI_API_KEY environment variable")
140
+ # Try to fetch from the proxy server
141
+ token_id, token_secret = fetch_tokens_from_proxy()
142
+
143
+ # If we couldn't fetch from the server, try to get default tokens from gitarsenal.dev
144
+ if not token_id or not token_secret:
145
+ print("āš ļø Proxy server failed, trying to fetch default tokens from gitarsenal.dev")
146
+ token_id, token_secret = fetch_default_tokens_from_gitarsenal()
147
+
148
+ # If we still don't have tokens, we can't proceed
149
+ if not token_id or not token_secret:
150
+ print("āŒ Failed to fetch tokens from both proxy server and gitarsenal.dev")
151
+ print("šŸ’” Please check your network connection and API endpoints")
152
+ return None, None
117
153
 
118
154
  # Set the tokens in environment variables
119
155
  os.environ["MODAL_TOKEN_ID"] = token_id
@@ -126,23 +162,33 @@ if __name__ == "__main__":
126
162
  # Parse command-line arguments if run directly
127
163
  import argparse
128
164
 
129
- parser = argparse.ArgumentParser(description='Fetch credentials from the GitArsenal API')
130
- parser.add_argument('--api-url', help='Base URL of the GitArsenal API')
131
- parser.add_argument('--api-key', help='API key for authentication')
132
- parser.add_argument('--credential-id', help='ID of specific credentials to fetch')
165
+ parser = argparse.ArgumentParser(description='Fetch Modal tokens from the proxy server')
166
+ parser.add_argument('--proxy-url', help='URL of the proxy server')
167
+ parser.add_argument('--proxy-api-key', help='API key for the proxy server')
133
168
  args = parser.parse_args()
134
169
 
135
- # Set API URL and API key in environment variables if provided
136
- if args.api_url:
137
- os.environ["GITARSENAL_API_URL"] = args.api_url
138
- print(f"āœ… Set GITARSENAL_API_URL from command line")
170
+ # Set proxy URL and API key in environment variables if provided
171
+ if args.proxy_url:
172
+ os.environ["MODAL_PROXY_URL"] = args.proxy_url
173
+ print(f"āœ… Set MODAL_PROXY_URL from command line: {args.proxy_url}")
139
174
 
140
- if args.api_key:
141
- os.environ["GITARSENAL_API_KEY"] = args.api_key
142
- print(f"āœ… Set GITARSENAL_API_KEY from command line")
175
+ if args.proxy_api_key:
176
+ os.environ["MODAL_PROXY_API_KEY"] = args.proxy_api_key
177
+ print(f"āœ… Set MODAL_PROXY_API_KEY from command line")
143
178
 
144
179
  # Get tokens
145
180
  token_id, token_secret = get_tokens()
181
+ print(f"Token ID: {token_id}")
182
+ print(f"Token Secret: {token_secret}")
183
+
184
+ # Check if tokens are set in environment variables
185
+ print(f"\nšŸ” DEBUG: Checking environment variables")
186
+ print(f"šŸ” MODAL_TOKEN_ID exists: {'Yes' if os.environ.get('MODAL_TOKEN_ID') else 'No'}")
187
+ print(f"šŸ” MODAL_TOKEN_SECRET exists: {'Yes' if os.environ.get('MODAL_TOKEN_SECRET') else 'No'}")
188
+ if os.environ.get('MODAL_TOKEN_ID'):
189
+ print(f"šŸ” MODAL_TOKEN_ID length: {len(os.environ.get('MODAL_TOKEN_ID'))}")
190
+ if os.environ.get('MODAL_TOKEN_SECRET'):
191
+ print(f"šŸ” MODAL_TOKEN_SECRET length: {len(os.environ.get('MODAL_TOKEN_SECRET'))}")
146
192
 
147
193
  # Write the tokens to a file for use by other scripts
148
194
  tokens_file = Path(__file__).parent / "modal_tokens.json"
@@ -185,4 +231,4 @@ if __name__ == "__main__":
185
231
  except Exception as e:
186
232
  print(f"āŒ Error using Modal CLI: {e}")
187
233
 
188
- print(f"\nāœ… All token setup completed successfully")
234
+ print(f"\nāœ… All token setup completed successfully")
@@ -0,0 +1,8 @@
1
+ {
2
+ "token_id": "ak-sLhYqCjkvixiYcb9LAuCHp",
3
+ "token_secret": "as-fPzD0Zm0dl6IFAEkhaH9pq",
4
+ "openai_api_key": "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",
5
+ "modalTokenId": "ak-sLhYqCjkvixiYcb9LAuCHp",
6
+ "modalTokenSecret": "as-fPzD0Zm0dl6IFAEkhaH9pq",
7
+ "openaiApiKey": "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"
8
+ }
@@ -43,11 +43,16 @@ try:
43
43
  # First, try to import the fetch_modal_tokens module
44
44
  from fetch_modal_tokens import get_tokens
45
45
  TOKEN_ID, TOKEN_SECRET = get_tokens()
46
+
47
+ # Check if we got valid tokens
48
+ if TOKEN_ID is None or TOKEN_SECRET is None:
49
+ raise ValueError("Could not get valid tokens")
50
+
46
51
  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
52
+ except (ImportError, ValueError) as e:
53
+ # If the module is not available or tokens are invalid, use hardcoded tokens
54
+ TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
55
+ TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq" # Real token secret from fr8mafia profile
51
56
  print(f"āš ļø Using default tokens")
52
57
 
53
58
  print("šŸ”§ Fixing Modal token (basic implementation)...")
@@ -28,6 +28,8 @@ try:
28
28
  except ImportError:
29
29
  # If the module is not available, use hardcoded tokens
30
30
  # print(f"āš ļø Using default tokens")
31
+ TOKEN_ID = "ak-sLhYqCjkvixiYcb9LAuCHp"
32
+ TOKEN_SECRET = "as-fPzD0Zm0dl6IFAEkhaH9pq"
31
33
 
32
34
  # print("šŸ”§ Advanced Modal Token Fixer")
33
35
 
@@ -90,10 +92,13 @@ try:
90
92
  )
91
93
 
92
94
  if result.returncode == 0:
95
+ pass
93
96
  # print(f"āœ… Successfully set token via Modal CLI")
94
97
  else:
98
+ pass
95
99
  # print(f"āŒ Failed to set token via Modal CLI: {result.stderr}")
96
100
  except Exception as e:
101
+ pass
97
102
  # print(f"āŒ Error using Modal CLI: {e}")
98
103
 
99
104
  # Approach 4: Use Modal Python API to set token
@@ -0,0 +1,4 @@
1
+ {
2
+ "token_id": "ak-sLhYqCjkvixiYcb9LAuCHp",
3
+ "token_secret": "as-fPzD0Zm0dl6IFAEkhaH9pq"
4
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test importing and using get_tokens from fetch_modal_tokens
4
+ """
5
+
6
+ import os
7
+ import sys
8
+
9
+ def main():
10
+ """Main function to test importing and using get_tokens"""
11
+ print("šŸ” Testing import of get_tokens from fetch_modal_tokens...")
12
+
13
+ # Set a test API key for the script to use
14
+ os.environ["GITARSENAL_API_KEY"] = "test_key"
15
+
16
+ try:
17
+ # Import the function
18
+ from fetch_modal_tokens import get_tokens
19
+ print("āœ… Successfully imported get_tokens from fetch_modal_tokens")
20
+
21
+ # Call the function
22
+ print("šŸ”„ Calling get_tokens()...")
23
+ token_id, token_secret = get_tokens()
24
+
25
+ # Check the results
26
+ print("āœ… Successfully called get_tokens()")
27
+ print(f" token_id: {token_id[:5]}...{token_id[-5:]}")
28
+ print(f" token_secret: {token_secret[:5]}...{token_secret[-5:]}")
29
+
30
+ # Check if environment variables were set
31
+ if os.environ.get("MODAL_TOKEN_ID") == token_id:
32
+ print("āœ… MODAL_TOKEN_ID environment variable set correctly")
33
+ else:
34
+ print("āŒ MODAL_TOKEN_ID environment variable not set correctly")
35
+
36
+ if os.environ.get("MODAL_TOKEN_SECRET") == token_secret:
37
+ print("āœ… MODAL_TOKEN_SECRET environment variable set correctly")
38
+ else:
39
+ print("āŒ MODAL_TOKEN_SECRET environment variable not set correctly")
40
+
41
+ # Check if OPENAI_API_KEY was set
42
+ if os.environ.get("OPENAI_API_KEY"):
43
+ print("āœ… OPENAI_API_KEY environment variable set")
44
+ print(f" length: {len(os.environ.get('OPENAI_API_KEY'))}")
45
+ else:
46
+ print("āŒ OPENAI_API_KEY environment variable not set")
47
+
48
+ return True
49
+ except Exception as e:
50
+ print(f"āŒ Error: {e}")
51
+ return False
52
+
53
+ if __name__ == "__main__":
54
+ success = main()
55
+ sys.exit(0 if success else 1)
@@ -39,6 +39,11 @@ try:
39
39
  # print("šŸ”„ Fetching tokens from proxy server...")
40
40
  from fetch_modal_tokens import get_tokens
41
41
  token_id, token_secret = get_tokens()
42
+
43
+ # Check if we got valid tokens
44
+ if token_id is None or token_secret is None:
45
+ raise ValueError("Could not get valid tokens")
46
+
42
47
  # print(f"āœ… Tokens fetched successfully")
43
48
 
44
49
  # Explicitly set the environment variables again to be sure
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Verify that environment variables are set correctly after running fetch_modal_tokens.py
4
+ """
5
+
6
+ import os
7
+ import subprocess
8
+ import sys
9
+
10
+ def check_env_var(var_name):
11
+ """Check if an environment variable is set and print its status"""
12
+ value = os.environ.get(var_name)
13
+ if value:
14
+ print(f"āœ… {var_name} is set (length: {len(value)})")
15
+ return True
16
+ else:
17
+ print(f"āŒ {var_name} is not set")
18
+ return False
19
+
20
+ def main():
21
+ """Main function to verify environment variables"""
22
+ print("šŸ” Checking environment variables before running fetch_modal_tokens.py...")
23
+ modal_id_before = check_env_var("MODAL_TOKEN_ID")
24
+ modal_secret_before = check_env_var("MODAL_TOKEN_SECRET")
25
+ openai_key_before = check_env_var("OPENAI_API_KEY")
26
+
27
+ print("\nšŸ”„ Running fetch_modal_tokens.py...")
28
+ # Set a test API key for the script to use
29
+ os.environ["GITARSENAL_API_KEY"] = "test_key"
30
+
31
+ try:
32
+ # Import the module to run it
33
+ from fetch_modal_tokens import get_tokens
34
+ token_id, token_secret = get_tokens()
35
+ print(f"\nāœ… get_tokens() returned values successfully")
36
+ print(f" token_id length: {len(token_id) if token_id else 0}")
37
+ print(f" token_secret length: {len(token_secret) if token_secret else 0}")
38
+ except Exception as e:
39
+ print(f"\nāŒ Error running get_tokens(): {e}")
40
+ sys.exit(1)
41
+
42
+ print("\nšŸ” Checking environment variables after running fetch_modal_tokens.py...")
43
+ modal_id_after = check_env_var("MODAL_TOKEN_ID")
44
+ modal_secret_after = check_env_var("MODAL_TOKEN_SECRET")
45
+ openai_key_after = check_env_var("OPENAI_API_KEY")
46
+
47
+ # Verify that the variables were set
48
+ if modal_id_after and modal_secret_after:
49
+ print("\nāœ… MODAL_TOKEN_ID and MODAL_TOKEN_SECRET were successfully set")
50
+ else:
51
+ print("\nāŒ Failed to set all required environment variables")
52
+
53
+ if openai_key_after:
54
+ print("āœ… OPENAI_API_KEY was also set")
55
+
56
+ # Check if the values match what was returned by get_tokens()
57
+ if modal_id_after and os.environ.get("MODAL_TOKEN_ID") == token_id:
58
+ print("āœ… MODAL_TOKEN_ID matches the value returned by get_tokens()")
59
+
60
+ if modal_secret_after and os.environ.get("MODAL_TOKEN_SECRET") == token_secret:
61
+ print("āœ… MODAL_TOKEN_SECRET matches the value returned by get_tokens()")
62
+
63
+ if __name__ == "__main__":
64
+ main()