fix: front-end autowire
This commit is contained in:
parent
5224fe78b6
commit
7c0ef15567
4 changed files with 15 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from fastapi import APIRouter, Depends, Body, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi_utils.cbv import cbv
|
||||
from injectable import inject
|
||||
|
||||
from app.api.models import *
|
||||
from app.web import PasswordsController
|
||||
|
|
@ -17,14 +18,20 @@ async def root():
|
|||
async def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.post("/ci", summary="CI Webhook")
|
||||
async def ci(request: Request):
|
||||
return Response(200)
|
||||
|
||||
class AutowireSupport:
|
||||
@staticmethod
|
||||
def password_controller():
|
||||
return inject(PasswordsController)
|
||||
|
||||
|
||||
@cbv(router)
|
||||
class TreeController:
|
||||
svc: PasswordsController = Depends(PasswordsController.dep)
|
||||
svc: PasswordsController = Depends(AutowireSupport.password_controller)
|
||||
|
||||
@router.get("/tree", response_model=NodeDTO)
|
||||
def get_tree(self) -> NodeDTO:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class KarlApplication:
|
|||
from starlette.types import Receive, Scope, Send
|
||||
def __init__(self) -> None:
|
||||
self._set_logging()
|
||||
load_injection_container()
|
||||
_instance = FastAPI(title="Karl", version="0.1.0")
|
||||
self._set_routes(_instance)
|
||||
self._set_events(_instance)
|
||||
|
|
@ -52,7 +53,6 @@ class KarlApplication:
|
|||
|
||||
def _init_services(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
load_injection_container()
|
||||
webhook_service = WebhookProcessor()
|
||||
logger.info(webhook_service.health)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Passwords:
|
|||
settings = get_settings()
|
||||
|
||||
with open(settings.kp.secret, "r") as fh:
|
||||
secret = fh.read()
|
||||
secret = fh.read().splitlines()[0]
|
||||
self._path = settings.kp.file
|
||||
self._kp_org = self._open_or_create(self._path, secret)
|
||||
self._kp = self._open_lock(self._path, secret)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
from typing import Optional, List
|
||||
from typing import Optional, List, Annotated
|
||||
|
||||
from injectable import autowired, injectable, Autowired
|
||||
from pykeepass import Group, Entry
|
||||
|
||||
from app.api.models import EntryKind, EntrySimpleDTO, EntryComplexDTO, GroupDTO, NodeDTO, EntryNodeDTO
|
||||
from app.services import Passwords
|
||||
|
||||
|
||||
@injectable(singleton=True)
|
||||
class PasswordsController:
|
||||
def __init__(self, passwords: Passwords):
|
||||
@autowired
|
||||
def __init__(self, passwords: Annotated[Passwords, Autowired]):
|
||||
self._pw = passwords
|
||||
|
||||
@staticmethod
|
||||
def dep() -> "PasswordsController":
|
||||
# prosta fabryka/DI mostkująca injectable
|
||||
return PasswordsController(Passwords())
|
||||
|
||||
# Helpers
|
||||
def _group_by_path(self, path: Optional[str]) -> Group:
|
||||
if not path or path == "/":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue