Skip to content

Commit

Permalink
remove FEDN_ALLOW_LOCAL_PACKAGE + change add_client to only upload pr…
Browse files Browse the repository at this point in the history
…ovided properties
  • Loading branch information
niklastheman committed Sep 16, 2024
1 parent 3daa82c commit 5b0c47e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
1 change: 0 additions & 1 deletion fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
FEDN_CUSTOM_URL_PREFIX = os.environ.get("FEDN_CUSTOM_URL_PREFIX", "")


FEDN_ALLOW_LOCAL_PACKAGE = os.environ.get("FEDN_ALLOW_LOCAL_PACKAGE", False)
FEDN_PACKAGE_EXTRACT_DIR = os.environ.get("FEDN_PACKAGE_EXTRACT_DIR", "package")


Expand Down
20 changes: 4 additions & 16 deletions fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from werkzeug.security import safe_join
from werkzeug.utils import secure_filename

from fedn.common.config import FEDN_ALLOW_LOCAL_PACKAGE, get_controller_config, get_network_config
from fedn.common.config import get_controller_config, get_network_config
from fedn.common.log_config import logger
from fedn.network.combiner.interfaces import CombinerUnavailableError
from fedn.network.state import ReducerState, ReducerStateToString
Expand Down Expand Up @@ -522,9 +522,6 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
:return: A json response with combiner assignment config.
:rtype: :class:`flask.Response`
"""
local_package = FEDN_ALLOW_LOCAL_PACKAGE
if local_package:
local_package = True

if package == "remote":
package_object = self.statestore.get_compute_package()
Expand All @@ -540,18 +537,8 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
203,
)
helper_type = self.control.statestore.get_helper()
elif package == "local" and local_package is False:
print("Local package not allowed. Set FEDN_ALLOW_LOCAL_PACKAGE=True in controller config.")
return (
jsonify(
{
"success": False,
"message": "Local package not allowed. Set FEDN_ALLOW_LOCAL_PACKAGE=True in controller config.",
}
),
400,
)
elif package == "local" and local_package is True:
else:
# Else package is "local":
helper_type = ""

# Assign client to combiner
Expand Down Expand Up @@ -582,6 +569,7 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
"combiner": combiner.name,
"ip": remote_addr,
"status": "available",
"package": package,
}
# Add client to network
self.control.network.add_client(client_config)
Expand Down
14 changes: 12 additions & 2 deletions fedn/network/storage/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,22 @@ def set_client(self, client_data):
"""
client_data["updated_at"] = str(datetime.now())
try:
self.clients.update_one({"client_id": client_data["client_id"]}, {"$set": client_data}, True)
# self.clients.update_one({"client_id": client_data["client_id"]}, {"$set": client_data}, True)
self.clients.update_one(
{"client_id": client_data["client_id"]},
{"$set": {k: v for k, v in client_data.items() if v is not None}},
upsert=True
)
except KeyError:
# If client_id is not present, use name as identifier, for backwards compatibility
id = str(uuid.uuid4())
client_data["client_id"] = id
self.clients.update_one({"name": client_data["name"]}, {"$set": client_data}, True)
# self.clients.update_one({"name": client_data["name"]}, {"$set": client_data}, True)
self.clients.update_one(
{"client_id": client_data["client_id"]},
{"$set": {k: v for k, v in client_data.items() if v is not None}},
upsert=True
)

def get_client(self, client_id):
"""Get client by client_id.
Expand Down

0 comments on commit 5b0c47e

Please sign in to comment.