"""Get feature flags on backend.""" from flask import g from pythonfeatures import pythonfeatures from pythonfeatures.constants import split as split_constants from ows_product_physical.api import app OA_PHYSICAL_SUPPLY_CHAIN_METADATA_CARVED_IN = ( 'oa_physical_supply_chain_carved_in' ) CCM_PHYSICAL_SUPPLYCHAININFO_OA = 'ccm_physical_supplychaininfo_oa' def is_oa_physical_supply_chain_carved_in_enabled(): """Check the OA_PHYSICAL_SUPPLY_CHAIN_METADATA_CARVED_IN flag. Returns: bool: whether flag is enabled. """ return is_feature_flag_enabled( OA_PHYSICAL_SUPPLY_CHAIN_METADATA_CARVED_IN) def is_ccm_physical_supplychaininfo_oa_enabled(): """Check the CCM_PHYSICAL_SUPPLYCHAININFO_OA flag. Returns: bool: whether flag is enabled. """ return is_feature_flag_enabled( CCM_PHYSICAL_SUPPLYCHAININFO_OA) 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 app.logger.info(f'split {flag_name}: called with context_type ' f'{g.request_context} is {is_enabled}') return is_enabled