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
13 changes: 9 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ The library has a layered design with strict separation of concerns:

```
__init__.py Public API re-exports (all models, exceptions, client, discovery)
client.py TeaClient — high-level consumer API, spec version resolution, checksum verification
client.py TeaClient — high-level consumer API, spec version resolution, checksum verification,
from_well_known / from_tei endpoint failover (_connect)
protocols.py TeaClientProtocol — method-only Protocol of TeaClient's public API, for test doubles
↓ uses
_validation.py Input validation helpers (path segments, page size, Pydantic wrappers)
_http.py TeaHttpClient — low-level requests wrapper, auth, streaming downloads
Also: probe_endpoint() for endpoint failover
_http.py TeaHttpClient — low-level requests wrapper, auth (incl. the /token API key exchange),
streaming downloads. Also: probe_endpoint() for endpoint failover
_constants.py Shared constants (package version for the User-Agent)
_security.py SSRF protection (_validate_download_url, DNS rebinding checks, internal IP detection)
_hashing.py Checksum hash builders (SHA-*, BLAKE2b-*, MD5)
discovery.py TEI parsing, .well-known/tea fetching, SemVer endpoint selection, redirect SSRF protection
Expand Down Expand Up @@ -100,5 +103,7 @@ Key spec files: `spec/openapi.yaml`, `discovery/readme.md`, `auth/readme.md`. Th

## Design Docs

- `docs/cli.md` — `tea-cli` reference (keep in step with the click options in `cli.py`)
- `docs/conformance.md` — Conformance suite usage and check reference
- `docs/FUTURE.md` — Items blocked on external factors (Publisher API)
- `docs/FUTURE.md` — Deferred items: Publisher API (blocked on the spec) and optional TEA 1.0.0 consumer features
- `.claude/skills/cut-release/SKILL.md` — Release process (CalVer `YY.MM.MICRO`); maintainers cut releases
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ with TeaClient.from_well_known("trust.sbomify.com") as client:
from libtea import TeaClient

# Bearer token
client = TeaClient.from_well_known("trust.sbomify.com", token="your-token")
client = TeaClient.from_well_known("tea.example.com", token="your-token")

# API key (TEA 1.x): exchanged at POST /token, and the access token is sent instead
client = TeaClient.from_well_known("trust.sbomify.com", basic_auth=("key-id", "key-secret"))
client = TeaClient.from_well_known("tea.example.com", basic_auth=("key-id", "key-secret"))

# Both work with from_tei too
client, results = TeaClient.from_tei("tei://example.com/uuid/d4d9f54a-abcf-11ee-ac79-1a52914d44b1", token="your-token")
```

On a TEA 1.x server `basic_auth` is an API key. The client sends it only to `POST /token` (the `client_credentials` grant over HTTP Basic, as the TEA auth baseline requires) and presents the access token it gets as the bearer token. A token rejected with an `invalid_token` challenge is replaced, and the request retried, once. A TEA 0.4.0 server receives `basic_auth` as HTTP Basic auth on every request.
Expand Down Expand Up @@ -407,10 +410,13 @@ These flags can be placed before or after the subcommand name. They appear under
--verbose, -v Show verbose output (libtea debug logs)
--debug, -d Show debug output (full HTTP firehose including urllib3)
--allow-private-ips Allow artifact downloads from private/internal IPs
--no-input Never prompt for input (for scripts and CI)
--no-color Disable colored output (also respects NO_COLOR)
--output, -o FILE Write formatted output to a file instead of stdout
--version Show version
```

All commands also accept connection options: `--base-url`, `--domain`, `--token`, `--auth`, `--use-http`, `--port`.
All commands also accept connection options: `--base-url`, `--domain`, `--token`, `--auth`, `--timeout`, `--use-http`, `--port`. A TEI given without `--base-url` (`discover`, `inspect`, `download`) is resolved with `TeaClient.from_tei`, failing over between the domain's `.well-known/tea` endpoints.

### Discover

Expand Down Expand Up @@ -533,7 +539,7 @@ tea-cli conformance --base-url https://tea.example.com/v1 --json
|----------|-------------|
| `TEA_BASE_URL` | TEA server base URL (alternative to `--base-url`) |
| `TEA_TOKEN` | Bearer token (alternative to `--token`) |
| `TEA_AUTH` | Basic auth as `USER:PASSWORD` (alternative to `--auth`) |
| `TEA_AUTH` | `USER:PASSWORD` (alternative to `--auth`): an API key exchanged at `/token` on TEA 1.x, HTTP basic auth on 0.4.0 |

### Shell completion

Expand Down Expand Up @@ -643,15 +649,15 @@ Exception hierarchy:
| `TeaValidationError` | Malformed server response |
| `TeaInsecureTransportWarning` | Warning emitted when using plaintext HTTP |

Using a bearer token over plaintext HTTP raises `ValueError` immediately — HTTPS is required for authenticated requests.
Using a bearer token or `basic_auth` over plaintext HTTP raises `ValueError` immediately — HTTPS is required for authenticated requests.

## Upgrading

libtea now targets TEA 1.0.0 and still talks to 0.4.0 servers. These Python API changes can break code written against libtea 0.5.1.

**Spec versions**

- A base URL without a `/v<semver>` suffix (and no `spec_version=`) is now TEA 1.0.0, not 0.4.0. `TEA_SPEC_VERSION` is `"1.0.0"`. To keep talking to a 0.4.0 server, pass `spec_version="0.4.0"` or end the base URL in `/v0.4.0`.
- A base URL without a `/v<semver>` suffix (and no `spec_version=`) is now TEA 1.0.0, not 0.4.0. `TEA_SPEC_VERSION` is `"1.0.0"`. To keep talking to a 0.4.0 server, pass `spec_version="0.4.0"` or end the base URL in `/v0.4.0`. `tea-cli --base-url`, `run_conformance` and the pytest plugin have no version option, so give them a base URL ending in `/v0.4.0`.
- `TeaClient.from_well_known(version=None)` now negotiates: it prefers 1.0.0, falls back to 0.4.0, and fails over across both. It used to default to `"0.4.0"`. Pass `version="0.4.0"` to pin the old behaviour. Endpoints of another compatible version (for example `0.3.0`) are tried, with a warning, only after every endpoint advertising 1.0.0 or 0.4.0 exactly has failed; a prerelease such as `1.0.0-rc.1` does not count as 1.0.0. With the default `scheme="https"`, an `http://` endpoint listed in `.well-known` is rejected and the next one is tried. The API path uses the version spelling exactly as the server advertises it (for example `/v1.0.0+build.5`).
- A base URL ending in `/v<semver>` with a major version other than 0 or 1 (for example `/v2.0.0`) now raises `ValueError`.
- On a 1.x server `basic_auth` is now an API key exchanged at `POST /token`; it is no longer sent to resource endpoints. A server without a `/token` endpoint answers that exchange with an error, so code that used `basic_auth` against a 0.4.0 server behind an unversioned base URL needs `spec_version="0.4.0"`.
Expand All @@ -663,6 +669,7 @@ libtea now targets TEA 1.0.0 and still talks to 0.4.0 servers. These Python API
- TEIs are now `tei://<domain>/<type>/<identifier>`. `parse_tei` and the CLI still accept the legacy `urn:tei:<type>:<domain>:<identifier>` form, and `TeaClient.discover` sends whatever TEI you give it verbatim; use the legacy form with 0.4.0 servers. When the CLI discovers the server from a legacy-form TEI, it connects to a 0.4.0 endpoint, since only 0.4.0 defines that form.
- `discover(tei=None, *, purl=None)` takes exactly one of the two, otherwise `TeaValidationError`. PURL lookup needs a 1.x server. On a 1.x server an empty discovery array also raises `TeaValidationError`; an unknown TEI is a 404.
- `TeaClient.from_tei(tei)` is new and returns `(client, results)`. It fails over between `.well-known/tea` endpoints at the `/discovery` step, as TEA discovery requires, which `from_well_known` followed by `discover` does not. The CLI's `discover`, `inspect` and TEI `download` use it when no `--base-url` is given, so they no longer send a HEAD probe first.
- Endpoint URLs in `.well-known/tea` must match the TEA schema: `http` or `https`, with no userinfo, query, fragment or trailing slash. A document that lists any other URL is rejected with `TeaDiscoveryError` (libtea 0.5.1 accepted it and stripped a trailing slash).

**Pagination**

Expand Down Expand Up @@ -725,7 +732,8 @@ Optional:

- Publisher API (blocked on the TEA spec)
- Async client
- Some TEA 1.0.0 consumer features: `ETag` revalidation, signature downloads, `sortField`/`sortOrder` and following `servers[].rootUrl`. See [docs/FUTURE.md](docs/FUTURE.md)
- Some TEA 1.0.0 consumer features: `ETag` revalidation, signature downloads, `sortField`/`sortOrder`, following `servers[].rootUrl` and renewing an access token before it expires. See [docs/FUTURE.md](docs/FUTURE.md)
- A spec-version option for `tea-cli` and the conformance suite (use a base URL ending in `/v0.4.0` instead)

## Development

Expand All @@ -741,7 +749,7 @@ uv build # Build wheel and sdist

## Versioning

Versions are CalVer, `YY.M.PATCH`, matching the other sbomify projects: the two-digit year and month of the release, then a counter that restarts at 0 each month. Releases are tagged `vYY.M.PATCH` (for example `v26.11.0`). 26.11.0 follows 0.5.1, so version ordering still holds for pip and uv.
Versions are CalVer, `YY.MM.MICRO`, like every sbomify project ([ADR-0002](https://github.com/sbomify/adr/blob/master/0002-adopt-calver-versioning.md)): the two-digit year, the month without zero padding, then a counter for releases within that month (`26.7.0` is the first release of July 2026). Releases are tagged `v<version>`. The first CalVer release follows 0.5.1, so version ordering still holds for pip and uv; a pin such as `libtea~=0.5` will not pick it up.

## License

Expand Down
25 changes: 19 additions & 6 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pip install libtea[cli]
| `--verbose`, `-v` | Show verbose output (libtea debug logs on stderr, suppresses urllib3/requests noise) |
| `--debug`, `-d` | Show full debug output (all HTTP requests, urllib3, timing) on stderr |
| `--allow-private-ips` | Allow artifact downloads from private/internal IPs (relaxes SSRF checks for downloads only). Scheme validation and cloud metadata endpoint blocking are always enforced. |
| `--no-input` | Never prompt for input, for scripts and CI. A TEI `download` without `DEST_DIR` then saves into the current directory without asking. |
| `--no-color` | Disable colored output. The `NO_COLOR` environment variable is also respected. |
| `--output`, `-o` *FILE* | Write the formatted output to *FILE* instead of stdout. Not used by `download`, which writes to its destination. |
| `--version` | Show version and exit |
| `--help` | Show help message and exit |

Expand Down Expand Up @@ -338,12 +341,16 @@ tea-cli conformance --base-url URL [OPTIONS]
| `--component-release-uuid` *UUID* | Explicit component release UUID. |
| `--artifact-uuid` *UUID* | Explicit artifact UUID. |
| `--token` *TOKEN* | Bearer token. Can also be set via `TEA_TOKEN`. |
| `--auth` *USER:PASSWORD* | Basic auth credentials. Can also be set via `TEA_AUTH`. |
| `--auth` *USER:PASSWORD* | Basic auth credentials: an API key exchanged at `/token` on TEA 1.x. Can also be set via `TEA_AUTH`. |
| `--timeout` *SECONDS* | Request timeout in seconds (default: 30). |
| `--allow-private-ips` | Allow private IPs in downloads. |
| `--json` | Output results as JSON. |
| `-v`, `--verbose` | Show failure details and increase logging verbosity. |
| `-d`, `--debug` | Show debug output. |
| `--no-color` | Disable colored output. |
| `--output`, `-o` *FILE* | Write the output to *FILE* instead of stdout. |

The spec version under test comes from `--base-url`: a `/v<semver>` suffix selects it, otherwise TEA 1.0.0 is assumed. To test a TEA 0.4.0 server, end the base URL in `/v0.4.0`.

The command exits with code 0 if all checks pass, and code 1 if any check fails.

Expand All @@ -357,20 +364,25 @@ See the [conformance docs](conformance.md) for the full check reference and pyte
|----------|-------------|
| `TEA_BASE_URL` | TEA server base URL. Equivalent to `--base-url`. |
| `TEA_TOKEN` | Bearer token. Equivalent to `--token`. Preferred over the command-line flag to avoid exposing the token in shell history. |
| `TEA_AUTH` | Basic auth credentials as `USER:PASSWORD`. Equivalent to `--auth`. |
| `TEA_AUTH` | Basic auth credentials as `USER:PASSWORD`: an API key on TEA 1.x. Equivalent to `--auth`. |
| `NO_COLOR` | Disable colored output. Equivalent to `--no-color`. |

## Authentication

`tea-cli` supports three authentication methods, all mutually exclusive:
`tea-cli` supports two authentication methods, which are mutually exclusive:

**Bearer token** (most common): Pass via `--token` or `TEA_TOKEN`. Requires HTTPS. The token is never sent to artifact download URLs (CDNs) — only to the TEA API server.

**API key / HTTP basic auth:** Pass via `--auth USER:PASSWORD` or `TEA_AUTH`. Requires HTTPS. On a TEA 1.x server the pair is an API key (`KEY-ID:SECRET`): it is sent only to `POST /token`, and the access token it yields is sent to every other endpoint. A TEA 0.4.0 server receives it as HTTP basic auth on every request.

**Discovery failover:** A TEI given without `--base-url` (`discover`, `inspect`, `download`) is resolved at each `.well-known/tea` endpoint in turn until one answers `/discovery`. An unreachable endpoint, a 5xx, a 404 that is not a TEA error or an invalid body moves on to the next one. A TEA error 404 (for example `OBJECT_UNKNOWN`), 401 or 403 stops there.

Using credentials over plaintext HTTP raises an error. Use `--use-http` only for unauthenticated local development.

## Discovery Failover

A TEI given without `--base-url` (`discover`, `inspect`, `download`) is resolved at each `.well-known/tea` endpoint of its domain (or of `--domain`) in turn until one answers `/discovery`. TEA 1.0.0 endpoints are tried before 0.4.0 ones; a legacy URN TEI only goes to 0.4.0 endpoints. An unreachable endpoint, a 5xx, a 404 that is not a TEA error or an invalid body moves on to the next one. A TEA error 404 (for example `OBJECT_UNKNOWN`), 401 or 403 stops there.

With `--base-url`, the TEI is sent to that server only.

## Examples

Discover sbomify product releases:
Expand Down Expand Up @@ -456,7 +468,8 @@ tea-cli get-product <product-uuid>
| Code | Meaning |
|------|---------|
| `0` | Success |
| `1` | Error (network failure, authentication error, not found, invalid input, etc.). The error message is printed to stderr. |
| `1` | Error (network failure, authentication error, not found, invalid input, etc.). The error message is printed to stderr. `conformance` also exits with 1 when any check fails. |
| `2` | Usage error (unknown option, missing argument). |

## See Also

Expand Down
6 changes: 3 additions & 3 deletions docs/conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ for check in result.checks:
| `component_release_uuid` | `str \| None` | Explicit component release UUID |
| `artifact_uuid` | `str \| None` | Explicit artifact UUID |
| `token` | `str \| None` | Bearer token |
| `basic_auth` | `tuple[str, str] \| None` | `(user, password)` tuple |
| `basic_auth` | `tuple[str, str] \| None` | `(user, password)` tuple; on TEA 1.x an API key, exchanged at `POST /token` for a bearer token |
| `timeout` | `float` | Request timeout in seconds (default: 30) |
| `allow_private_ips` | `bool` | Allow private IPs in downloads (default: False) |

The spec version under test comes from `base_url`: a `/v<semver>` suffix such as `/v0.4.0` selects that version, otherwise TEA 1.0.0 is assumed. Checks that differ between versions adapt to it (see the check reference).
The spec version under test comes from `base_url`: a `/v<semver>` suffix such as `/v0.4.0` selects that version, otherwise TEA 1.0.0 is assumed. There is no separate version option, so test a 0.4.0 server with a base URL ending in `/v0.4.0`. Checks that differ between versions adapt to it (see the check reference).

**Returns:** `ConformanceResult` with `.passed`, `.failed`, `.warned`, `.skipped` counts and `.checks` list.

Expand Down Expand Up @@ -206,7 +206,7 @@ Example GitHub Actions workflow:
```yaml
- name: TEA conformance
run: |
pip install libtea[conformance]
pip install "libtea[cli]"
tea-cli conformance \
--base-url "${{ secrets.TEA_BASE_URL }}" \
--token "${{ secrets.TEA_TOKEN }}" \
Expand Down
11 changes: 7 additions & 4 deletions src/libtea/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""libtea — Python client library for the Transparency Exchange API (TEA).

Quick start::
Quick start: resolve a TEI through its domain's ``.well-known/tea``, failing over between endpoints::

from libtea import TeaClient

with TeaClient("https://tea.example.com/v1", token="...") as client:
results = client.discover("tei://example.com/uuid/d4d9f54a-abcf-11ee-ac79-1a52914d44b1")
client, results = TeaClient.from_tei("tei://example.com/uuid/d4d9f54a-abcf-11ee-ac79-1a52914d44b1")
with client:
release = client.get_product_release(results[0].product_release_uuid)

Or auto-discover the server from a domain's ``.well-known/tea``::
Or connect to a known server (the ``/v<semver>`` suffix selects the spec version), or to a domain's
``.well-known/tea`` endpoint::

client = TeaClient("https://tea.example.com/tea/v1.0.0", token="...")
client = TeaClient.from_well_known("tea.example.com", token="...")
"""

Expand Down
9 changes: 6 additions & 3 deletions src/libtea/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def shared_options(fn): # type: ignore[no-untyped-def]
click.option("--timeout", type=click.FloatRange(min=0.1), default=30.0, help="Request timeout in seconds"),
click.option("--domain", default=None, help="Discover server from domain's .well-known/tea"),
click.option(
"--auth", envvar="TEA_AUTH", default=None, help="Basic auth as USER:PASSWORD (prefer TEA_AUTH env var)"
"--auth",
envvar="TEA_AUTH",
default=None,
help="Basic auth as USER:PASSWORD, an API key on TEA 1.x (prefer TEA_AUTH env var)",
),
click.option(
"--token",
Expand Down Expand Up @@ -412,7 +415,7 @@ def _error(message: str) -> NoReturn:
Environment variables:
TEA_BASE_URL TEA server base URL
TEA_TOKEN Bearer token for authentication
TEA_AUTH Basic auth as USER:PASSWORD
TEA_AUTH Basic auth as USER:PASSWORD (an API key on TEA 1.x)

\b
Exit codes:
Expand Down Expand Up @@ -1358,7 +1361,7 @@ def inspect(
@click.option("--artifact-uuid", default=None, help="Artifact UUID")
@click.option("--timeout", type=click.FloatRange(min=0.1), default=30.0, help="Request timeout in seconds")
@click.option("--token", envvar="TEA_TOKEN", default=None, help="Bearer token")
@click.option("--auth", envvar="TEA_AUTH", default=None, help="Basic auth as USER:PASSWORD")
@click.option("--auth", envvar="TEA_AUTH", default=None, help="Basic auth as USER:PASSWORD, an API key on TEA 1.x")
@click.option("--allow-private-ips", is_flag=True, help="Allow private IPs")
@click.option("--json", "output_json", is_flag=True, help="Output results as JSON")
@click.option("-v", "--verbose", is_flag=True, help="Show failure details and increase logging verbosity")
Expand Down
Loading