mirror of
https://github.com/remnawave/python-sdk.git
synced 2026-05-13 12:16:42 +00:00
feat: Update SDK initialization to include caddy_token and enhance header preparation (Issue #6)
This commit is contained in:
parent
19d085d8da
commit
adc37ab126
4 changed files with 30 additions and 8 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -173,4 +173,6 @@ cython_debug/
|
|||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
test.py
|
||||
test.py
|
||||
.DS_Store
|
||||
docs/
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
[](https://pypi.python.org/pypi/remnawave-api)
|
||||
[](https://github.com/sm1ky/remnawave-api/actions/workflows/upload.yml)
|
||||
|
||||
A Python SDK client for interacting with the [Remnawave API](https://remna.st).
|
||||
This library simplifies working with the API by providing convenient controllers, Pydantic models for requests and responses, and fast serialization with `orjson`.
|
||||
A Python SDK client for interacting with the **[Remnawave API](https://remna.st)**.
|
||||
This library simplifies working with the API by providing convenient controllers, Pydantic models for requests and responses, and fast serialization with `orjson`.
|
||||
Library checked with Remnawave **[v1.5.7](https://github.com/remnawave/panel/releases/tag/1.5.7)**
|
||||
|
||||
## ✨ Key Features
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "remnawave-api"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
description = "A Python SDK for interacting with the Remnawave API."
|
||||
authors = [
|
||||
{name = "Artem",email = "sm1ky@forestsnet.com"}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,21 @@ class RemnawaveSDK:
|
|||
client: Optional[httpx.AsyncClient] = None,
|
||||
base_url: Optional[str] = None,
|
||||
token: Optional[str] = None,
|
||||
caddy_token: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
Remnawave SDK init
|
||||
|
||||
Args:
|
||||
client (Optional[httpx.AsyncClient]): - Default client.
|
||||
base_url (Optional[str]): - Base url of the Remnawave panel. Defaults to None.
|
||||
token (Optional[str]): - Token for authorization.
|
||||
caddy_token (Optional[str]): - Token for Caddy Auth (Headers). Defaults to None.
|
||||
"""
|
||||
self._client = client
|
||||
self._token = token
|
||||
self.base_url = base_url
|
||||
self.caddy_token = caddy_token
|
||||
|
||||
self._validate_params()
|
||||
|
||||
|
|
@ -76,13 +87,21 @@ class RemnawaveSDK:
|
|||
)
|
||||
|
||||
def _prepare_headers(self) -> dict:
|
||||
if not self._token.startswith("Bearer "):
|
||||
self._token = "Bearer " + self._token
|
||||
return {"Authorization": self._token}
|
||||
headers = {}
|
||||
if self._token:
|
||||
headers["Authorization"] = (
|
||||
self._token if self._token.startswith("Bearer ") else f"Bearer {self._token}"
|
||||
)
|
||||
|
||||
# X-Api-Key for Caddy (https://remna.st/security/caddy-with-custom-path#issuing-api-keys)
|
||||
if self.caddy_token is not None:
|
||||
headers["X-Api-Key"] = self.caddy_token
|
||||
|
||||
return headers
|
||||
|
||||
def _prepare_url(self) -> str:
|
||||
if self.base_url.endswith("/"):
|
||||
self.base_url[:-1]
|
||||
self.base_url = self.base_url[:-1]
|
||||
|
||||
if not self.base_url.endswith("/api"):
|
||||
self.base_url += "/api"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue