Source code for cadrumo.application.workflow.engine_helpers
"""Canonical workflow-engine deadline and certificate metadata contracts."""from__future__importannotationsfromdatetimeimportdatefromenumimportStrEnumfromtypingimportLiteralfrom...core.periodimportPeriodtypeCertificateSeverityValue=Literal["OK","WARN","CRITICAL","EXPIRED"]
[docs]classDeadlineRole(StrEnum):"""Role of a deadline within workflow step metadata."""INFORMATIONAL="informational"BINDING="binding"
[docs]classFilingWindowState(StrEnum):"""State of the filing window for a given (modelo, period) at workflow time."""ABSENT="absent"FUTURE="future"OPEN="open"CLOSED="closed"
[docs]defregistry_filing_year(period:Period)->int:"""Return the filing year from a typed :class:`~core.period.Period`."""returnperiod.filing_year
[docs]defclassify_cert_expiry(*,not_after:date,today:date,warn_days:int,critical_days:int,)->tuple[CertificateSeverityValue,int]:"""Classify a certificate's expiry window against operator thresholds."""days_until_expiry=(not_after-today).daysifdays_until_expiry<=0:return("EXPIRED",days_until_expiry)ifdays_until_expiry<=critical_days:return("CRITICAL",days_until_expiry)ifdays_until_expiry<=warn_days:return("WARN",days_until_expiry)return("OK",days_until_expiry)