forked from awslabs/mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplore-datasphere-api.py
More file actions
196 lines (157 loc) · 6.3 KB
/
explore-datasphere-api.py
File metadata and controls
196 lines (157 loc) · 6.3 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python3
"""
Advanced Datasphere API exploration script
"""
import requests
import json
from requests.auth import HTTPBasicAuth
# Connection details
TENANT_ID = "f45fa9cc-f4b5-4126-ab73-b19b578fb17a"
BASE_URL = f"https://{TENANT_ID}.eu10.hcs.cloud.sap"
USERNAME = "GE230769"
PASSWORD = "ObVSIDDHPG1!"
def explore_api_discovery():
"""Try to discover the actual API structure"""
session = requests.Session()
session.auth = HTTPBasicAuth(USERNAME, PASSWORD)
print(f"🔍 Exploring API structure for: {BASE_URL}")
print("=" * 60)
# Try different authentication and discovery approaches
discovery_endpoints = [
# Common API discovery endpoints
"/.well-known/openapi",
"/.well-known/api",
"/swagger.json",
"/openapi.json",
"/api-docs",
"/docs",
# SAP specific patterns
"/sap/bc/rest/",
"/sap/opu/odata/",
"/sap/bc/ui5_ui5/",
# Datasphere specific patterns (based on SAP documentation)
"/dwaas-core/",
"/dwc/",
"/api/v1/",
"/rest/v1/",
# Try without authentication first
"/public/health",
"/public/api",
"/public/info"
]
working_endpoints = []
for endpoint in discovery_endpoints:
try:
# Try with authentication
response = session.get(BASE_URL + endpoint, timeout=5)
if response.status_code < 500:
status = "✅" if response.status_code < 400 else "⚠️"
print(f"{status} {endpoint}: {response.status_code}")
if response.status_code < 400:
working_endpoints.append(endpoint)
# Check content type and try to parse
content_type = response.headers.get('content-type', '')
if 'json' in content_type:
try:
data = response.json()
print(f" 📊 JSON: {type(data).__name__}")
if isinstance(data, dict) and data:
print(f" 🔑 Keys: {list(data.keys())[:5]}")
except:
print(f" 📄 JSON parsing failed")
elif 'html' in content_type:
print(f" 🌐 HTML response")
elif 'xml' in content_type:
print(f" 📋 XML response")
else:
print(f" 📄 Content-Type: {content_type}")
except requests.exceptions.RequestException as e:
print(f"❌ {endpoint}: {type(e).__name__}")
return working_endpoints
def try_oauth_discovery():
"""Try to discover OAuth/SAML endpoints"""
print(f"\n🔐 Checking authentication endpoints...")
print("-" * 40)
# Don't use authentication for these
session = requests.Session()
auth_endpoints = [
"/oauth/token",
"/oauth/authorize",
"/login",
"/auth",
"/saml/login",
"/sap/bc/sec/oauth2/token",
"/.well-known/oauth_authorization_server"
]
for endpoint in auth_endpoints:
try:
response = session.get(BASE_URL + endpoint, timeout=5, allow_redirects=False)
if response.status_code < 500:
status = "✅" if response.status_code < 400 else "⚠️"
print(f"{status} {endpoint}: {response.status_code}")
# Check for redirects or auth challenges
if 'location' in response.headers:
print(f" 🔄 Redirects to: {response.headers['location']}")
if 'www-authenticate' in response.headers:
print(f" 🔐 Auth challenge: {response.headers['www-authenticate']}")
except requests.exceptions.RequestException:
pass
def check_common_sap_paths():
"""Check common SAP application paths"""
print(f"\n🏢 Checking SAP application paths...")
print("-" * 40)
session = requests.Session()
session.auth = HTTPBasicAuth(USERNAME, PASSWORD)
sap_paths = [
# SAP Fiori Launchpad
"/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html",
# SAP Gateway
"/sap/opu/odata/sap/",
# SAP Business Application Studio
"/app-studio/",
# SAP Analytics Cloud / Datasphere specific
"/sac/",
"/datasphere/",
"/dwc/",
"/dwaas/",
# REST APIs
"/sap/bc/rest/",
"/rest/",
# Common SAP services
"/sap/bc/ping",
"/sap/public/ping"
]
for path in sap_paths:
try:
response = session.get(BASE_URL + path, timeout=5)
if response.status_code < 500:
status = "✅" if response.status_code < 400 else "⚠️"
print(f"{status} {path}: {response.status_code}")
except requests.exceptions.RequestException:
pass
if __name__ == "__main__":
print("🚀 Starting comprehensive Datasphere API exploration")
# Step 1: API Discovery
working_endpoints = explore_api_discovery()
# Step 2: OAuth/Auth Discovery
try_oauth_discovery()
# Step 3: SAP-specific paths
check_common_sap_paths()
# Summary
print(f"\n" + "=" * 60)
print("EXPLORATION SUMMARY")
print("=" * 60)
if working_endpoints:
print(f"✅ Found {len(working_endpoints)} working endpoints:")
for ep in working_endpoints:
print(f" • {ep}")
print(f"\n🎯 Next steps:")
print(f" 1. Explore the working endpoints for API documentation")
print(f" 2. Check if they contain links to other APIs")
print(f" 3. Look for OData metadata or OpenAPI specs")
else:
print("❌ No additional working endpoints found")
print("🔧 Recommendations:")
print(" 1. Check SAP Datasphere documentation for correct API paths")
print(" 2. Verify tenant configuration and user permissions")
print(" 3. Contact SAP support for API access details")