-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_token.py
More file actions
66 lines (56 loc) · 2.42 KB
/
debug_token.py
File metadata and controls
66 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Debug script to test GitHub token permissions and API access
"""
import requests
import os
def test_github_token():
token = os.getenv('GH_SECRET') or os.getenv('GITHUB_TOKEN')
if not token:
print("❌ No GitHub token found!")
return
headers = {
'Authorization': f'token {token}',
'Accept': 'application/vnd.github.v3+json'
}
print(f"🔑 Testing token: {token[:8]}...{token[-4:]}")
# Test 1: Check token permissions
print("\n1. Testing token permissions...")
response = requests.get('https://api.github.com/user', headers=headers)
if response.status_code == 200:
user_data = response.json()
print(f"✅ Token valid for user: {user_data.get('login')}")
print(f" User type: {user_data.get('type')}")
else:
print(f"❌ Token validation failed: {response.status_code}")
return
# Test 2: Check rate limits
print("\n2. Checking rate limits...")
rate_limit = response.headers.get('X-RateLimit-Remaining', 'Unknown')
rate_reset = response.headers.get('X-RateLimit-Reset', 'Unknown')
print(f" Remaining requests: {rate_limit}")
# Test 3: Test organization access (try one org with different approaches)
test_org = "DHCW-Digital-Health-and-Care-Wales"
print(f"\n3. Testing organization access for: {test_org}")
# Try different API endpoints
endpoints = [
f'https://api.github.com/orgs/{test_org}/repos',
f'https://api.github.com/orgs/{test_org}/repos?type=all',
f'https://api.github.com/orgs/{test_org}/repos?type=public',
f'https://api.github.com/orgs/{test_org}/repos?type=private'
]
for endpoint in endpoints:
print(f"\n Testing: {endpoint}")
response = requests.get(endpoint, headers=headers, params={'per_page': 5})
if response.status_code == 200:
repos = response.json()
print(f" ✅ Found {len(repos)} repositories")
if repos:
for repo in repos[:2]: # Show first 2
visibility = repo.get('visibility', 'unknown')
private = repo.get('private', 'unknown')
print(f" - {repo['name']}: visibility={visibility}, private={private}")
else:
print(f" ❌ Failed: {response.status_code} - {response.text[:100]}")
if __name__ == "__main__":
test_github_token()