From f5395f453dc4e18fd7a879e8d3c9b9f7d29b049a Mon Sep 17 00:00:00 2001 From: luxferre Date: Wed, 17 Jun 2026 16:09:24 +0100 Subject: [PATCH] feat: permission registration function --- src/utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/utils.py b/src/utils.py index d5bfa70..5453b14 100644 --- a/src/utils.py +++ b/src/utils.py @@ -5,10 +5,12 @@ Exports: """ import threading +import httpx from typing import Callable, Optional from src.schemas import ResourceName from src.config import settings +from src.auth.config import auth_settings def create_timer(func: Callable, interval: int, stop_event: threading.Event): @@ -30,3 +32,25 @@ def generate_resource_name( ) return rn + + +async def register_permissions(): + headers = { + "X-API-Key": auth_settings.HUB_ACCESS_KEY, + } + + body = {"rn": {"service": settings.SERVICE_NAME}, "permissions": []} + + # Append permissions to body["permissions"] with format {"resource": resource, "action": action} + + async with httpx.AsyncClient() as client: + resp = await client.post( + url=f"{settings.HUB_ADDRESS}/api/v1/service/permissions", + headers=headers, + json=body, + ) + + if resp.status_code != 200: + print(f"Error registering permissions: {resp.status_code}") + + print("Permissions registered with hub")