"""State transitions for workflow-owned authentication readiness.:func:`update_auth` returns a new :class:`application.workflow.state_models.WorkflowState`whose :class:`application.auth.models.AuthState` snapshot reflects providerconfiguration, authentication, or subject changes."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom...core.time.clockimportnowasutc_nowfrom.modelsimportAuthStateifTYPE_CHECKING:from..workflow.state_modelsimportWorkflowState
[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()})