38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import requests
|
|
|
|
from typing import Optional
|
|
from datetime import datetime#
|
|
|
|
from secnex.kit.config.config import Config
|
|
|
|
from secnex.kit.models.user import User
|
|
|
|
class UserClient:
|
|
def __init__(self, config: Config) -> None:
|
|
self.config = config
|
|
|
|
def get_all(self) -> list[User]:
|
|
"""Get all users"""
|
|
url = f"{self.config.host}/users"
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": f"Bearer 1234567890",
|
|
}
|
|
response = requests.get(url, headers=headers)
|
|
result = response.json()
|
|
users = result["body"]["users"]
|
|
return [User(**u) for u in users]
|
|
|
|
def add_user_to_tenant(self, tenant_id: str, user_id: str) -> tuple[bool, int]:
|
|
"""Add a user to a tenant"""
|
|
url = f"{self.config.host}/users/{user_id}/tenant"
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": f"Bearer 1234567890",
|
|
}
|
|
data = {
|
|
"tenant": tenant_id,
|
|
}
|
|
response = requests.put(url, headers=headers, json=data)
|
|
success = response.status_code == 200
|
|
return success, response.status_code |