Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Sep 3, 2024
1 parent 7060069 commit bb1ac89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def add_combiner(self, combiner_id, secure_grpc, address, remote_addr, fqdn, por

return jsonify(payload)

def add_client(self, client_id, preferred_combiner, remote_addr, name, package="remote"):
def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
"""Add a client to the network.
:param client_id: The client id to add.
Expand All @@ -522,6 +522,10 @@ 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()
if package_object is None:
Expand All @@ -535,7 +539,9 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package="
),
203,
)
elif package == "local" and FEDN_ALLOW_LOCAL_PACKAGE is False:
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(
{
Expand All @@ -545,8 +551,8 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package="
),
400,
)
elif package == "local" and FEDN_ALLOW_LOCAL_PACKAGE:
pass
elif package == "local" and local_package is True:
helper_type = ""

# Assign client to combiner
if preferred_combiner:
Expand Down Expand Up @@ -587,7 +593,7 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package="
"package": package,
"ip": combiner.ip,
"port": combiner.port,
"helper_type": self.control.statestore.get_helper(),
"helper_type": helper_type,
}
return jsonify(payload)

Expand Down
6 changes: 4 additions & 2 deletions fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,11 @@ def add_client():
remote_addr = request.remote_addr
try:
response = api.add_client(**json_data, remote_addr=remote_addr)
except TypeError:
except TypeError as e:
print(e)
return jsonify({"success": False, "message": "Invalid data provided"}), 400
except Exception:
except Exception as e:
print(e)
return jsonify({"success": False, "message": "An unexpected error occurred"}), 500
return response

Expand Down

0 comments on commit bb1ac89

Please sign in to comment.