libtea 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libtea-0.2.0/.github/dependabot.yml +18 -0
- libtea-0.2.0/.github/workflows/ci.yaml +22 -0
- libtea-0.2.0/.github/workflows/codeql.yaml +30 -0
- libtea-0.2.0/.github/workflows/pypi.yaml +65 -0
- {libtea-0.1.0 → libtea-0.2.0}/.gitignore +1 -6
- libtea-0.2.0/.pre-commit-config.yaml +15 -0
- libtea-0.2.0/CLAUDE.md +93 -0
- libtea-0.2.0/PKG-INFO +447 -0
- libtea-0.2.0/README.md +415 -0
- libtea-0.2.0/docs/FUTURE.md +23 -0
- libtea-0.2.0/docs/cli.md +347 -0
- libtea-0.2.0/docs/plans/2025-02-25-tea-client-design.md +218 -0
- libtea-0.2.0/docs/plans/2026-02-25-v0.2.0-design.md +745 -0
- libtea-0.2.0/docs/plans/2026-02-26-v0.3.0-design.md +710 -0
- {libtea-0.1.0 → libtea-0.2.0}/pyproject.toml +38 -8
- libtea-0.2.0/src/libtea/__init__.py +121 -0
- libtea-0.2.0/src/libtea/_cli_entry.py +17 -0
- libtea-0.2.0/src/libtea/_cli_fmt.py +542 -0
- libtea-0.2.0/src/libtea/_hashing.py +63 -0
- libtea-0.2.0/src/libtea/_http.py +378 -0
- libtea-0.2.0/src/libtea/_security.py +91 -0
- libtea-0.2.0/src/libtea/_validation.py +82 -0
- libtea-0.2.0/src/libtea/cli.py +623 -0
- libtea-0.2.0/src/libtea/client.py +551 -0
- libtea-0.2.0/src/libtea/discovery.py +264 -0
- libtea-0.2.0/src/libtea/exceptions.py +97 -0
- libtea-0.2.0/src/libtea/models.py +533 -0
- libtea-0.2.0/tests/cli/__init__.py +0 -0
- libtea-0.2.0/tests/cli/test_cli.py +1274 -0
- libtea-0.2.0/tests/cli/test_cli_fmt.py +953 -0
- libtea-0.2.0/tests/client/__init__.py +0 -0
- libtea-0.2.0/tests/client/test_client.py +762 -0
- libtea-0.2.0/tests/client/test_discovery.py +527 -0
- libtea-0.2.0/tests/client/test_download.py +120 -0
- libtea-0.2.0/tests/client/test_http.py +524 -0
- libtea-0.2.0/tests/conftest.py +25 -0
- libtea-0.2.0/tests/integration/__init__.py +0 -0
- libtea-0.2.0/tests/integration/test_integration.py +124 -0
- libtea-0.2.0/tests/unit/__init__.py +0 -0
- libtea-0.2.0/tests/unit/test_cli_entry.py +21 -0
- libtea-0.2.0/tests/unit/test_exceptions.py +75 -0
- libtea-0.2.0/tests/unit/test_hashing.py +60 -0
- libtea-0.2.0/tests/unit/test_models.py +581 -0
- libtea-0.2.0/tests/unit/test_security.py +198 -0
- libtea-0.2.0/tests/unit/test_validation.py +122 -0
- libtea-0.2.0/tests/unit/test_version.py +23 -0
- libtea-0.2.0/uv.lock +920 -0
- libtea-0.1.0/.pre-commit-config.yaml +0 -7
- libtea-0.1.0/CLAUDE.md +0 -30
- libtea-0.1.0/PKG-INFO +0 -62
- libtea-0.1.0/README.md +0 -36
- libtea-0.1.0/libtea/__init__.py +0 -5
- libtea-0.1.0/tests/test_version.py +0 -5
- {libtea-0.1.0 → libtea-0.2.0}/LICENSE +0 -0
- {libtea-0.1.0 → libtea-0.2.0/src}/libtea/py.typed +0 -0
- {libtea-0.1.0 → libtea-0.2.0}/tests/__init__.py +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "github-actions"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
groups:
|
|
8
|
+
github-actions:
|
|
9
|
+
patterns:
|
|
10
|
+
- "*"
|
|
11
|
+
- package-ecosystem: "uv"
|
|
12
|
+
directory: "/"
|
|
13
|
+
schedule:
|
|
14
|
+
interval: "weekly"
|
|
15
|
+
groups:
|
|
16
|
+
uv:
|
|
17
|
+
patterns:
|
|
18
|
+
- "*"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
16
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
17
|
+
- run: uv python install ${{ matrix.python-version }}
|
|
18
|
+
- run: uv sync --extra cli
|
|
19
|
+
- run: uv run ruff check .
|
|
20
|
+
- run: uv run ruff format --check .
|
|
21
|
+
- run: uv run pytest --cov-fail-under=90
|
|
22
|
+
- run: uv build
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: CodeQL
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
schedule:
|
|
8
|
+
- cron: "0 6 * * 1"
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
analyze:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
security-events: write
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
language: [python]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
20
|
+
|
|
21
|
+
- name: Initialize CodeQL
|
|
22
|
+
uses: github/codeql-action/init@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
23
|
+
with:
|
|
24
|
+
languages: ${{ matrix.language }}
|
|
25
|
+
|
|
26
|
+
- name: Autobuild
|
|
27
|
+
uses: github/codeql-action/autobuild@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
28
|
+
|
|
29
|
+
- name: Perform CodeQL Analysis
|
|
30
|
+
uses: github/codeql-action/analyze@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: Build and Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-publish-testpypi:
|
|
12
|
+
if: github.event_name == 'push'
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
environment:
|
|
15
|
+
name: testpypi
|
|
16
|
+
url: https://test.pypi.org/p/libtea
|
|
17
|
+
permissions:
|
|
18
|
+
id-token: write
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
21
|
+
|
|
22
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
23
|
+
|
|
24
|
+
- name: Determine version
|
|
25
|
+
id: version
|
|
26
|
+
run: |
|
|
27
|
+
BASE_VERSION=$(grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
|
28
|
+
DEV_VERSION="${BASE_VERSION}.dev${GITHUB_RUN_NUMBER}"
|
|
29
|
+
echo "version=${DEV_VERSION}" >> "$GITHUB_OUTPUT"
|
|
30
|
+
|
|
31
|
+
- name: Set dev version
|
|
32
|
+
run: |
|
|
33
|
+
sed -i "s/^version = .*/version = \"${{ steps.version.outputs.version }}\"/" pyproject.toml
|
|
34
|
+
|
|
35
|
+
- name: Build package
|
|
36
|
+
run: uv build
|
|
37
|
+
|
|
38
|
+
- name: Publish to TestPyPI
|
|
39
|
+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
|
40
|
+
with:
|
|
41
|
+
repository-url: https://test.pypi.org/legacy/
|
|
42
|
+
|
|
43
|
+
build-and-publish-pypi:
|
|
44
|
+
if: github.event_name == 'release'
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
environment:
|
|
47
|
+
name: pypi
|
|
48
|
+
url: https://pypi.org/p/libtea
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
53
|
+
|
|
54
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
55
|
+
|
|
56
|
+
- name: Run tests
|
|
57
|
+
run: |
|
|
58
|
+
uv sync --extra cli
|
|
59
|
+
uv run pytest --cov-fail-under=90
|
|
60
|
+
|
|
61
|
+
- name: Build package
|
|
62
|
+
run: uv build
|
|
63
|
+
|
|
64
|
+
- name: Publish to PyPI
|
|
65
|
+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
|
@@ -46,6 +46,7 @@ htmlcov/
|
|
|
46
46
|
nosetests.xml
|
|
47
47
|
coverage.xml
|
|
48
48
|
*.cover
|
|
49
|
+
*,cover
|
|
49
50
|
*.py.cover
|
|
50
51
|
.hypothesis/
|
|
51
52
|
.pytest_cache/
|
|
@@ -94,12 +95,6 @@ ipython_config.py
|
|
|
94
95
|
# install all needed dependencies.
|
|
95
96
|
#Pipfile.lock
|
|
96
97
|
|
|
97
|
-
# UV
|
|
98
|
-
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
-
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
-
# commonly ignored for libraries.
|
|
101
|
-
uv.lock
|
|
102
|
-
|
|
103
98
|
# poetry
|
|
104
99
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
100
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.15.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
- repo: local
|
|
9
|
+
hooks:
|
|
10
|
+
- id: mypy
|
|
11
|
+
name: mypy
|
|
12
|
+
entry: uv run mypy
|
|
13
|
+
language: system
|
|
14
|
+
types: [python]
|
|
15
|
+
pass_filenames: false
|
libtea-0.2.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
**py-libtea** is a hand-crafted Python client library for the Transparency Exchange API (TEA) v0.3.0-beta.2. Consumer-focused (read-only); publisher API is not yet supported (blocked on TEA spec). Licensed Apache 2.0, maintained under sbomify.
|
|
8
|
+
|
|
9
|
+
## Build & Dev Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv sync # Install all dependencies
|
|
13
|
+
uv run pytest # Run full test suite with coverage
|
|
14
|
+
uv run pytest tests/client/test_client.py -v # Run a single test file
|
|
15
|
+
uv run pytest tests/unit/test_security.py::TestSsrfProtection::test_rejects_cgnat_ip -v # Single test
|
|
16
|
+
uv run mypy # Type check (strict mode)
|
|
17
|
+
uv run ruff check . # Lint
|
|
18
|
+
uv run ruff format --check . # Format check
|
|
19
|
+
uv run ruff format . # Auto-format
|
|
20
|
+
uv build # Build wheel and sdist
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Code Conventions
|
|
24
|
+
|
|
25
|
+
- **Layout**: src/ layout (`src/libtea/`), hatchling build backend
|
|
26
|
+
- **Python**: >=3.11 (enables `StrEnum`, `X | Y` union syntax)
|
|
27
|
+
- **Line length**: 120, ruff rules: E, F, I
|
|
28
|
+
- **Models**: Pydantic v2 with `frozen=True`, `extra="ignore"`, `alias_generator=to_camel`
|
|
29
|
+
- **HTTP mocking**: `responses` library (not `unittest.mock` for HTTP)
|
|
30
|
+
- **Coverage**: Branch coverage enabled, target ~97%
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
The library has a layered design with strict separation of concerns:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
__init__.py Public API re-exports (all models, exceptions, client, discovery)
|
|
38
|
+
client.py TeaClient — high-level consumer API, checksum verification
|
|
39
|
+
↓ uses
|
|
40
|
+
_validation.py Input validation helpers (path segments, page size/offset, Pydantic wrappers)
|
|
41
|
+
_http.py TeaHttpClient — low-level requests wrapper, auth, streaming downloads
|
|
42
|
+
Also: probe_endpoint() for endpoint failover
|
|
43
|
+
_security.py SSRF protection (_validate_download_url, DNS rebinding checks, internal IP detection)
|
|
44
|
+
_hashing.py Checksum hash builders (SHA-*, BLAKE2b-*, MD5)
|
|
45
|
+
discovery.py TEI parsing, .well-known/tea fetching, SemVer endpoint selection, redirect SSRF protection
|
|
46
|
+
models.py Pydantic v2 models for all TEA domain objects (frozen, camelCase aliases)
|
|
47
|
+
exceptions.py Exception hierarchy (all inherit from TeaError)
|
|
48
|
+
cli.py click CLI (optional dependency, thin wrapper over TeaClient)
|
|
49
|
+
_cli_fmt.py Rich output formatters for all CLI commands (tables, panels, escape helpers)
|
|
50
|
+
_cli_entry.py Entry point wrapper that handles missing CLI extras gracefully
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Key design patterns:**
|
|
54
|
+
|
|
55
|
+
- `TeaClient` delegates all HTTP to `TeaHttpClient` — never calls `requests` directly
|
|
56
|
+
- Bearer tokens are NOT sent to artifact download URLs (separate unauthenticated session prevents token leakage to CDNs)
|
|
57
|
+
- Downloads follow redirects manually with SSRF validation at each hop
|
|
58
|
+
- Discovery redirects are validated against internal networks (SSRF protection via `_security._validate_download_url`)
|
|
59
|
+
- `_validation._validate()` wraps Pydantic `ValidationError` into `TeaValidationError` so all client errors are `TeaError` subclasses
|
|
60
|
+
- Endpoint failover: `from_well_known()` probes candidates in priority order, skipping unreachable ones
|
|
61
|
+
- `probe_endpoint()` lives in `_http.py` (not `client.py`) to maintain the HTTP layer boundary
|
|
62
|
+
- `_raise_for_status()` uses bounded reads (201 bytes) for error body snippets to avoid memory issues on streaming responses
|
|
63
|
+
- CLI formatters in `_cli_fmt.py` escape all server-controlled strings with `rich.markup.escape()` to prevent Rich markup injection
|
|
64
|
+
|
|
65
|
+
**Auth**: Bearer token and basic auth are supported. Token and basic_auth are mutually exclusive. HTTP (non-TLS) with credentials is rejected.
|
|
66
|
+
|
|
67
|
+
## Critical Implementation Rules
|
|
68
|
+
|
|
69
|
+
- **NEVER** use `from __future__ import annotations` in files containing Pydantic models — it breaks Pydantic v2 runtime type evaluation
|
|
70
|
+
- `pydantic >= 2.1.0` is the floor (for `pydantic.alias_generators.to_camel`)
|
|
71
|
+
- `requests` auto-encodes query params — do NOT pre-encode with `urllib.parse.quote()`
|
|
72
|
+
- When mocking with `responses` library, use `requests.ConnectionError` as the body exception (not Python's built-in `ConnectionError` — they are different classes)
|
|
73
|
+
- `ChecksumAlgorithm` values may arrive as `SHA_256` (underscore) or `SHA-256` (hyphen) from servers — the `@field_validator` in `Checksum` normalizes both
|
|
74
|
+
- BLAKE3 is in the enum for spec completeness but NOT supported at runtime (not in stdlib `hashlib`) — raises `TeaChecksumError`
|
|
75
|
+
- `Identifier.id_type` is typed as `str` (not `IdentifierType` enum) so unknown types from future spec versions pass through
|
|
76
|
+
- CGNAT range (100.64.0.0/10, RFC 6598) is checked separately in SSRF protection because `ipaddress.is_private` misses it on Python 3.11+
|
|
77
|
+
|
|
78
|
+
## TEA Spec Reference
|
|
79
|
+
|
|
80
|
+
The TEA spec repo should be cloned to `/tmp/transparency-exchange-api/` for cross-referencing:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://github.com/CycloneDX/transparency-exchange-api /tmp/transparency-exchange-api
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Key spec files: `spec/openapi.yaml`, `discovery/readme.md`, `auth/readme.md`
|
|
87
|
+
|
|
88
|
+
## Design Docs
|
|
89
|
+
|
|
90
|
+
- `docs/plans/2025-02-25-tea-client-design.md` — v0.1.0 original design
|
|
91
|
+
- `docs/plans/2026-02-25-v0.2.0-design.md` — v0.2.0 (CLE, SemVer, failover, CLI)
|
|
92
|
+
- `docs/plans/2026-02-26-v0.3.0-design.md` — v0.3.0 (httpx migration, async client)
|
|
93
|
+
- `docs/FUTURE.md` — Items blocked on external factors (Publisher API)
|