Skip to content

Commit 5f9dc75

Browse files
fix: add use_proxy param to /ports/ endpoints
1 parent 3e6d6c2 commit 5f9dc75

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/api/router/apps.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,10 @@ async def get_network(
308308
async def list_port_mappings(
309309
request: Request,
310310
app_name: str,
311+
use_proxy: bool = False,
311312
):
312313
success, result = await AppService.list_port_mappings(
313-
request.state.session_user, app_name
314+
request.state.session_user, app_name, use_proxy
314315
)
315316

316317
return JSONResponse(
@@ -331,9 +332,10 @@ async def add_port_mapping(
331332
origin_port: int,
332333
dest_port: int,
333334
protocol: str = "http",
335+
use_proxy: bool = False,
334336
):
335337
success, result = await AppService.add_port_mapping(
336-
request.state.session_user, app_name, origin_port, dest_port, protocol
338+
request.state.session_user, app_name, origin_port, dest_port, protocol, use_proxy
337339
)
338340

339341
return JSONResponse(
@@ -354,9 +356,10 @@ async def remove_port_mapping(
354356
origin_port: int,
355357
dest_port: int,
356358
protocol: str = "http",
359+
use_proxy: bool = False,
357360
):
358361
success, result = await AppService.remove_port_mapping(
359-
request.state.session_user, app_name, origin_port, dest_port, protocol
362+
request.state.session_user, app_name, origin_port, dest_port, protocol, use_proxy
360363
)
361364

362365
return JSONResponse(

src/api/services/apps.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,17 @@ async def get_network(session_user: UserSchema, app_name: str) -> Tuple[bool, An
334334

335335
@staticmethod
336336
async def list_port_mappings(
337-
session_user: UserSchema, app_name: str
337+
session_user: UserSchema, app_name: str, use_proxy: bool = False
338338
) -> Tuple[bool, Any]:
339339
app_name = ResourceName(session_user, app_name, App).for_system()
340340

341341
if app_name not in session_user.apps:
342342
raise HTTPException(status_code=404, detail="App does not exist")
343-
344-
success, message = await run_command(f"proxy:ports {app_name}")
343+
344+
if use_proxy:
345+
success, message = await run_command(f"proxy:ports {app_name}")
346+
else:
347+
success, message = await run_command(f"ports:list {app_name}")
345348

346349
if "no port mappings" in message.lower():
347350
return True, []
@@ -358,15 +361,21 @@ async def add_port_mapping(
358361
origin_port: int,
359362
dest_port: int,
360363
protocol: str,
364+
use_proxy: bool = False,
361365
) -> Tuple[bool, Any]:
362366
app_name = ResourceName(session_user, app_name, App).for_system()
363367

364368
if app_name not in session_user.apps:
365369
raise HTTPException(status_code=404, detail="App does not exist")
366370

367-
return await run_command(
368-
f"proxy:ports-add {app_name} {protocol}:{origin_port}:{dest_port}"
369-
)
371+
if use_proxy:
372+
return await run_command(
373+
f"proxy:ports-add {app_name} {protocol}:{origin_port}:{dest_port}"
374+
)
375+
else:
376+
return await run_command(
377+
f"ports:add {app_name} {protocol}:{origin_port}:{dest_port}"
378+
)
370379

371380
@staticmethod
372381
async def remove_port_mapping(
@@ -375,15 +384,21 @@ async def remove_port_mapping(
375384
origin_port: int,
376385
dest_port: int,
377386
protocol: str,
387+
use_proxy: bool = False,
378388
) -> Tuple[bool, Any]:
379389
app_name = ResourceName(session_user, app_name, App).for_system()
380390

381391
if app_name not in session_user.apps:
382392
raise HTTPException(status_code=404, detail="App does not exist")
383393

384-
return await run_command(
385-
f"proxy:ports-remove {app_name} {protocol}:{origin_port}:{dest_port}"
386-
)
394+
if use_proxy:
395+
return await run_command(
396+
f"proxy:ports-remove {app_name} {protocol}:{origin_port}:{dest_port}"
397+
)
398+
else:
399+
return await run_command(
400+
f"ports:remove {app_name} {protocol}:{origin_port}:{dest_port}"
401+
)
387402

388403
@staticmethod
389404
async def get_linked_databases(

0 commit comments

Comments
 (0)