dq-export-connector 0.1.0.dev12__tar.gz → 0.1.0.dev14__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.
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/PKG-INFO +8 -6
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/README.md +7 -5
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/datasets.py +10 -4
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/store.py +47 -4
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/errors.py +1 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/pyproject.toml +1 -1
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_runner.py +21 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_store.py +23 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/uv.lock +1 -1
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/.gitignore +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/.python-version +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/_models/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/_models/bucket_validation_result.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/_models/export_connector_credentials.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/_models/export_report.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/_models/export_worker_config.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/export.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/paths.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/upload.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/bucket/validate.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/log.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/redact.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/report.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/runner.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/scripts/codegen-models.sh +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_live_buckets.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_models_are_current.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_paths.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_redact.py +0 -0
- {dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_upload.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dq-export-connector
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev14
|
|
4
4
|
Summary: Worker logic for the Export Connector DCR.
|
|
5
5
|
Author: Decentriq
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -46,8 +46,10 @@ uv run mypy dq_export_connector tests
|
|
|
46
46
|
|
|
47
47
|
## Releasing
|
|
48
48
|
|
|
49
|
-
Bump
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
Bump the version with `uv version <version> --no-sync`, which also updates
|
|
50
|
+
`uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
|
|
51
|
+
commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
|
|
52
|
+
uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
|
|
53
|
+
ddc then pins the new version, as
|
|
54
|
+
[ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
|
|
55
|
+
describes.
|
|
@@ -35,8 +35,10 @@ uv run mypy dq_export_connector tests
|
|
|
35
35
|
|
|
36
36
|
## Releasing
|
|
37
37
|
|
|
38
|
-
Bump
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
Bump the version with `uv version <version> --no-sync`, which also updates
|
|
39
|
+
`uv.lock`, commit, and push a `dq-export-connector-v<version>` tag on that
|
|
40
|
+
commit; the `Publish dq-export-connector to PyPI` workflow tests, builds and
|
|
41
|
+
uploads it. Use `.devN` versions while developing; PyPI releases can't be replaced.
|
|
42
|
+
ddc then pins the new version, as
|
|
43
|
+
[ddc's export worker README](../../dcr-compiler/ddc/src/archv2/data_room/export_connector/README.md)
|
|
44
|
+
describes.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""How an Input's dataset maps to files. A ZIP whose entries are all stored
|
|
2
|
-
without compression is unpacked, each entry keeping its path
|
|
3
|
-
|
|
4
|
-
`data`."""
|
|
2
|
+
without compression is unpacked, each entry keeping its path, except the logs
|
|
3
|
+
a compute worker adds to its result. Anything else, including a ZIP with a
|
|
4
|
+
compressed or an encrypted entry, is one raw file named `data`."""
|
|
5
5
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
@@ -13,6 +13,8 @@ from pathlib import Path
|
|
|
13
13
|
from typing import BinaryIO
|
|
14
14
|
|
|
15
15
|
RAW_FILE_NAME = "data"
|
|
16
|
+
# A compute worker can write its logs at the root of its result ZIP.
|
|
17
|
+
CONTAINER_LOG = "container.log"
|
|
16
18
|
# The ZIP general purpose flags of an encrypted entry and of a UTF-8 name.
|
|
17
19
|
_ENCRYPTED = 0x1
|
|
18
20
|
_UTF8_NAME = 0x800
|
|
@@ -57,7 +59,11 @@ def open_dataset(dataset_path: Path) -> Iterator[tuple[Layout, _Reader]]:
|
|
|
57
59
|
return
|
|
58
60
|
named = [(_name(entry), entry) for entry in entries]
|
|
59
61
|
# An entry is a directory by its name alone, whatever its attributes say.
|
|
60
|
-
files = [
|
|
62
|
+
files = [
|
|
63
|
+
DatasetFile(name, entry.file_size, entry)
|
|
64
|
+
for name, entry in named
|
|
65
|
+
if not name.endswith("/") and name != CONTAINER_LOG
|
|
66
|
+
]
|
|
61
67
|
yield Layout(files, None), _ZipReader(archive)
|
|
62
68
|
|
|
63
69
|
|
|
@@ -5,8 +5,9 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import re
|
|
7
7
|
from collections.abc import Callable
|
|
8
|
-
from datetime import timedelta
|
|
8
|
+
from datetime import datetime, timedelta, timezone
|
|
9
9
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
10
|
+
from urllib.parse import unquote
|
|
10
11
|
|
|
11
12
|
import obstore.exceptions
|
|
12
13
|
from obstore.store import AzureStore, GCSStore, S3Store
|
|
@@ -215,7 +216,7 @@ def _store(connection: BucketConnection, credentials: BucketExportCredentials) -
|
|
|
215
216
|
return AzureStore(
|
|
216
217
|
container_name=azure.container,
|
|
217
218
|
account_name=azure.account_name,
|
|
218
|
-
sas_key=
|
|
219
|
+
sas_key=_checked_azure_sas_token(azure_credentials.sas_token),
|
|
219
220
|
retry_config=RETRY_CONFIG,
|
|
220
221
|
client_options=CLIENT_CONFIG,
|
|
221
222
|
)
|
|
@@ -240,10 +241,11 @@ def _checked_s3_access_key(access_key: str) -> str:
|
|
|
240
241
|
return access_key
|
|
241
242
|
|
|
242
243
|
|
|
243
|
-
def
|
|
244
|
+
def _checked_azure_sas_token(sas_token: str) -> str:
|
|
244
245
|
"""The portal's "Blob SAS token" includes a leading `?`. A SAS URL is
|
|
245
246
|
rejected rather than parsed: its account and container would be ignored,
|
|
246
|
-
hiding a paste error.
|
|
247
|
+
hiding a paste error. An expired token fails before any request, since
|
|
248
|
+
Azure's answer to it looks like a rejected one's."""
|
|
247
249
|
token = sas_token.strip().lstrip("?")
|
|
248
250
|
if "://" in token:
|
|
249
251
|
raise ExportConnectorError(
|
|
@@ -253,4 +255,45 @@ def _normalize_azure_sas_token(sas_token: str) -> str:
|
|
|
253
255
|
)
|
|
254
256
|
if not token:
|
|
255
257
|
raise ExportConnectorError(ErrorCode.INVALID_CREDENTIALS, "The Azure SAS token in the credentials is empty")
|
|
258
|
+
expiry = _sas_token_expiry(token)
|
|
259
|
+
if expiry is not None and expiry <= datetime.now(timezone.utc):
|
|
260
|
+
raise ExportConnectorError(
|
|
261
|
+
ErrorCode.CREDENTIALS_EXPIRED,
|
|
262
|
+
f"The Azure SAS token expired at {expiry.astimezone(timezone.utc):%Y-%m-%d %H:%M:%S} UTC:"
|
|
263
|
+
" replace it with a new one",
|
|
264
|
+
)
|
|
256
265
|
return token
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
# Azure's accepted forms: a date, or a date and time to the minute or the
|
|
269
|
+
# second, with `Z`, an offset, or no suffix for UTC.
|
|
270
|
+
_AZURE_DATETIME_FORMATS = (
|
|
271
|
+
"%Y-%m-%d",
|
|
272
|
+
"%Y-%m-%dT%H:%M%z",
|
|
273
|
+
"%Y-%m-%dT%H:%M",
|
|
274
|
+
"%Y-%m-%dT%H:%M:%S%z",
|
|
275
|
+
"%Y-%m-%dT%H:%M:%S",
|
|
276
|
+
"%Y-%m-%dT%H:%M:%S.%f%z",
|
|
277
|
+
"%Y-%m-%dT%H:%M:%S.%f",
|
|
278
|
+
)
|
|
279
|
+
# Azure allows seven digits of fractional seconds, strptime six.
|
|
280
|
+
_SEVENTH_FRACTION_DIGIT = re.compile(r"(\.\d{6})\d")
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _sas_token_expiry(token: str) -> datetime | None:
|
|
284
|
+
"""The token's `se`. A token without one names a stored access policy,
|
|
285
|
+
which holds its expiry."""
|
|
286
|
+
values = [unquote(value) for key, _, value in (pair.partition("=") for pair in token.split("&")) if key == "se"]
|
|
287
|
+
if not values:
|
|
288
|
+
return None
|
|
289
|
+
value = _SEVENTH_FRACTION_DIGIT.sub(r"\1", values[0])
|
|
290
|
+
for datetime_format in _AZURE_DATETIME_FORMATS:
|
|
291
|
+
try:
|
|
292
|
+
expiry = datetime.strptime(value, datetime_format)
|
|
293
|
+
except ValueError:
|
|
294
|
+
continue
|
|
295
|
+
return expiry if expiry.tzinfo else expiry.replace(tzinfo=timezone.utc)
|
|
296
|
+
raise ExportConnectorError(
|
|
297
|
+
ErrorCode.INVALID_CREDENTIALS,
|
|
298
|
+
f"The Azure SAS token's expiry `se={values[0]}` isn't a date and time Azure accepts",
|
|
299
|
+
)
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/errors.py
RENAMED
|
@@ -11,6 +11,7 @@ from enum import Enum
|
|
|
11
11
|
class ErrorCode(str, Enum):
|
|
12
12
|
INVALID_CREDENTIALS = "INVALID_CREDENTIALS"
|
|
13
13
|
UNAUTHENTICATED = "UNAUTHENTICATED"
|
|
14
|
+
CREDENTIALS_EXPIRED = "CREDENTIALS_EXPIRED"
|
|
14
15
|
ACCESS_DENIED = "ACCESS_DENIED"
|
|
15
16
|
DESTINATION_NOT_FOUND = "DESTINATION_NOT_FOUND"
|
|
16
17
|
UNREACHABLE = "UNREACHABLE"
|
|
@@ -98,6 +98,27 @@ def _receipt(inputs, export_prefix=None):
|
|
|
98
98
|
return receipt if export_prefix is None else {**receipt, "exportPrefix": export_prefix}
|
|
99
99
|
|
|
100
100
|
|
|
101
|
+
def test_the_logs_a_compute_worker_adds_to_its_result_are_not_exported(tmp_path, monkeypatch):
|
|
102
|
+
store = MemoryStore()
|
|
103
|
+
result = {
|
|
104
|
+
"dataset.csv": b"a,b\n",
|
|
105
|
+
"container.log": b"logs",
|
|
106
|
+
"accessed_domains.txt": b"example.com",
|
|
107
|
+
"types": b"schema",
|
|
108
|
+
"sub/container.log": b"kept",
|
|
109
|
+
}
|
|
110
|
+
_run(tmp_path, _config(EXPORT, [("segA", "seg_a")]), {"segA": _zip(result)}, store, monkeypatch)
|
|
111
|
+
assert (_objects(store), _report(tmp_path)) == (
|
|
112
|
+
{
|
|
113
|
+
"decentriq/seg_a/dataset.csv": b"a,b\n",
|
|
114
|
+
"decentriq/seg_a/accessed_domains.txt": b"example.com",
|
|
115
|
+
"decentriq/seg_a/types": b"schema",
|
|
116
|
+
"decentriq/seg_a/sub/container.log": b"kept",
|
|
117
|
+
},
|
|
118
|
+
{"version": "V0", "warnings": [], "receipt": _receipt([("segA", "seg_a", 4, 25)])},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
101
122
|
def test_stored_zips_are_unpacked_and_other_datasets_written_raw(tmp_path, monkeypatch):
|
|
102
123
|
store = MemoryStore()
|
|
103
124
|
datasets = {
|
|
@@ -59,6 +59,29 @@ def test_malformed_credentials_are_invalid_before_any_request():
|
|
|
59
59
|
]
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
def test_an_expired_sas_token_fails_before_any_request():
|
|
63
|
+
azure = {"type": "azureBlob", "accountName": "a", "container": "c", "pathPrefix": None}
|
|
64
|
+
tokens = [
|
|
65
|
+
"sv=2022-11-02&se=2020-01-01T00%3A00%3A00Z&sr=c&sp=cw&sig=x",
|
|
66
|
+
"?se=2020-01-01T01:30%2B01:00&sig=x",
|
|
67
|
+
"se=2020-01-01&sig=x",
|
|
68
|
+
"se=2020-01-01T00:00:00.1234567&sig=x",
|
|
69
|
+
"se=2999-01-01T00:00Z&sig=x",
|
|
70
|
+
"si=policy&sig=x",
|
|
71
|
+
"se=next-year&sig=x",
|
|
72
|
+
]
|
|
73
|
+
expired = "The Azure SAS token expired at {} UTC: replace it with a new one"
|
|
74
|
+
assert [_build_error(azure, {"type": "azureBlob", "sasToken": token}) for token in tokens] == [
|
|
75
|
+
(ErrorCode.CREDENTIALS_EXPIRED, expired.format("2020-01-01 00:00:00")),
|
|
76
|
+
(ErrorCode.CREDENTIALS_EXPIRED, expired.format("2020-01-01 00:30:00")),
|
|
77
|
+
(ErrorCode.CREDENTIALS_EXPIRED, expired.format("2020-01-01 00:00:00")),
|
|
78
|
+
(ErrorCode.CREDENTIALS_EXPIRED, expired.format("2020-01-01 00:00:00")),
|
|
79
|
+
None,
|
|
80
|
+
None,
|
|
81
|
+
(ErrorCode.INVALID_CREDENTIALS, "The Azure SAS token's expiry `se=next-year` isn't a date and time Azure accepts"),
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
|
|
62
85
|
def test_an_s3_access_key_no_header_can_hold_is_invalid():
|
|
63
86
|
s3 = {"type": "s3", "region": "eu-central-1", "bucket": "b", "pathPrefix": None}
|
|
64
87
|
error = (
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/log.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/redact.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/report.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/dq_export_connector/runner.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/scripts/codegen-models.sh
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_live_buckets.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev12 → dq_export_connector-0.1.0.dev14}/tests/test_models_are_current.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|