Changed FS structure, add initial hsman directory
This commit is contained in:
parent
e90cac77db
commit
089de6685e
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os
|
||||||
from typing import Optional, Union
|
from typing import Union
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@ class APISettings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_prefix='HS_')
|
model_config = SettingsConfigDict(env_prefix='HS_')
|
||||||
server: str = "http://localhost:8080"
|
server: str = "http://localhost:8080"
|
||||||
api_path: str = "/api/v1"
|
api_path: str = "/api/v1"
|
||||||
|
api_token: Union[str, None] = None
|
||||||
ssl_verify: Union[bool, str] = True
|
ssl_verify: Union[bool, str] = True
|
||||||
api_token: Union[None, str] = None
|
|
||||||
|
|
||||||
def refresh_api_token(self):
|
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):
|
class HTTPException(Exception):
|
|
@ -28,11 +28,8 @@ class HSAPICall:
|
||||||
|
|
||||||
objectPath: str = ""
|
objectPath: str = ""
|
||||||
|
|
||||||
def __init__(self, api_settings_override: Optional[APISettings] = None) -> None:
|
def __init__(self, settings: Optional[APISettings] = None) -> None:
|
||||||
if api_settings_override:
|
self.api_settings = settings if settings else APISettings()
|
||||||
self.api_settings = api_settings_override
|
|
||||||
else:
|
|
||||||
self.api_settings = APISettings()
|
|
||||||
self.base_path = f"{
|
self.base_path = f"{
|
||||||
self.api_settings.server}{self.api_settings.api_path}/{self.objectPath}"
|
self.api_settings.server}{self.api_settings.api_path}/{self.objectPath}"
|
||||||
|
|
||||||
|
@ -61,7 +58,7 @@ class HSAPICall:
|
||||||
json=json_
|
json=json_
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
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}")
|
response.text}")
|
||||||
|
|
||||||
return response
|
return response
|
|
@ -1,7 +1,7 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "headscale-api-client"
|
name = "hsapi"
|
||||||
version = "0.1.0"
|
version = "0.9.0"
|
||||||
description = "Headscale API module"
|
description = "Headscale API client"
|
||||||
authors = ["Andrea Mistrali <andrea@mistrali.pw>"]
|
authors = ["Andrea Mistrali <andrea@mistrali.pw>"]
|
||||||
license = "BSD"
|
license = "BSD"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
Loading…
Reference in New Issue