Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/tailscale/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""

Expand All @@ -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.

"""
8 changes: 6 additions & 2 deletions src/tailscale/tailscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-------
Expand Down Expand Up @@ -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:
Expand Down
Loading