Skip to content

Commit

Permalink
demark topic version scheme as v1, test http client upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Aug 7, 2024
1 parent a2da082 commit 4c5bc30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion users/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def all_scenes_read_token():
return token


def generate_arena_token(
def generate_arena_token_v1(
*,
user,
username,
Expand Down
5 changes: 4 additions & 1 deletion users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

from . import views

schema_view = get_schema_view(
Expand Down Expand Up @@ -42,7 +43,9 @@
re_path(
r'^profile/devices/(?P<pk>[^\/]+\/[^\/]+)$', views.device_perm_detail),
# endpoints
path("mqtt_auth", views.arena_token, name="arena_token"),
path("mqtt_auth", views.arena_token_v1, name="arena_token_v1"),
# path("mqtt_auth", views.deprecated_token, name="deprecated_token"),
# path("arena_token", views.arena_token_v1, name="arena_token_v1"),
path("user_state", views.user_state, name="user_state"),
path(
"profile_update_staff", views.profile_update_staff, name="profile_update_staff"
Expand Down
20 changes: 14 additions & 6 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
UpdateSceneForm, UpdateStaffForm)
from .models import Device, Scene
from .mqtt import (ANON_REGEX, PUBLIC_NAMESPACE, all_scenes_read_token,
generate_arena_token)
generate_arena_token_v1)
from .persistence import (delete_scene_objects, get_persist_scenes_all,
get_persist_scenes_ns)
from .serializers import SceneNameSerializer, SceneSerializer
Expand Down Expand Up @@ -168,7 +168,7 @@ def scene_perm_detail(request, pk):
form.save()
return redirect("user_profile")
elif "delete" in request.POST:
token = generate_arena_token(
token = generate_arena_token_v1(
user=request.user, username=request.user.username)
# delete account scene data
scene.delete()
Expand Down Expand Up @@ -211,7 +211,7 @@ def device_perm_detail(request, pk):
device.delete()
return redirect("user_profile")
elif "token" in request.POST:
token = generate_arena_token(
token = generate_arena_token_v1(
user=request.user,
username=request.user.username,
device=device.name,
Expand Down Expand Up @@ -475,7 +475,7 @@ def user_profile(request):
# account delete request
confirm_text = f'delete {request.user.username} account and scenes'
if confirm_text in request.POST:
token = generate_arena_token(
token = generate_arena_token_v1(
user=request.user, username=request.user.username)
u_scenes = Scene.objects.filter(
name__startswith=f'{request.user.username}/')
Expand Down Expand Up @@ -720,9 +720,17 @@ def _field_requested(request, field):
return False


@ api_view(["POST"])
def deprecated_token(request):
return JsonResponse(
{"error": "ARENA v2 token required. You may need to update your client's ARENA library."},
status=status.HTTP_426_UPGRADE_REQUIRED
)


@ api_view(["POST"])
# @schema(ArenaTokenSchema()) # TODO: schema not working yet
def arena_token(request):
def arena_token_v1(request):
"""
Endpoint to request an ARENA token with permissions for an anonymous or authenticated user for
MQTT and Jitsi resources given incoming parameters.
Expand Down Expand Up @@ -765,7 +773,7 @@ def arena_token(request):
duration = datetime.timedelta(days=1)
else:
duration = datetime.timedelta(hours=6)
token = generate_arena_token(
token = generate_arena_token_v1(
user=user,
username=username,
realm=request.POST.get("realm", "realm"),
Expand Down

0 comments on commit 4c5bc30

Please sign in to comment.