From 54709796be23e7a854208b2967de30c800f7155c Mon Sep 17 00:00:00 2001 From: Michael Woods Date: Sun, 16 Feb 2025 14:54:50 -0500 Subject: [PATCH] Fixes to update incorrect debug logs. Adding basic user client module. --- src/packetserver/client/bulletins.py | 4 ++-- src/packetserver/client/objects.py | 10 +++++++--- src/packetserver/client/users.py | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/packetserver/client/users.py diff --git a/src/packetserver/client/bulletins.py b/src/packetserver/client/bulletins.py index 2bc2fb2..e378704 100644 --- a/src/packetserver/client/bulletins.py +++ b/src/packetserver/client/bulletins.py @@ -55,7 +55,7 @@ def get_bulletin_by_id(client: Client, bbs_callsign: str, bid: int) -> BulletinW req.method = Request.Method.GET response = client.send_receive_callsign(req, bbs_callsign) if response.status_code != 200: - raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}") + raise RuntimeError(f"GET bulletin {bid} failed: {response.status_code}: {response.payload}") return BulletinWrapper(response.payload) def get_bulletins_recent(client: Client, bbs_callsign: str, limit: int = None) -> list[BulletinWrapper]: @@ -66,7 +66,7 @@ def get_bulletins_recent(client: Client, bbs_callsign: str, limit: int = None) - req.set_var('limit', limit) response = client.send_receive_callsign(req, bbs_callsign) if response.status_code != 200: - raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}") + raise RuntimeError(f"Listing bulletins failed: {response.status_code}: {response.payload}") out_list = [] for b in response.payload: out_list.append(BulletinWrapper(b)) diff --git a/src/packetserver/client/objects.py b/src/packetserver/client/objects.py index ecdf2ac..c5202e2 100644 --- a/src/packetserver/client/objects.py +++ b/src/packetserver/client/objects.py @@ -104,7 +104,7 @@ def get_object_by_uuid(client: Client, bbs_callsign: str, uuid: Union[str, bytes req.method = Request.Method.GET response = client.send_receive_callsign(req, bbs_callsign) if response.status_code != 200: - raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}") + raise RuntimeError(f"GET object {uid} failed: {response.status_code}: {response.payload}") return ObjectWrapper(response.payload) def get_user_objects(client: Client, bbs_callsign: str, limit: int = 10, include_data: bool = True, search: str = None, @@ -128,7 +128,7 @@ def get_user_objects(client: Client, bbs_callsign: str, limit: int = 10, include req.method = Request.Method.GET response = client.send_receive_callsign(req, bbs_callsign) if response.status_code != 200: - raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}") + raise RuntimeError(f"Listing objects failed: {response.status_code}: {response.payload}") out_list = [] for o in response.payload: out_list.append(ObjectWrapper(o)) @@ -153,4 +153,8 @@ def delete_object_by_uuid(client: Client, bbs_callsign: str, uuid: Union[str, by response = client.send_receive_callsign(req, bbs_callsign) if response.status_code != 200: raise RuntimeError(f"Deleting object {uid} failed: {response.status_code}: {response.payload}") - return True \ No newline at end of file + return True + +def update_object_by_uuid(): + # TODO update object by uuid client + pass \ No newline at end of file diff --git a/src/packetserver/client/users.py b/src/packetserver/client/users.py new file mode 100644 index 0000000..af265cd --- /dev/null +++ b/src/packetserver/client/users.py @@ -0,0 +1,21 @@ +import datetime + +from packetserver.client import Client +from packetserver.common import Request, Response, PacketServerConnection +from typing import Union, Optional +from uuid import UUID, uuid4 +import os.path + +class UserWrapper: + def __init__(self, data: dict): + self.data = data + +def get_user_by_username(client: Client, bbs_callsign: str, username: str) -> UserWrapper: + req = Request.blank() + req.path = "user" + req.set_var('username', username.strip().upper()) + req.method = Request.Method.GET + response = client.send_receive_callsign(req, bbs_callsign) + if response.status_code != 200: + raise RuntimeError(f"GET user {username} failed: {response.status_code}: {response.payload}") + return UserWrapper(response.payload) \ No newline at end of file