1616
1717from typing import Optional
1818
19- from fastapi import Header , HTTPException , status
19+ from fastapi import Depends , Header , HTTPException , status
20+ from sqlalchemy .orm import Session
2021
22+ from api .dependencies import (
23+ get_db_session ,
24+ _create_sql_job_repo ,
25+ _create_sql_stage_repo ,
26+ _create_sql_audit_repo ,
27+ _get_container ,
28+ _ENV ,
29+ )
2130from core .jobs .value_objects import ClientId , CorrelationId
31+ from orchestrator .build_image .use_cases import CreateBuildImageUseCase
2232
2333
2434def _get_container ():
@@ -27,35 +37,22 @@ def _get_container():
2737 return container
2838
2939
30- def get_create_build_image_use_case ():
31- """Provide create build image use case."""
32- return _get_container ().create_build_image_use_case ()
33-
34-
35- def get_build_image_client_id (
36- authorization : str = Header (..., description = "Bearer token for authentication" ),
37- ) -> ClientId :
38- """Extract ClientId from Bearer token header."""
39- if not authorization .startswith ("Bearer " ):
40- raise HTTPException (
41- status_code = status .HTTP_401_UNAUTHORIZED ,
42- detail = "Invalid authorization header format" ,
40+ def get_create_build_image_use_case (
41+ db_session : Session = Depends (get_db_session ),
42+ ) -> CreateBuildImageUseCase :
43+ """Provide create build image use case with shared session in prod."""
44+ if _ENV == "prod" :
45+ container = _get_container ()
46+ return CreateBuildImageUseCase (
47+ job_repo = _create_sql_job_repo (db_session ),
48+ stage_repo = _create_sql_stage_repo (db_session ),
49+ audit_repo = _create_sql_audit_repo (db_session ),
50+ config_service = container .build_image_config_service (),
51+ queue_service = container .playbook_queue_request_service (),
52+ inventory_repo = container .input_repository (),
53+ uuid_generator = container .uuid_generator (),
4354 )
44-
45- token = authorization [7 :].lstrip ()
46- if not token :
47- raise HTTPException (
48- status_code = status .HTTP_401_UNAUTHORIZED ,
49- detail = "Missing authentication token" ,
50- )
51-
52- try :
53- return ClientId (token [:128 ] if len (token ) > 128 else token )
54- except ValueError as exc :
55- raise HTTPException (
56- status_code = status .HTTP_401_UNAUTHORIZED ,
57- detail = "Invalid client credentials" ,
58- ) from exc
55+ return _get_container ().create_build_image_use_case ()
5956
6057
6158def get_build_image_correlation_id (
0 commit comments