Initial curated Unraid-AppOps-Gateway source from 3bd6f6fee310125bfbb4d4650389a817f498724d
This commit is contained in:
commit
1dfbca08a1
528 files changed
+131054
No files matched your search
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from ..connectors.portainer import PortainerConnector
|
||||
from ..core.redaction import redact_message
|
||||
|
||||
router = APIRouter(prefix='/api/stacks')
|
||||
|
||||
|
||||
def _raise_connector_error(response: dict):
|
||||
status = str(response.get('status', 'error'))
|
||||
reason = redact_message(str(response.get('reason', 'connection_failed')))
|
||||
status_code = 503 if status == 'missing_config' else 502
|
||||
raise HTTPException(
|
||||
status_code=status_code,
|
||||
detail={
|
||||
'status': status,
|
||||
'reason': reason,
|
||||
'connector': 'portainer',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.get('')
|
||||
def list_stacks():
|
||||
response = PortainerConnector().list_stacks()
|
||||
if response.get('status') == 'ok':
|
||||
return response.get('stacks', [])
|
||||
_raise_connector_error(response)
|
||||
|
||||
|
||||
@router.get('/{stack_id}')
|
||||
def get_stack(stack_id: str):
|
||||
response = PortainerConnector().get_stack_status(stack_id)
|
||||
if response.get('status') == 'ok':
|
||||
return response.get('stack')
|
||||
if response.get('status') == 'not_found':
|
||||
return None
|
||||
_raise_connector_error(response)
|
||||
Reference in new issue
Block a user