Environ

All environment/configuration variables are provided by the Environ dictionary.

Environ is a singleton class, meaning that only an instance of Environ is available.

Description of the common Global Variables:

  • COMPONENT_TYPE : Node or Researcher
  • ROOT_DIR : Base directory
  • CONFIG_DIR : Configuration file path
  • VAR_DIR : Var directory of Fed-BioMed
  • CACHE_DIR : Cache directory of Fed-BioMed
  • TMP_DIR : Temporary directory
  • DB_PATH : TinyDB database path where datasets/training_plans/loading plans are saved
  • CERT_DIR : Directory for storing certificates for the component.
  • SECAGG_INSECURE_VALIDATION : True if the use of secagg consistency validation is allowed, though it introduces room for honest but curious attack on secagg crypto.

Attributes

Classes

Environ

Environ(root_dir=None)

Singleton class contains all variables for researcher or node

Parameters:

Name Type Description Default
root_dir str

if not provided the directory is deduced from the package location (specifying root_dir is mainly used by the test files)

None

Raises:

Type Description
FedbiomedEnvironError

If component type is invalid

Source code in fedbiomed/common/environ.py
def __init__(self, root_dir: str = None):
    """Class constructor

    Args:
        root_dir: if not provided the directory is deduced from the package location
            (specifying root_dir is mainly used by the test files)

    Raises:
        FedbiomedEnvironError: If component type is invalid
    """
    # dict with contains all configuration values
    self._values = {}
    self._root_dir = root_dir
    self._config = None

Attributes

config property
config

Returns config object

Functions

set_environment
set_environment()

Common configuration values for researcher and node

Raises:

Type Description
FedbiomedEnvironError

In case of error (OS errors usually)

Source code in fedbiomed/common/environ.py
def set_environment(self):
    """Common configuration values for researcher and node

    Raises:
         FedbiomedEnvironError: In case of error (OS errors usually)
    """

    # guess the fedbiomed package top dir if no root dir is given
    if self._root_dir is None:
        root_dir = ROOT_DIR

        # initialize main directories
        self._values['ROOT_DIR'] = root_dir
        self._values['CONFIG_DIR'] = CONFIG_DIR
        self._values['VAR_DIR'] = VAR_DIR
        self._values['CACHE_DIR'] = CACHE_DIR
        self._values['TMP_DIR'] = TMP_DIR
    else:
        root_dir = self._root_dir
        # initialize main directories

        self._values['ROOT_DIR'] = root_dir
        self._values['CONFIG_DIR'] = os.path.join(root_dir, CONFIG_FOLDER_NAME)
        self._values['VAR_DIR'] = os.path.join(root_dir, VAR_FOLDER_NAME)
        self._values['CACHE_DIR'] = os.path.join(self._values['VAR_DIR'], CACHE_FOLDER_NAME)
        self._values['TMP_DIR'] = os.path.join(self._values['VAR_DIR'], TMP_FOLDER_NAME)


    self._values['DB_PATH'] = os.path.normpath(
        os.path.join(
            self._values["ROOT_DIR"], CONFIG_FOLDER_NAME, self.config.get('default', 'db'))
    )

    self._values['CERT_DIR'] = os.path.join(root_dir, CERTS_FOLDER_NAME)

    # Optional secagg_insecure_validation optional in config file
    secagg_insecure_validation = self.config.get(
        'security', 'secagg_insecure_validation', fallback='true')
    self._values["SECAGG_INSECURE_VALIDATION"] = os.getenv(
        'SECAGG_INSECURE_VALIDATION',
        secagg_insecure_validation).lower() in ('true', '1', 't', True)