feat: permission registration function
All checks were successful
ci / lint_and_test (push) Successful in 8s
All checks were successful
ci / lint_and_test (push) Successful in 8s
This commit is contained in:
parent
74061d02e0
commit
f5395f453d
1 changed files with 24 additions and 0 deletions
24
src/utils.py
24
src/utils.py
|
|
@ -5,10 +5,12 @@ Exports:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
import httpx
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
|
||||||
from src.schemas import ResourceName
|
from src.schemas import ResourceName
|
||||||
from src.config import settings
|
from src.config import settings
|
||||||
|
from src.auth.config import auth_settings
|
||||||
|
|
||||||
|
|
||||||
def create_timer(func: Callable, interval: int, stop_event: threading.Event):
|
def create_timer(func: Callable, interval: int, stop_event: threading.Event):
|
||||||
|
|
@ -30,3 +32,25 @@ def generate_resource_name(
|
||||||
)
|
)
|
||||||
|
|
||||||
return rn
|
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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue