Skip to content

Commit 8e82361

Browse files
authored
fix: testing improvements (#102)
* fix: pass python version input to uv testing step * fix: fail fast in check_entitlements.sh * fix: improve documentation * fix: consolidate 'load_tdf' function * fix: consolidate 'load_tdf' function
1 parent ef5849e commit 8e82361

File tree

8 files changed

+104
-121
lines changed

8 files changed

+104
-121
lines changed

.github/check_entitlements.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
24

35
# Derive additional environment variables
46
TOKEN_URL="${OIDC_OP_TOKEN_ENDPOINT}"
@@ -24,6 +26,11 @@ get_token() {
2426

2527
echo "🔐 Getting access token..."
2628
BEARER=$( get_token | jq -r '.access_token' )
29+
if [ -z "$BEARER" ]; then
30+
echo "❌ Failed to get access token."
31+
exit 1
32+
fi
33+
2734
# NOTE: It's always okay to print this token, because it will
2835
# only be valid / available in dummy / dev scenarios
2936
[[ "${DEBUG:-}" == "1" ]] && echo "Got Access Token: ${BEARER}"

.github/workflows/platform-integration-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ jobs:
154154
with:
155155
enable-cache: true
156156
cache-dependency-glob: "uv.lock"
157+
python-version: ${{ inputs.python_version }}
157158

158159
- name: Run all tests, minus integration tests
159160
env:

README.md

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,6 @@ Unofficial OpenTDF SDK for Python
1313

1414
A legacy version (0.2.x) of this project is available for users who need the previous implementation. For more information, see [LEGACY_VERSION.md](docs/LEGACY_VERSION.md) or visit the [legacy branch on GitHub](https://github.com/b-long/opentdf-python-sdk/tree/0.2.x).
1515

16-
## Prerequisites
17-
18-
This project uses [uv](https://docs.astral.sh/uv/) for dependency management and task running.
19-
20-
### Installing uv
21-
22-
Install `uv` using one of the following methods:
23-
24-
**macOS/Linux:**
25-
```bash
26-
curl -LsSf https://astral.sh/uv/install.sh | sh
27-
```
28-
29-
**Windows:**
30-
```powershell
31-
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
32-
```
33-
34-
**Using Homebrew (macOS):**
35-
```bash
36-
brew install uv
37-
```
38-
39-
For more installation options, see the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).
40-
41-
## Development Setup
42-
43-
1. Clone the repository:
44-
```bash
45-
git clone <repository-url>
46-
cd opentdf-python-sdk
47-
```
48-
49-
2. Install dependencies:
50-
```bash
51-
uv sync
52-
```
53-
54-
## Running Tests
55-
56-
Run the full test suite:
57-
```bash
58-
uv run pytest tests/
59-
```
60-
61-
Run specific test files:
62-
```bash
63-
uv run pytest tests/test_sdk.py
64-
```
65-
66-
Run tests with verbose output:
67-
```bash
68-
uv run pytest tests/ -v
69-
```
70-
71-
Run integration tests only:
72-
```bash
73-
uv run pytest tests/ -m integration
74-
```
7516

7617
## Installation
7718

@@ -80,21 +21,6 @@ Install from PyPI:
8021
pip install otdf-python
8122
```
8223

83-
84-
## Protobuf & Connect RPC Generation
85-
86-
This project uses a dedicated submodule, `otdf-python-proto/`, for generating Python protobuf files and Connect RPC clients from OpenTDF platform proto definitions.
87-
88-
### Regenerating Protobuf & Connect RPC Files
89-
90-
From the submodule:
91-
```bash
92-
cd otdf-python-proto
93-
uv run python scripts/generate_connect_proto.py
94-
```
95-
96-
See [`otdf-python-proto/README.md`](otdf-python-proto/README.md) and [`PROTOBUF_SETUP.md`](PROTOBUF_SETUP.md) for details.
97-
9824
## Quick Start
9925

10026
### Basic Configuration
@@ -141,7 +67,7 @@ sdk = builder.build()
14167
from io import BytesIO
14268

14369
# Create TDF configuration with attributes
144-
config = sdk.new_tdf_config(attributes=["https://example.com/attr/classification/value/public"])
70+
config = sdk.new_tdf_config(attributes=["https://example.net/attr/attr1/value/value1"])
14571

14672
# Encrypt data to TDF format
14773
input_data = b"Hello, World!"
@@ -164,8 +90,7 @@ with open("encrypted.tdf", "rb") as f:
16490
encrypted_data = f.read()
16591

16692
# Decrypt TDF
167-
reader_config = TDFReaderConfig()
168-
tdf_reader = sdk.load_tdf(encrypted_data, reader_config)
93+
tdf_reader = sdk.load_tdf(encrypted_data)
16994
decrypted_data = tdf_reader.payload
17095

17196
# Save decrypted data
@@ -189,21 +114,22 @@ src/otdf_python/
189114
└── ... # Additional modules
190115
tests/
191116
└── ... # Various tests
117+
```
192118

193119
## Contributing
194120

195121
1. Fork the repository
196122
2. Create a feature branch: `git checkout -b feature-name`
197123
3. Make your changes
198124
4. Run tests: `uv run pytest tests/`
199-
5. Commit your changes: `git commit -am 'Add feature'`
125+
5. Commit your changes: `git commit -am 'feat: add feature'`
200126
6. Push to the branch: `git push origin feature-name`
201127
7. Submit a pull request
202128

203129
### Release Process
204130

205131
For maintainers and contributors working on releases:
206-
- See [RELEASES.md](RELEASES.md) for comprehensive release documentation
132+
- See [RELEASES.md](docs/RELEASES.md) for comprehensive release documentation
207133
- Feature branch alpha releases available for testing changes before merge
208134
- Automated releases via Release Please on the main branch
209135

docs/DEVELOPING.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,80 @@ You can run the following command in your terminal:
1616
```
1717

1818
Using this script will automatically enable direct access grants in Keycloak for you.
19+
20+
## Dependency Management
21+
22+
### Prerequisites
23+
24+
This project uses [uv](https://docs.astral.sh/uv/) for dependency management and task running.
25+
26+
#### Installing uv
27+
28+
Install `uv` using one of the following methods:
29+
30+
**macOS/Linux:**
31+
```bash
32+
curl -LsSf https://astral.sh/uv/install.sh | sh
33+
```
34+
35+
**Windows:**
36+
```powershell
37+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
38+
```
39+
40+
**Using Homebrew (macOS):**
41+
```bash
42+
brew install uv
43+
```
44+
45+
For more installation options, see the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).
46+
47+
## Development Setup
48+
49+
1. Clone the repository:
50+
```bash
51+
git clone https://github.com/b-long/opentdf-python-sdk.git
52+
cd opentdf-python-sdk
53+
```
54+
55+
2. Install dependencies:
56+
```bash
57+
uv sync
58+
```
59+
60+
### Running Tests
61+
62+
Run the full test suite:
63+
```bash
64+
uv run pytest tests/
65+
```
66+
67+
Run specific test files:
68+
```bash
69+
uv run pytest tests/test_sdk.py
70+
```
71+
72+
Run tests with verbose output:
73+
```bash
74+
uv run pytest tests/ -v
75+
```
76+
77+
Run integration tests only:
78+
```bash
79+
uv run pytest tests/ -m integration
80+
```
81+
82+
83+
### Protobuf & Connect RPC Generation
84+
85+
This project uses a dedicated submodule, `otdf-python-proto/`, for generating Python protobuf files and Connect RPC clients from OpenTDF platform proto definitions.
86+
87+
#### Regenerating Protobuf & Connect RPC Files
88+
89+
From the submodule:
90+
```bash
91+
cd otdf-python-proto
92+
uv run python scripts/generate_connect_proto.py
93+
```
94+
95+
See [`otdf-python-proto/README.md`](../otdf-python-proto/README.md) and [`PROTOBUF_SETUP.md`](./PROTOBUF_SETUP.md) for details.

src/otdf_python/cli.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from otdf_python.sdk import SDK
2121
from otdf_python.sdk_builder import SDKBuilder
2222
from otdf_python.sdk_exceptions import SDKException
23-
from otdf_python.tdf import TDFReaderConfig
2423

2524
try:
2625
__version__ = metadata.version("otdf-python")
@@ -310,10 +309,7 @@ def cmd_decrypt(args):
310309
if encrypted_data.startswith(b"PK"):
311310
# Regular TDF (ZIP format)
312311
logger.debug("Decrypting TDF")
313-
reader_config = TDFReaderConfig()
314-
tdf_reader = sdk.load_tdf_with_config(
315-
encrypted_data, reader_config
316-
)
312+
tdf_reader = sdk.load_tdf(encrypted_data)
317313
# Access payload directly from TDFReader
318314
payload_bytes = tdf_reader.payload
319315
output_file.write(payload_bytes)
@@ -336,8 +332,7 @@ def cmd_decrypt(args):
336332
if encrypted_data.startswith(b"PK"):
337333
# Regular TDF (ZIP format)
338334
logger.debug("Decrypting TDF")
339-
reader_config = TDFReaderConfig()
340-
tdf_reader = sdk.load_tdf_with_config(encrypted_data, reader_config)
335+
tdf_reader = sdk.load_tdf(encrypted_data)
341336
payload_bytes = tdf_reader.payload
342337
output_file.write(payload_bytes)
343338
logger.info("Successfully decrypted TDF")
@@ -370,10 +365,7 @@ def cmd_inspect(args):
370365
if encrypted_data.startswith(b"PK"):
371366
# Regular TDF
372367
logger.debug("Inspecting TDF")
373-
reader_config = TDFReaderConfig()
374-
tdf_reader = sdk.load_tdf_with_config(
375-
BytesIO(encrypted_data), reader_config
376-
)
368+
tdf_reader = sdk.load_tdf(BytesIO(encrypted_data))
377369
manifest = tdf_reader.manifest
378370

379371
# Try to get data attributes

src/otdf_python/sdk.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,13 @@ def get_platform_url(self) -> str | None:
348348
"""Returns the platform URL if set"""
349349
return self.platform_url
350350

351-
def load_tdf_with_config(
352-
self, tdf_data: bytes | BinaryIO | BytesIO, config: TDFReaderConfig
351+
def load_tdf(
352+
self,
353+
tdf_data: bytes | BinaryIO | BytesIO,
354+
config: TDFReaderConfig | None = None,
353355
) -> TDFReader:
354356
"""
355-
Loads a TDF from the provided data according to the config.
357+
Loads a TDF from the provided data, optionally according to the config.
356358
357359
Args:
358360
tdf_data: The TDF data as bytes, file object, or BytesIO
@@ -365,26 +367,10 @@ def load_tdf_with_config(
365367
SDKException: If there's an error loading the TDF
366368
"""
367369
tdf = TDF(self.services)
368-
return tdf.load_tdf(tdf_data, config)
369-
370-
def load_tdf_without_config(
371-
self, tdf_data: bytes | BinaryIO | BytesIO
372-
) -> TDFReader:
373-
"""
374-
Loads a TDF from the provided data.
375-
376-
Args:
377-
tdf_data: The TDF data as bytes, file object, or BytesIO
370+
if config is None:
371+
config = TDFReaderConfig()
378372

379-
Returns:
380-
TDFReader: Contains payload and manifest
381-
382-
Raises:
383-
SDKException: If there's an error loading the TDF
384-
"""
385-
tdf = TDF(self.services)
386-
default = TDFReaderConfig()
387-
return tdf.load_tdf(tdf_data, default)
373+
return tdf.load_tdf(tdf_data, config)
388374

389375
def create_tdf(
390376
self,

tests/integration/test_pe_interaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def decrypt(input_path: Path, output_path: Path, sdk: SDK):
2525
with open(input_path, "rb") as infile, open(output_path, "wb") as outfile:
2626
try:
2727
logger.debug("Decrypting TDF")
28-
tdf_reader = sdk.load_tdf_without_config(infile.read())
28+
tdf_reader = sdk.load_tdf(infile.read())
2929
# Access payload directly from TDFReader
3030
payload_bytes = tdf_reader.payload
3131
outfile.write(payload_bytes)

tests/test_validate_otdf_python.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import pytest
1515

16-
from otdf_python.tdf import TDFReaderConfig
1716
from tests.integration.support_sdk import get_sdk
1817

1918
# Set up detailed logging
@@ -52,13 +51,8 @@ def decrypt_file(encrypted_path: Path) -> Path:
5251

5352
output_path = encrypted_path.with_suffix(".decrypted")
5453
with open(encrypted_path, "rb") as infile, open(output_path, "wb") as outfile:
55-
# Include attributes for policy enforcement
56-
reader_config = TDFReaderConfig(
57-
attributes=_test_attributes # Same attributes used in encrypt_file
58-
)
59-
6054
# Use KAS client for key unwrapping
61-
reader = sdk.load_tdf_with_config(infile.read(), reader_config)
55+
reader = sdk.load_tdf(infile.read())
6256
# TDFReader is a dataclass with payload attribute
6357
outfile.write(reader.payload)
6458
return output_path

0 commit comments

Comments
 (0)