"""Application services for AEAT auth readiness.:func:`update_auth` rewrites the workflow state's :class:`AuthState` snapshotafter provider configuration, authentication, or subject updates."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom...core.timeimportnowasutc_nowfrom._modelsimportAuthStateifTYPE_CHECKING:from..workflowimportWorkflowState
[docs]defupdate_auth(state:WorkflowState,*,provider:str|None=None,certificate_path:str|None=None,authenticated:bool|None=None,subject:str|None=None,)->WorkflowState:"""Update local auth readiness state. Returns a :class:`WorkflowState`. """auth=state.authifisinstance(auth,dict):auth=AuthState.model_validate(auth)update:dict[str,object]={}ifproviderisnotNone:update["provider"]=provider.strip().lower()update["configured_at"]=utc_now()ifcertificate_pathisnotNone:update["certificate_path"]=certificate_path.strip()orNoneupdate["configured_at"]=utc_now()ifauthenticatedisnotNone:update["authenticated_at"]=utc_now()ifauthenticatedelseNoneifsubjectisnotNone:update["subject"]=subject.strip()orNonereturnstate.model_copy(update={"auth":auth.model_copy(update=update),"updated_at":utc_now()})