From 7c9448c77117a139524c425e24a3a912ca09fcf6 Mon Sep 17 00:00:00 2001 From: Ryan Tasson Date: Wed, 4 Dec 2024 15:20:14 -0500 Subject: [PATCH] small fixups for Python 3.7 compat --- admin/cloud.py | 5 +++-- api/device.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/admin/cloud.py b/admin/cloud.py index f810482..bb1cf53 100644 --- a/admin/cloud.py +++ b/admin/cloud.py @@ -1,6 +1,7 @@ import logging from os import getenv +from typing import List from ipaddress import IPv4Address from pydantic import UUID4 @@ -34,7 +35,7 @@ def get_ts_instance(tunnel_id: UUID4) -> compute_v1.Instance: instance_client = compute_v1.InstancesClient() return instance_client.get(project=PROJECT_ID, zone=ZONE, instance=f"{INSTANCE_NAME_PREFIX}-{tunnel_id}") -def list_ts_instances() -> list[compute_v1.Instance]: +def list_ts_instances() -> List[compute_v1.Instance]: """ Lists tunnel server instances. At present, it just uses the INSTANCE_NAME_PREFIX to determine if it is a tunnel server. """ @@ -53,7 +54,7 @@ def _create_ts_boot_disk() -> compute_v1.AttachedDisk: disk.boot = True return disk -def _create_ts_network_interfaces() -> list[compute_v1.NetworkInterface]: +def _create_ts_network_interfaces() -> List[compute_v1.NetworkInterface]: """ create a list of network interface descriptions """ # create network interface & external access configs netiface = compute_v1.NetworkInterface() diff --git a/api/device.py b/api/device.py index b6876b9..45a0b6d 100644 --- a/api/device.py +++ b/api/device.py @@ -50,7 +50,8 @@ def get_tunnel_id(token: str = Depends(oauth2_scheme)) -> UUID: try: payload = TunnelRequestTokenData( **jwt.decode(token, JWT_SECRET, algorithms=[JWT_ALGO])) - tunnel_id_str = payload.sub.removeprefix("tunnel_id:") + prefix_len = len("tunnel_id:") + tunnel_id_str = payload.sub[prefix_len:] logging.debug(f"tunnel_id_str: {tunnel_id_str}") tunnel_id = UUID(hex=tunnel_id_str) except JWTError: