diff --git a/LICENSE b/hsapi/LICENSE similarity index 100% rename from LICENSE rename to hsapi/LICENSE diff --git a/README.md b/hsapi/README.md similarity index 100% rename from README.md rename to hsapi/README.md diff --git a/headscale.openapi.json b/hsapi/headscale.openapi.json similarity index 100% rename from headscale.openapi.json rename to hsapi/headscale.openapi.json diff --git a/headscale_api_client/__init__.py b/hsapi/hsapi/__init__.py similarity index 100% rename from headscale_api_client/__init__.py rename to hsapi/hsapi/__init__.py diff --git a/headscale_api_client/apikeys.py b/hsapi/hsapi/apikeys.py similarity index 100% rename from headscale_api_client/apikeys.py rename to hsapi/hsapi/apikeys.py diff --git a/headscale_api_client/config.py b/hsapi/hsapi/config.py similarity index 82% rename from headscale_api_client/config.py rename to hsapi/hsapi/config.py index a0af05a..14d9d57 100644 --- a/headscale_api_client/config.py +++ b/hsapi/hsapi/config.py @@ -1,5 +1,5 @@ import os -from typing import Optional, Union +from typing import Union from pydantic_settings import BaseSettings, SettingsConfigDict @@ -8,11 +8,11 @@ class APISettings(BaseSettings): model_config = SettingsConfigDict(env_prefix='HS_') server: str = "http://localhost:8080" api_path: str = "/api/v1" + api_token: Union[str, None] = None ssl_verify: Union[bool, str] = True - api_token: Union[None, str] = None def refresh_api_token(self): - self.api_token = os.environ.get('HS_API_TOKEN') + self.api_token = os.environ.get('HS_API_TOKEN', 'default') class HTTPException(Exception): diff --git a/headscale_api_client/model.py b/hsapi/hsapi/model.py similarity index 85% rename from headscale_api_client/model.py rename to hsapi/hsapi/model.py index b393f4c..724272c 100644 --- a/headscale_api_client/model.py +++ b/hsapi/hsapi/model.py @@ -28,11 +28,8 @@ class HSAPICall: objectPath: str = "" - def __init__(self, api_settings_override: Optional[APISettings] = None) -> None: - if api_settings_override: - self.api_settings = api_settings_override - else: - self.api_settings = APISettings() + def __init__(self, settings: Optional[APISettings] = None) -> None: + self.api_settings = settings if settings else APISettings() self.base_path = f"{ self.api_settings.server}{self.api_settings.api_path}/{self.objectPath}" @@ -61,7 +58,7 @@ class HSAPICall: json=json_ ) if response.status_code != 200: - raise HTTPException(response.status_code, f" failed with status code: { + raise HTTPException(response.status_code, f" failed. Error: { response.text}") return response diff --git a/headscale_api_client/nodes.py b/hsapi/hsapi/nodes.py similarity index 100% rename from headscale_api_client/nodes.py rename to hsapi/hsapi/nodes.py diff --git a/headscale_api_client/preauthkeys.py b/hsapi/hsapi/preauthkeys.py similarity index 100% rename from headscale_api_client/preauthkeys.py rename to hsapi/hsapi/preauthkeys.py diff --git a/headscale_api_client/routes.py b/hsapi/hsapi/routes.py similarity index 100% rename from headscale_api_client/routes.py rename to hsapi/hsapi/routes.py diff --git a/headscale_api_client/schemas.py b/hsapi/hsapi/schemas.py similarity index 100% rename from headscale_api_client/schemas.py rename to hsapi/hsapi/schemas.py diff --git a/headscale_api_client/users.py b/hsapi/hsapi/users.py similarity index 100% rename from headscale_api_client/users.py rename to hsapi/hsapi/users.py diff --git a/poetry.lock b/hsapi/poetry.lock similarity index 100% rename from poetry.lock rename to hsapi/poetry.lock diff --git a/pyproject.toml b/hsapi/pyproject.toml similarity index 78% rename from pyproject.toml rename to hsapi/pyproject.toml index b7320aa..eb3f0da 100644 --- a/pyproject.toml +++ b/hsapi/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] -name = "headscale-api-client" -version = "0.1.0" -description = "Headscale API module" +name = "hsapi" +version = "0.9.0" +description = "Headscale API client" authors = ["Andrea Mistrali "] license = "BSD" readme = "README.md"