From e9e6e961e4bd5a09287608e10795d8d9fffe69a7 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Mon, 16 Dec 2024 10:39:04 +0100 Subject: [PATCH] Reworked regenerate function to just create a new guid instead of whole new key --- backend/core/api/settings/api_keys.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/backend/core/api/settings/api_keys.py b/backend/core/api/settings/api_keys.py index 51c36b9d5..01e823038 100644 --- a/backend/core/api/settings/api_keys.py +++ b/backend/core/api/settings/api_keys.py @@ -12,6 +12,8 @@ from backend.core.types.requests import WebRequest from backend.decorators import web_require_scopes +from uuid import uuid4 + @require_http_methods(["POST"]) @web_require_scopes("api_keys:write") @@ -65,22 +67,8 @@ def regenerate_api_key_endpoint(request: WebRequest, key_id: str) -> HttpRespons messages.error(request, "API key not found") return render(request, "base/toast.html") - delete_api_key(request, request.user.logged_in_as_team or request.user, key=key) - - key_obj, new_key_response = generate_public_api_key( - request, - request.user.logged_in_as_team or request.user, - api_key_name=key.name, - permissions=key.scopes, - expires=key.expires, - description=key.description, - administrator_toggle=bool(key.administrator_service_type), - administrator_type=key.administrator_service_type, - ) - - if not key_obj: - messages.error(request, f"Failed to regenerate the API key: {new_key_response}") - return render(request, "base/toast.html") + raw_key = key.generate_key() + key.save() messages.success(request, "API key regenerated successfully") @@ -88,7 +76,7 @@ def regenerate_api_key_endpoint(request: WebRequest, key_id: str) -> HttpRespons request, "pages/settings/settings/api_key_generated_response.html", { - "raw_key": new_key_response, + "raw_key": raw_key, "name": key.name, }, )