Skip to content

Commit c0fda5c

Browse files
committed
style: apply ruff formatting fixes
- Fix code formatting across 21 files - Ensure consistent code style for release v2.2.9 - Maintain code quality standards
1 parent f30784c commit c0fda5c

21 files changed

+1257
-900
lines changed

examples/mcp-proxy/authentication-example.py

Lines changed: 78 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ async def main():
2626
"info": {
2727
"title": "Secure API",
2828
"version": "1.0.0",
29-
"description": "API demonstrating various authentication methods"
29+
"description": "API demonstrating various authentication methods",
3030
},
3131
"servers": [
32-
{"url": "https://api.secure-example.com", "description": "Production server"}
32+
{
33+
"url": "https://api.secure-example.com",
34+
"description": "Production server",
35+
}
3336
],
3437
"paths": {
3538
"/public/status": {
@@ -43,9 +46,9 @@ async def main():
4346
"application/json": {
4447
"example": {"status": "healthy", "version": "1.0.0"}
4548
}
46-
}
49+
},
4750
}
48-
}
51+
},
4952
}
5053
},
5154
"/api/users": {
@@ -59,13 +62,13 @@ async def main():
5962
"application/json": {
6063
"example": [
6164
{"id": 1, "name": "John Doe", "role": "admin"},
62-
{"id": 2, "name": "Jane Smith", "role": "user"}
65+
{"id": 2, "name": "Jane Smith", "role": "user"},
6366
]
6467
}
65-
}
68+
},
6669
},
67-
"401": {"description": "Unauthorized"}
68-
}
70+
"401": {"description": "Unauthorized"},
71+
},
6972
}
7073
},
7174
"/api/profile": {
@@ -81,13 +84,16 @@ async def main():
8184
"id": 1,
8285
"name": "John Doe",
8386
"email": "john@example.com",
84-
"preferences": {"theme": "dark", "notifications": True}
87+
"preferences": {
88+
"theme": "dark",
89+
"notifications": True,
90+
},
8591
}
8692
}
87-
}
93+
},
8894
},
89-
"401": {"description": "Unauthorized"}
90-
}
95+
"401": {"description": "Unauthorized"},
96+
},
9197
}
9298
},
9399
"/admin/settings": {
@@ -102,14 +108,14 @@ async def main():
102108
"example": {
103109
"maintenance_mode": False,
104110
"max_users": 1000,
105-
"features": ["analytics", "reporting"]
111+
"features": ["analytics", "reporting"],
106112
}
107113
}
108-
}
114+
},
109115
},
110116
"401": {"description": "Unauthorized"},
111-
"403": {"description": "Forbidden"}
112-
}
117+
"403": {"description": "Forbidden"},
118+
},
113119
}
114120
},
115121
"/oauth/userinfo": {
@@ -125,34 +131,34 @@ async def main():
125131
"sub": "user123",
126132
"name": "John Doe",
127133
"email": "john@example.com",
128-
"scope": ["read:user", "write:profile"]
134+
"scope": ["read:user", "write:profile"],
129135
}
130136
}
131-
}
137+
},
132138
},
133-
"401": {"description": "Invalid token"}
134-
}
139+
"401": {"description": "Invalid token"},
140+
},
135141
}
136-
}
142+
},
137143
},
138144
"components": {
139145
"securitySchemes": {
140146
"ApiKeyAuth": {
141147
"type": "apiKey",
142148
"in": "header",
143149
"name": "X-API-Key",
144-
"description": "API key authentication"
150+
"description": "API key authentication",
145151
},
146152
"BearerAuth": {
147153
"type": "http",
148154
"scheme": "bearer",
149155
"bearerFormat": "JWT",
150-
"description": "Bearer token authentication"
156+
"description": "Bearer token authentication",
151157
},
152158
"BasicAuth": {
153159
"type": "http",
154160
"scheme": "basic",
155-
"description": "Basic HTTP authentication"
161+
"description": "Basic HTTP authentication",
156162
},
157163
"OAuth2": {
158164
"type": "oauth2",
@@ -162,13 +168,13 @@ async def main():
162168
"tokenUrl": "https://api.secure-example.com/oauth/token",
163169
"scopes": {
164170
"read:user": "Read user information",
165-
"write:profile": "Update user profile"
166-
}
171+
"write:profile": "Update user profile",
172+
},
167173
}
168-
}
169-
}
174+
},
175+
},
170176
}
171-
}
177+
},
172178
}
173179

174180
# Authentication configurations for different scenarios
@@ -177,25 +183,27 @@ async def main():
177183
"auth_type": "api_key",
178184
"credentials": {"api_key": "sk-test-api-key-12345"},
179185
"location": "header",
180-
"name": "X-API-Key"
186+
"name": "X-API-Key",
181187
},
182188
"bearer_token": {
183189
"auth_type": "bearer_token",
184-
"credentials": {"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test-jwt-token"}
190+
"credentials": {
191+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test-jwt-token"
192+
},
185193
},
186194
"basic_auth": {
187195
"auth_type": "basic_auth",
188-
"credentials": {"username": "admin", "password": "secure-password-123"}
196+
"credentials": {"username": "admin", "password": "secure-password-123"},
189197
},
190198
"oauth2": {
191199
"auth_type": "oauth2",
192200
"credentials": {
193201
"access_token": "ya29.test-oauth2-access-token",
194202
"refresh_token": "1//test-refresh-token",
195203
"client_id": "test-client-id.apps.googleusercontent.com",
196-
"client_secret": "test-client-secret"
197-
}
198-
}
204+
"client_secret": "test-client-secret",
205+
},
206+
},
199207
}
200208

201209
# Scenario 1: API Key Authentication
@@ -209,12 +217,16 @@ async def main():
209217
plugin_name="secure_api_key",
210218
target_url="https://api.secure-example.com",
211219
auth_config=auth_configs["api_key"],
212-
proxy_config=None
220+
proxy_config=None,
213221
)
214222

215223
print(f"✅ API Key plugin created: {api_key_plugin.get('plugin_id', 'N/A')}")
216-
print(f" Auth type: {api_key_plugin.get('auth_config', {}).get('auth_type', 'N/A')}")
217-
print(f" Key location: {api_key_plugin.get('auth_config', {}).get('location', 'N/A')}")
224+
print(
225+
f" Auth type: {api_key_plugin.get('auth_config', {}).get('auth_type', 'N/A')}"
226+
)
227+
print(
228+
f" Key location: {api_key_plugin.get('auth_config', {}).get('location', 'N/A')}"
229+
)
218230

219231
except Exception as e:
220232
print(f"❌ API Key plugin creation failed: {e}")
@@ -230,11 +242,15 @@ async def main():
230242
plugin_name="secure_api_bearer",
231243
target_url="https://api.secure-example.com",
232244
auth_config=auth_configs["bearer_token"],
233-
proxy_config=None
245+
proxy_config=None,
234246
)
235247

236-
print(f"✅ Bearer token plugin created: {bearer_plugin.get('plugin_id', 'N/A')}")
237-
print(f" Auth type: {bearer_plugin.get('auth_config', {}).get('auth_type', 'N/A')}")
248+
print(
249+
f"✅ Bearer token plugin created: {bearer_plugin.get('plugin_id', 'N/A')}"
250+
)
251+
print(
252+
f" Auth type: {bearer_plugin.get('auth_config', {}).get('auth_type', 'N/A')}"
253+
)
238254
print(" Token format: JWT")
239255

240256
except Exception as e:
@@ -253,23 +269,19 @@ async def main():
253269
auth_config=auth_configs["basic_auth"],
254270
proxy_config={
255271
"route_rules": [
256-
{
257-
"pattern": "/admin/*",
258-
"mode": "proxy",
259-
"priority": 10
260-
},
261-
{
262-
"pattern": "/public/*",
263-
"mode": "mock",
264-
"priority": 5
265-
}
272+
{"pattern": "/admin/*", "mode": "proxy", "priority": 10},
273+
{"pattern": "/public/*", "mode": "mock", "priority": 5},
266274
]
267-
}
275+
},
268276
)
269277

270278
print(f"✅ Basic auth plugin created: {basic_plugin.get('plugin_id', 'N/A')}")
271-
print(f" Auth type: {basic_plugin.get('auth_config', {}).get('auth_type', 'N/A')}")
272-
print(f" Username: {basic_plugin.get('auth_config', {}).get('credentials', {}).get('username', 'N/A')}")
279+
print(
280+
f" Auth type: {basic_plugin.get('auth_config', {}).get('auth_type', 'N/A')}"
281+
)
282+
print(
283+
f" Username: {basic_plugin.get('auth_config', {}).get('credentials', {}).get('username', 'N/A')}"
284+
)
273285

274286
except Exception as e:
275287
print(f"❌ Basic auth plugin creation failed: {e}")
@@ -285,12 +297,16 @@ async def main():
285297
plugin_name="secure_api_oauth2",
286298
target_url="https://api.secure-example.com",
287299
auth_config=auth_configs["oauth2"],
288-
proxy_config=None
300+
proxy_config=None,
289301
)
290302

291303
print(f"✅ OAuth2 plugin created: {oauth2_plugin.get('plugin_id', 'N/A')}")
292-
print(f" Auth type: {oauth2_plugin.get('auth_config', {}).get('auth_type', 'N/A')}")
293-
print(f" Has refresh token: {'Yes' if 'refresh_token' in auth_configs['oauth2']['credentials'] else 'No'}")
304+
print(
305+
f" Auth type: {oauth2_plugin.get('auth_config', {}).get('auth_type', 'N/A')}"
306+
)
307+
print(
308+
f" Has refresh token: {'Yes' if 'refresh_token' in auth_configs['oauth2']['credentials'] else 'No'}"
309+
)
294310

295311
except Exception as e:
296312
print(f"❌ OAuth2 plugin creation failed: {e}")
@@ -308,7 +324,7 @@ async def main():
308324
mode="mock", # Use mock mode for demonstration
309325
validation_mode="strict",
310326
auto_generate_scenarios=True,
311-
execute_immediately=True
327+
execute_immediately=True,
312328
)
313329

314330
print("✅ Multi-auth testing completed!")
@@ -329,12 +345,12 @@ async def main():
329345
"auth_type": "api_key",
330346
"credentials": {"api_key": "invalid-key"},
331347
"location": "header",
332-
"name": "X-API-Key"
348+
"name": "X-API-Key",
333349
},
334350
"expired_token": {
335351
"auth_type": "bearer_token",
336-
"credentials": {"token": "expired.jwt.token"}
337-
}
352+
"credentials": {"token": "expired.jwt.token"},
353+
},
338354
}
339355

340356
for auth_name, auth_config in invalid_auth_configs.items():
@@ -345,7 +361,7 @@ async def main():
345361
plugin_name=f"test_{auth_name}",
346362
target_url="https://api.secure-example.com",
347363
auth_config=auth_config,
348-
proxy_config=None
364+
proxy_config=None,
349365
)
350366
print(f"⚠️ {auth_name} plugin created (will fail on real requests)")
351367

0 commit comments

Comments
 (0)