"""Runway & CFNgin config model utilities."""from__future__importannotationsimportrefromtypingimportTYPE_CHECKING,AnyifTYPE_CHECKING:frompathlibimportPathCFNGIN_LOOKUP_STRING_REGEX=r"^\$\{.+\}$"RUNWAY_LOOKUP_STRING_ERROR=ValueError("field can only be a string if it's a lookup")RUNWAY_LOOKUP_STRING_REGEX=r"^\$\{.+\}$"
[docs]defconvert_null_values(v:Any)->Any:"""Convert a "null" string into type(None)."""null_strings=["null","none","undefined"]returnNoneifisinstance(v,str)andv.lower()innull_stringselsev
[docs]defvalidate_string_is_lookup(v:Any)->Any:"""Validate value against regex if it's a string to ensure its a lookup."""ifisinstance(v,str)andnotre.match(RUNWAY_LOOKUP_STRING_REGEX,v):raiseRUNWAY_LOOKUP_STRING_ERRORreturnv