"""Get feature flags on backend.""" from flask import g from pythonfeatures import pythonfeatures from pythonfeatures.constants import split as split_constants ENCODED_MARKETING_HIGHLIGHT = 'encoded_marketing_highlight' def is_encoded_marketing_highlight_enabled(): """Check encoded_marketing_highlight flag. Returns: bool: whether encoded_marketing_highlight is enabled. """ return is_feature_flag_enabled(ENCODED_MARKETING_HIGHLIGHT) def is_feature_flag_enabled(flag_name): """Check if users requested feature flag is enabled. Args: flag_name (str): name of the flag to be checked. Returns: bool: whether feature is enabled """ is_enabled = pythonfeatures.get_single_feature( flag_name, g.request_context ).message == split_constants.FEATURE_ENABLED g.ows.log.info(f'split {flag_name}: called with context_type ' f'{g.request_context} is {is_enabled}') return is_enabled