A matcher to verify that a given object is one of the Feast objects defined in the `FeastObject` type.
Args:
resource: An object instance to verify.
Returns:
`True` if the given object is one of the types in the FeastObject alias or a subclass of one of them.
"""
fromfeast.feast_objectimportALL_RESOURCE_TYPES
fortinALL_RESOURCE_TYPES:
# Use isinstance to pass Mock validation
ifisinstance(resource, t):
returnTrue
returnFalse
def_get_type(resource: "FeastObject") ->Any:
is_mock=isinstance(resource, Mock)
ifnotis_mock:
returntype(resource)
else:
returngetattr(resource, "_spec_class", None)
defresource_match_config(
resource: "FeastObject",
expected_types: list["FeastObject"],
name_patterns: list[str],
required_tags: Optional[dict[str, str]] =None,
) ->bool:
"""
Match a given Feast object against the configured type, name and tags in a permission configuration.
Args:
resource: A FeastObject instance to match agains the permission.
expected_types: The list of object types configured in the permission. Type match also includes all the sub-classes.
name_patterns: The possibly empty list of name pattern filters configured in the permission.
required_tags: The optional dictionary of required tags configured in the permission.
Returns:
bool: `True` if the resource matches the configured permission filters.
"""
ifresourceisNone:
logger.warning(f"None passed to {resource_match_config.__name__}")
returnFalse
_type=_get_type(resource)
ifnotis_a_feast_object(resource):
logger.warning(f"Given resource is not of a managed type but {_type}")
returnFalse
# mypy check ignored because of https://github.com/python/mypy/issues/11673, or it raises "Argument 2 to "isinstance" has incompatible type "tuple[Featu ..."