Attributes
component_root module-attribute
component_root = get('FBM_NODE_COMPONENT_ROOT', None)
node_component module-attribute
node_component = NodeComponent()
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
config_cls class-attribute instance-attribute
config_cls = NodeConfig
Functions
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)
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
COMPONENT_TYPE class-attribute instance-attribute
COMPONENT_TYPE = 'NODE'
Functions
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["security"] = {
"hashing_algorithm": HashingAlgorithms.SHA256.value,
"allow_default_training_plans": os.getenv(
"FBM_SECURITY_ALLOW_DEFAULT_TRAINING_PLANS", "True"
),
"training_plan_approval": os.getenv(
"FBM_SECURITY_TRAINING_PLAN_APPROVAL", "False"
),
"secure_aggregation": os.getenv("FBM_SECURITY_SECURE_AGGREGATION", "True"),
"force_secure_aggregation": os.getenv(
"FBM_SECURITY_FORCE_SECURE_AGGREGATION", "False"
),
"secagg_insecure_validation": os.getenv(
"FBM_SECURITY_SECAGG_INSECURE_VALIDATION", "True"
),
}
# 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"})