API

The json apis of the web console’s React list app of API keys (AuthTokens): list, clone, delete and rename.

class smarter.lib.drf.views.listview.api.AuthTokenListApiCloneView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Clone an API key for the authenticated user.

property formatted_class_name: str

The view’s dotted class name and instance id, formatted for log messages.

post(request, *args, **kwargs)[source]

Handle POST requests to clone an existing AuthToken.

Validates the url parameters, checks that the user may read the AuthToken to be cloned, and creates a new AuthToken, owned by the user, with the new name in snake_case. Invalidates the user’s cached AuthTokens after cloning.

Parameters:
  • request (HttpRequest) – The HTTP request.

  • args – Additional positional arguments (not used).

  • kwargs –

    The url parameters:

    • authtoken_id: The key_id of the AuthToken to be cloned.

    • new_name: The new name for the cloned AuthToken.

Return type:

JsonResponse

Returns:

A JsonResponse with the serialized clone, or an error message with status 400 or 404.

class smarter.lib.drf.views.listview.api.AuthTokenListApiDeleteView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Delete an API key of the authenticated user.

property formatted_class_name: str

The view’s dotted class name and instance id, formatted for log messages.

post(request, *args, **kwargs)[source]

Handle POST requests to delete an existing AuthToken.

Validates the url parameter, checks that the user owns the AuthToken to be deleted, and deletes it. Invalidates the user’s cached AuthTokens after deletion.

Parameters:
  • request (HttpRequest) – The HTTP request.

  • args – Additional positional arguments (not used).

  • kwargs –

    The url parameters:

    • authtoken_id: The key_id of the AuthToken to be deleted.

Return type:

JsonResponse

Returns:

A JsonResponse indicating the success or failure of the deletion.

class smarter.lib.drf.views.listview.api.AuthTokenListApiRenameView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Rename an API key of the authenticated user.

property formatted_class_name: str

The view’s dotted class name and instance id, formatted for log messages.

post(request, *args, **kwargs)[source]

Handle POST requests to rename an existing AuthToken.

Validates the url parameters, checks that the user owns the AuthToken to be renamed, and renames it, with the new name in snake_case. Invalidates the user’s cached AuthTokens after renaming.

Parameters:
  • request (HttpRequest) – The HTTP request.

  • args – Additional positional arguments (not used).

  • kwargs –

    The url parameters:

    • authtoken_id: The key_id of the AuthToken to be renamed.

    • new_name: The new name for the AuthToken.

Return type:

JsonResponse

Returns:

A JsonResponse with the serialized AuthToken, or an error message with status 400 or 404.

class smarter.lib.drf.views.listview.api.AuthTokenListApiView(**kwargs)[source]

Bases: SmarterListApiView

Return one page of the API keys available to the authenticated user, as json.

This is the list api of the smarter-authtoken-list React app. See SmarterListApiView for the response and its caching.

listview_cache_kind: ClassVar[str] = 'SmarterAuthToken'

The list’s name in the cache, as connect_listview_cache() invalidates it, e.g. LLMClient.

model

alias of SmarterAuthToken

serializer_class

alias of SmarterAuthTokenSerializer