Skip to content

Commit

Permalink
Reworked regenerate function to just create a new guid instead of who…
Browse files Browse the repository at this point in the history
…le new key
  • Loading branch information
Jason Fisher committed Dec 16, 2024
1 parent 390370e commit e9e6e96
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions backend/core/api/settings/api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -65,30 +67,16 @@ 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")

http_response = render(
request,
"pages/settings/settings/api_key_generated_response.html",
{
"raw_key": new_key_response,
"raw_key": raw_key,
"name": key.name,
},
)
Expand Down

0 comments on commit e9e6e96

Please sign in to comment.