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")