import requests from typing import Optional from datetime import datetime# import secnex.utils as utils from secnex.kit.config.config import Config from secnex.kit.models.application import Application class ApplicationClient: def __init__(self, config: Config) -> None: self.config = config def create(self, name: str, tenant_id: str, secret: str) -> tuple[Optional[str], int, bool]: """Create a new application""" url = f"{self.config.host}/apps" headers = { "Content-Type": "application/json", "Authorization": f"Bearer 1234567890", } response = requests.post(url, headers=headers, json={"name": name, "tenant": tenant_id, "secret": secret}) result = response.json() success = False app_id = None if "id" in result["body"]: success = True app_id = result["body"]["id"] return app_id, response.status_code, success def get_all(self) -> tuple[Optional[list[Application]], int, bool]: """Get all applications""" url = f"{self.config.host}/apps" headers = { "Content-Type": "application/json", "Authorization": f"Bearer 1234567890", } response = requests.get(url, headers=headers) result = response.json() success = False applications = [] if "applications" in result["body"]: success = True applications = [Application(**application) for application in result["body"]["applications"]] return applications, response.status_code, success def remove(self, id: str) -> tuple[bool, int]: """Remove an application""" url = f"{self.config.host}/apps/{id}" headers = { "Content-Type": "application/json", "Authorization": f"Bearer 1234567890", } response = requests.delete(url, headers=headers) success = response.status_code == 200 return success, response.status_code