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,151 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from sqlmodel import Session
|
||||
|
||||
from ..db.session import get_session
|
||||
from ..services.inventory_discovery import (
|
||||
calculate_drift,
|
||||
acknowledge_drift,
|
||||
complete_app_review,
|
||||
create_drift_incident,
|
||||
get_run_detail,
|
||||
ignore_discovered_container,
|
||||
import_discovered_container,
|
||||
list_discovered,
|
||||
list_inventory_apps,
|
||||
list_inventory_containers,
|
||||
list_mappings,
|
||||
list_runs,
|
||||
list_suggestions,
|
||||
list_unknown,
|
||||
list_unmapped,
|
||||
map_discovered_to_existing_app,
|
||||
prune_historical_discovery_rows,
|
||||
run_discovery,
|
||||
sync_app_connector_statuses,
|
||||
update_discovered_review_metadata,
|
||||
update_inventory_baseline,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix='/api/inventory')
|
||||
|
||||
|
||||
@router.post('/discover')
|
||||
def discover(session: Session = Depends(get_session)):
|
||||
return run_discovery(session=session)
|
||||
|
||||
|
||||
@router.get('/runs')
|
||||
def runs(
|
||||
limit: int = Query(default=100, ge=1, le=500),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
return list_runs(session, limit=limit, offset=offset)
|
||||
|
||||
|
||||
@router.get('/runs/{run_id}')
|
||||
def run_detail(run_id: str, session: Session = Depends(get_session)):
|
||||
result = get_run_detail(session, run_id)
|
||||
if not result:
|
||||
return {'success': False, 'message': 'discovery_run_not_found', 'id': run_id}
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/discovered-containers')
|
||||
def discovered_containers(session: Session = Depends(get_session)):
|
||||
return list_discovered(session)
|
||||
|
||||
|
||||
@router.get('/containers')
|
||||
def inventory_containers(include_ignored: bool = True, session: Session = Depends(get_session)):
|
||||
return list_inventory_containers(session, include_ignored=include_ignored)
|
||||
|
||||
|
||||
@router.get('/apps')
|
||||
def inventory_apps(include_unmanaged: bool = True, include_ignored: bool = False, session: Session = Depends(get_session)):
|
||||
return list_inventory_apps(session, include_unmanaged=include_unmanaged, include_ignored=include_ignored)
|
||||
|
||||
|
||||
@router.get('/suggestions')
|
||||
def suggestions(session: Session = Depends(get_session)):
|
||||
return list_suggestions(session)
|
||||
|
||||
|
||||
@router.get('/unmapped')
|
||||
def unmapped(include_ignored: bool = False, session: Session = Depends(get_session)):
|
||||
return list_unmapped(session, include_ignored=include_ignored)
|
||||
|
||||
|
||||
@router.get('/unknown')
|
||||
def unknown(include_ignored: bool = False, session: Session = Depends(get_session)):
|
||||
return list_unknown(session, include_ignored=include_ignored)
|
||||
|
||||
|
||||
@router.get('/mappings')
|
||||
def mappings(session: Session = Depends(get_session)):
|
||||
return list_mappings(session)
|
||||
|
||||
|
||||
@router.get('/drift')
|
||||
def drift(session: Session = Depends(get_session)):
|
||||
return calculate_drift(session)
|
||||
|
||||
|
||||
@router.post('/drift/{drift_id}/acknowledge')
|
||||
def acknowledge_inventory_drift(drift_id: str, session: Session = Depends(get_session)):
|
||||
return acknowledge_drift(session, drift_id)
|
||||
|
||||
|
||||
@router.post('/drift/{drift_id}/incident')
|
||||
def create_inventory_drift_incident(drift_id: str, session: Session = Depends(get_session)):
|
||||
return create_drift_incident(session, drift_id)
|
||||
|
||||
|
||||
@router.post('/import')
|
||||
def import_container(payload: dict, session: Session = Depends(get_session)):
|
||||
discovered_id = str(payload.get('discoveredContainerId') or payload.get('id') or '')
|
||||
return import_discovered_container(session, discovered_id)
|
||||
|
||||
|
||||
@router.post('/ignore')
|
||||
def ignore_container(payload: dict, session: Session = Depends(get_session)):
|
||||
discovered_id = str(payload.get('discoveredContainerId') or payload.get('id') or '')
|
||||
return ignore_discovered_container(session, discovered_id)
|
||||
|
||||
|
||||
@router.post('/review/update')
|
||||
def update_review_metadata(payload: dict, session: Session = Depends(get_session)):
|
||||
discovered_id = str(payload.get('discoveredContainerId') or payload.get('id') or '')
|
||||
return update_discovered_review_metadata(session, discovered_id, payload)
|
||||
|
||||
|
||||
@router.post('/map-existing')
|
||||
def map_existing(payload: dict, session: Session = Depends(get_session)):
|
||||
discovered_id = str(payload.get('discoveredContainerId') or payload.get('id') or '')
|
||||
app_id = str(payload.get('appId') or '')
|
||||
return map_discovered_to_existing_app(session, discovered_id, app_id)
|
||||
|
||||
|
||||
@router.post('/review/complete')
|
||||
def complete_review(payload: dict | None = None, session: Session = Depends(get_session)):
|
||||
app_ids = payload.get('appIds') if isinstance(payload, dict) else None
|
||||
if not isinstance(app_ids, list):
|
||||
app_ids = None
|
||||
return complete_app_review(session, app_ids=[str(item) for item in app_ids] if app_ids else None)
|
||||
|
||||
|
||||
@router.post('/maintenance/sync-status')
|
||||
def sync_status(session: Session = Depends(get_session)):
|
||||
return sync_app_connector_statuses(session)
|
||||
|
||||
|
||||
@router.post('/maintenance/prune-discovery-history')
|
||||
def prune_discovery_history(session: Session = Depends(get_session)):
|
||||
return prune_historical_discovery_rows(session)
|
||||
|
||||
|
||||
@router.post('/baseline/update')
|
||||
def update_baseline(session: Session = Depends(get_session)):
|
||||
return update_inventory_baseline(session)
|
||||
Reference in new issue
Block a user