diff --git a/README.md b/README.md index 6b3464bd..90abda70 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,8 @@ Tailscale( To keep the access token of an OAuth client across restarts, pass a `token_storage`: an implementation of `TokenStorage`, with a `get_token()` -and a `set_token()` method. +and a `set_token()` method. The expiry it stores and returns must be a +timezone-aware `datetime`. The `tailnet` defaults to `"-"`, the tailnet of the credentials. Pass the tailnet ID to use another tailnet the credentials have access to. @@ -223,6 +224,8 @@ returns them as a dictionary keyed by device ID. Only the identifiers (`device_id`, `node_id`, `hostname`, and `name`) are always set. The API leaves out many fields for devices shared in from another tailnet, so the other fields are `None` when the API does not return them. +The exceptions are the lists, like `addresses` and `tags`, which are empty +then, and `is_external`, which is `False`. ```python async with Tailscale(api_key="tskey-api-...") as tailscale: @@ -293,7 +296,8 @@ paths, and split DNS have their own methods too. The policy file is kept as HuJSON, so its comments and formatting survive a round trip. Pass along its ETag when setting it, so it is not set when someone -else changed it in the meantime. +else changed it in the meantime. Without an ETag, which is the case when the +API returns none, it is set whatever changed. ```python async with Tailscale(api_key="tskey-api-...") as tailscale: @@ -335,7 +339,7 @@ apps, the contacts of the tailnet, and the tailnets of an organization. ### Error handling -All errors are a `TailscaleError`: +Errors of requests to the API are a `TailscaleError`: - `TailscaleConnectionError`: the API could not be reached, or did not answer in time. @@ -347,6 +351,9 @@ All errors are a `TailscaleError`: exist. - `TailscaleResponseError`: the API responded with another error. +A response the client cannot make sense of raises the error of the JSON or +model parsing instead. + The response errors have the HTTP `status`, and the `reason` the API gave: ```python @@ -371,7 +378,8 @@ Tailscale( ``` You may also pass your own `aiohttp.ClientSession` via `session=...` to -share a connection pool across multiple clients. +share a connection pool across multiple clients. A session you pass stays +yours: the client does not close it. ## Changelog & Releases diff --git a/src/tailscale/storage.py b/src/tailscale/storage.py index 5135395c..4d4b5075 100644 --- a/src/tailscale/storage.py +++ b/src/tailscale/storage.py @@ -13,7 +13,8 @@ async def get_token(self) -> tuple[str, datetime] | None: Returns ------- - The stored token and expiration time, or None if no token is stored. + The stored token and its timezone-aware expiration time, or None + if no token is stored. """ @@ -24,6 +25,6 @@ async def set_token(self, access_token: str, expires_at: datetime) -> None: Args: ---- access_token: The access token to store. - expires_at: The expiration time of the access token. + expires_at: The timezone-aware expiration time of the access token. """ diff --git a/src/tailscale/tailscale.py b/src/tailscale/tailscale.py index 4761577a..ebd6c573 100644 --- a/src/tailscale/tailscale.py +++ b/src/tailscale/tailscale.py @@ -830,7 +830,8 @@ async def set_policy_file( policy: The new policy file, as HuJSON or JSON. etag: The ETag of the policy file this one is based on. When the policy file has changed since, the API refuses the update - and a TailscaleError is raised. + and a TailscaleError is raised. Without it, the policy file + is set whatever changed. Returns: ------- @@ -2260,7 +2261,10 @@ async def delete_posture_integration(self, integration_id: str) -> None: ) async def close(self) -> None: - """Close open client session and cancel background tasks.""" + """Close the client session it opened, and cancel background tasks. + + A session passed to the client is left open, for its owner to close. + """ if self.session and self._close_session: await self.session.close() if self._get_oauth_token_task: