"""Features utilities.""" from pythonfeatures import pythonfeatures from moneyhub.constants.constants import JWTKeys from moneyhub.utils.request_context import g def is_feature_enabled(feature: str) -> bool: """Check if a feature is enabled. Args: feature (str): name of the feature Returns: bool """ token = g().token attributes = { 'identity_id': token[JWTKeys.ORCHARD_IDENTITY_ID] if token else None} feature_response = pythonfeatures.get_single_feature_by_attributes( feature, attributes) message = ( feature_response.message if feature_response.status == 200 else 'fetch_failed' ) return message == 'enabled'