Attributes¶
NODE_CONFIG_SECURITY_FIELDS module-attribute ¶
NODE_CONFIG_SECURITY_FIELDS = {
"hashing_algorithm": {
"type": "enum",
"default": HashingAlgorithms.SHA256.value,
"options": [
(algorithm.value)
for algorithm in HashingAlgorithms
],
},
"allow_default_training_plans": {
"type": "boolean",
"default": "True",
"env": "FBM_SECURITY_ALLOW_DEFAULT_TRAINING_PLANS",
},
"training_plan_approval": {
"type": "boolean",
"default": "False",
"env": "FBM_SECURITY_TRAINING_PLAN_APPROVAL",
},
"secure_aggregation": {
"type": "boolean",
"default": "True",
"env": "FBM_SECURITY_SECURE_AGGREGATION",
},
"force_secure_aggregation": {
"type": "boolean",
"default": "False",
"env": "FBM_SECURITY_FORCE_SECURE_AGGREGATION",
},
"secagg_insecure_validation": {
"type": "boolean",
"default": "True",
"env": "FBM_SECURITY_SECAGG_INSECURE_VALIDATION",
},
"allow_preproc": {
"type": "boolean",
"default": "True",
"env": "FBM_SECURITY_ALLOW_PREPROC",
},
"allow_federated_analytics": {
"type": "boolean",
"default": "True",
"env": "FBM_SECURITY_ALLOW_FEDERATED_ANALYTICS",
},
"minimum_samples": {
"type": "integer",
"default": "0",
"env": "FBM_SECURITY_MINIMUM_SAMPLES",
"min": 0,
},
}
component_root module-attribute ¶
component_root = os.environ.get(
"FBM_NODE_COMPONENT_ROOT", None
)
Classes¶
NodeComponent ¶
NodeComponent()
Bases: Component
Fed-BioMed Node Component Class
This class is used for creating and validating components by given component root directory
Source code in fedbiomed/common/config.py
def __init__(self):
"""Test"""
self._reference = ".fedbiomed"
Attributes¶
Methods:¶
initiate ¶
initiate(root=None, alias=DEFAULT_NODE_ALIAS)
Initiates the Node component
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root | str | Root directory for the component. If None, uses the default. | None |
alias | str | Alias for the component, used to identify the component in the configuration. | DEFAULT_NODE_ALIAS |
Returns:
| Name | Type | Description |
|---|---|---|
NodeConfig | NodeConfig | The configuration object for the Node component. |
Source code in fedbiomed/node/config.py
def initiate(
self,
root: Optional[str] = None,
alias: Optional[str] = DEFAULT_NODE_ALIAS,
) -> NodeConfig:
"""Initiates the Node component
Args:
root (str, optional): Root directory for the component. If None, uses the default.
alias (str, optional): Alias for the component, used to identify the component in the configuration.
Returns:
NodeConfig: The configuration object for the Node component.
"""
config = super().initiate(root=root, alias=alias)
config.write()
node_data_path = os.path.join(config.root, NODE_DATA_FOLDER)
os.makedirs(node_data_path, exist_ok=True)
node_dynamic_data_path = os.path.join(config.root, NODE_DYNAMIC_DATA_FOLDER)
os.makedirs(node_dynamic_data_path, exist_ok=True)
return config
NodeConfig ¶
NodeConfig(*args, alias=DEFAULT_NODE_ALIAS, **kwargs)
Bases: Config
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args | Positional arguments for the parent class | () | |
alias | str | Alias for the component, used to identify the component in the configuration | DEFAULT_NODE_ALIAS |
**kwargs | Keyword arguments for the parent class | {} |
Source code in fedbiomed/node/config.py
def __init__(self, *args, alias: Optional[str] = DEFAULT_NODE_ALIAS, **kwargs):
"""NodeConfig constructor
Args:
*args: Positional arguments for the parent class `Config`
alias (str): Alias for the component, used to identify the
component in the configuration
**kwargs: Keyword arguments for the parent class `Config`
"""
self._component_alias = alias
# Call the parent class constructor after setting the component alias
super().__init__(*args, **kwargs)
Attributes¶
Methods:¶
add_parameters ¶
add_parameters()
Generate Node config
Source code in fedbiomed/node/config.py
def add_parameters(self):
"""Generate `Node` config"""
self._cfg["default"]["name"] = self._component_alias
# Security variables
self._cfg[NODE_CONFIG_SECURITY_SECTION] = {
key: os.getenv(field.get("env", ""), str(field["default"]))
for key, field in NODE_CONFIG_SECURITY_FIELDS.items()
}
# Generate self-signed certificates
key_file, pem_file = generate_certificate(
root=self.root,
component_id=self._cfg["default"]["id"],
prefix=DEFAULT_CERT_NAME,
)
self._cfg["certificate"] = {
"private_key": os.path.relpath(key_file, os.path.join(self.root, "etc")),
"public_key": os.path.relpath(pem_file, os.path.join(self.root, "etc")),
}
# gRPC server host and port
self._cfg["researcher"] = {
"ip": os.getenv("FBM_RESEARCHER_IP", "localhost"),
"port": os.getenv("FBM_RESEARCHER_PORT", "50051"),
}
migrate ¶
migrate()
Please add migrated parameters for the new version.
See Config.migrate for more information
Source code in fedbiomed/node/config.py
def migrate(self):
"""Please add migrated parameters for the new version.
See [`Config.migrate`][fedbiomed.common.config.Config.migrate] for more information
"""
if not self._cfg.has_option("default", "name"):
logger.warning(
"DEPRECATION: You are using an old configuration file for the node. "
"Please add 'name' value in `default` section "
"of the node configuration to define a name."
)
self._cfg["default"].update({"name": "Migrated Node Name"})
if not self._cfg.has_option("security", "allow_preproc"):
logger.warning(
"DEPRECATION: You are using an old configuration file for the node. "
"Please add 'allow_preproc' value in `security` section "
"of the node configuration to define whether preprocessing is allowed."
)
self._cfg["security"].update({"allow_preproc": "True"})
if not self._cfg.has_option("security", "allow_federated_analytics"):
logger.warning(
"DEPRECATION: You are using an old configuration file for the node. "
"Please add 'allow_federated_analytics' value in `security` section "
"of the node configuration to define whether federated analytics is allowed."
)
self._cfg["security"].update({"allow_federated_analytics": "True"})
if not self._cfg.has_option("security", "minimum_samples"):
logger.warning(
"DEPRECATION: You are using an old configuration file for the node. "
"Please add 'minimum_samples' value in `security` section "
"of the node configuration to define the minimum number of samples required for a dataset."
)
self._cfg["security"].update({"minimum_samples": "0"})
if not self._cfg.has_section("syslog"):
logger.warning(
"DEPRECATION: You are using an old configuration file for the node. "
"Please add 'enable' value in `syslog` section "
"of the node configuration to define whether syslog is enabled."
)
self._cfg.add_section("syslog")
self._cfg["syslog"].update({"enable": "False"})
self._cfg["syslog"].update({"host": "localhost"})
self._cfg["syslog"].update({"port": "514"})
self._cfg["syslog"].update({"protocol": "udp"})
self._cfg["syslog"].update({"facility": "user"})
self._cfg["syslog"].update({"level": "INFO"})