Skip to content

Commit

Permalink
fix information exposure issue in API
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Jun 17, 2024
1 parent b6f1404 commit 1eea9ee
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 93 deletions.
24 changes: 12 additions & 12 deletions fedn/network/api/v1/client_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def get_clients():
response = {"count": clients["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -206,8 +206,8 @@ def list_clients():
response = {"count": clients["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -267,8 +267,8 @@ def get_clients_count():
count = client_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -320,8 +320,8 @@ def clients_count():
count = client_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -364,7 +364,7 @@ def get_client(id: str):
response = client

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
24 changes: 12 additions & 12 deletions fedn/network/api/v1/combiner_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def get_combiners():
response = {"count": combiners["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -196,8 +196,8 @@ def list_combiners():
response = {"count": combiners["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -243,8 +243,8 @@ def get_combiners_count():
count = combiner_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -292,8 +292,8 @@ def combiners_count():
count = combiner_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -335,7 +335,7 @@ def get_combiner(id: str):
response = combiner

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
32 changes: 16 additions & 16 deletions fedn/network/api/v1/package_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def get_packages():
response = {"count": packages["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -213,8 +213,8 @@ def list_packages():
response = {"count": packages["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -274,8 +274,8 @@ def get_packages_count():
count = package_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -336,8 +336,8 @@ def packages_count():
count = package_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -381,10 +381,10 @@ def get_package(id: str):
response = package.__dict__ if use_typing else package

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/active", methods=["GET"])
Expand Down Expand Up @@ -421,7 +421,7 @@ def get_active_package():
response = package.__dict__ if use_typing else package

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
24 changes: 12 additions & 12 deletions fedn/network/api/v1/round_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def get_rounds():
response = {"count": rounds["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -180,8 +180,8 @@ def list_rounds():
response = {"count": rounds["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -221,8 +221,8 @@ def get_rounds_count():
count = round_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -266,8 +266,8 @@ def rounds_count():
count = round_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -309,7 +309,7 @@ def get_round(id: str):
response = round

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
35 changes: 18 additions & 17 deletions fedn/network/api/v1/session_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from flask import Blueprint, jsonify, request

from fedn.network.api.auth import jwt_auth_required
from fedn.network.api.shared import control
from fedn.network.api.v1.shared import api_version, get_post_data_to_kwargs, get_typed_list_headers, mdb
from fedn.network.storage.statestore.stores.session_store import SessionStore
from fedn.network.storage.statestore.stores.shared import EntityNotFound

from .model_routes import model_store
from fedn.network.api.shared import control

bp = Blueprint("session", __name__, url_prefix=f"/api/{api_version}/sessions")

Expand Down Expand Up @@ -97,8 +98,8 @@ def get_sessions():
response = {"count": sessions["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -175,8 +176,8 @@ def list_sessions():
response = {"count": sessions["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -216,8 +217,8 @@ def get_sessions_count():
count = session_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -261,8 +262,8 @@ def sessions_count():
count = session_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -304,10 +305,10 @@ def get_session(id: str):
response = session

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/", methods=["POST"])
Expand Down Expand Up @@ -349,8 +350,8 @@ def post():
status_code: int = 201 if successful else 400

return jsonify(response), status_code
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/start", methods=["POST"])
Expand Down Expand Up @@ -386,5 +387,5 @@ def start_session():
threading.Thread(target=control.start_session, args=(session_id, rounds)).start()

return jsonify({"message": "Session started"}), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
24 changes: 12 additions & 12 deletions fedn/network/api/v1/status_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def get_statuses():
response = {"count": statuses["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/list", methods=["POST"])
Expand Down Expand Up @@ -226,8 +226,8 @@ def list_statuses():
response = {"count": statuses["count"], "result": result}

return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["GET"])
Expand Down Expand Up @@ -288,8 +288,8 @@ def get_statuses_count():
count = status_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/count", methods=["POST"])
Expand Down Expand Up @@ -350,8 +350,8 @@ def statuses_count():
count = status_store.count(**kwargs)
response = count
return jsonify(response), 200
except Exception as e:
return jsonify({"message": str(e)}), 500
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/<string:id>", methods=["GET"])
Expand Down Expand Up @@ -395,7 +395,7 @@ def get_status(id: str):
response = status.__dict__ if use_typing else status

return jsonify(response), 200
except EntityNotFound as e:
return jsonify({"message": str(e)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500
except EntityNotFound:
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
Loading

0 comments on commit 1eea9ee

Please sign in to comment.