dq-export-connector 0.1.0.dev8__tar.gz → 0.1.0.dev9__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.
Files changed (32) hide show
  1. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/PKG-INFO +2 -2
  2. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/README.md +1 -1
  3. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/_models/bucket_validation_result.py +2 -1
  4. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/_models/export_report.py +2 -1
  5. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/export.py +6 -2
  6. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/store.py +21 -1
  7. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/errors.py +8 -0
  8. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/report.py +3 -2
  9. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/pyproject.toml +1 -1
  10. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/tests/test_runner.py +40 -0
  11. dq_export_connector-0.1.0.dev9/tests/test_store.py +46 -0
  12. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/uv.lock +1 -1
  13. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/.gitignore +0 -0
  14. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/.python-version +0 -0
  15. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/__init__.py +0 -0
  16. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/_models/__init__.py +0 -0
  17. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/_models/export_connector_credentials.py +0 -0
  18. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/_models/export_worker_config.py +0 -0
  19. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/__init__.py +0 -0
  20. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/datasets.py +0 -0
  21. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/paths.py +0 -0
  22. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/upload.py +0 -0
  23. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/bucket/validate.py +0 -0
  24. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/log.py +0 -0
  25. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/redact.py +0 -0
  26. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/dq_export_connector/runner.py +0 -0
  27. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/scripts/codegen-models.sh +0 -0
  28. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/tests/test_live_buckets.py +0 -0
  29. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/tests/test_models_are_current.py +0 -0
  30. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/tests/test_paths.py +0 -0
  31. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/tests/test_redact.py +0 -0
  32. {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev9}/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.dev8
3
+ Version: 0.1.0.dev9
4
4
  Summary: Worker logic for the Export Connector DCR.
5
5
  Author: Decentriq
6
6
  Requires-Python: >=3.10
@@ -25,7 +25,7 @@ published to PyPI, since the compiled graph installs it from there.
25
25
  - `dq_export_connector.errors`: the codes the worker reports, and
26
26
  `ExportConnectorError`, which stops a run with one.
27
27
  - `dq_export_connector.report`: collects a run's error, warnings and receipt
28
- while it runs.
28
+ while it runs, and cuts each message to ddc's 1,000 characters once redacted.
29
29
  - `dq_export_connector.redact`: keeps every value from the sealed half, and
30
30
  URL query strings, out of log lines and result messages.
31
31
  - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
@@ -15,7 +15,7 @@ published to PyPI, since the compiled graph installs it from there.
15
15
  - `dq_export_connector.errors`: the codes the worker reports, and
16
16
  `ExportConnectorError`, which stops a run with one.
17
17
  - `dq_export_connector.report`: collects a run's error, warnings and receipt
18
- while it runs.
18
+ while it runs, and cuts each message to ddc's 1,000 characters once redacted.
19
19
  - `dq_export_connector.redact`: keeps every value from the sealed half, and
20
20
  URL query strings, out of log lines and result messages.
21
21
  - `dq_export_connector.bucket`: the bucket kind (`ValidateConnection` and
@@ -21,7 +21,8 @@ class ExportMessage(BaseModel):
21
21
  message: Annotated[
22
22
  str,
23
23
  Field(
24
- description='Safe to show to the user: no credentials and no dataset values.'
24
+ description='Safe to show to the user: no credentials and no dataset values. A\nlonger one is cut, ending in `…`.',
25
+ max_length=1000,
25
26
  ),
26
27
  ]
27
28
 
@@ -61,7 +61,8 @@ class ExportMessage(BaseModel):
61
61
  message: Annotated[
62
62
  str,
63
63
  Field(
64
- description='Safe to show to the user: no credentials and no dataset values.'
64
+ description='Safe to show to the user: no credentials and no dataset values. A\nlonger one is cut, ending in `…`.',
65
+ max_length=1000,
65
66
  ),
66
67
  ]
67
68
 
@@ -5,6 +5,7 @@ they are, and the receipt counts them."""
5
5
  from __future__ import annotations
6
6
 
7
7
  import time
8
+ import zipfile
8
9
  from collections.abc import Callable, Iterator
9
10
  from contextlib import contextmanager
10
11
  from datetime import datetime
@@ -147,11 +148,14 @@ def _export_input(
147
148
 
148
149
  @contextmanager
149
150
  def _reading(destination: str) -> Iterator[None]:
151
+ """A stored ZIP that is corrupt raises `BadZipFile`, or `EOFError` for an
152
+ entry cut short, when its entry is read."""
150
153
  try:
151
154
  yield
152
- except OSError as error:
155
+ except (OSError, EOFError, zipfile.BadZipFile) as error:
153
156
  raise ExportConnectorError(
154
- ErrorCode.READ_FAILED, f"The dataset for '{destination}/' couldn't be read: {error}"
157
+ ErrorCode.READ_FAILED,
158
+ f"The dataset for '{destination}/' couldn't be read: {str(error) or type(error).__name__}",
155
159
  ) from error
156
160
 
157
161
 
@@ -57,11 +57,17 @@ CLIENT_CONFIG: ClientConfig = {
57
57
  T = TypeVar("T")
58
58
 
59
59
 
60
+ def describe(error: Exception) -> str:
61
+ """obstore's message without the `Debug source:` dump it appends, which
62
+ repeats the error."""
63
+ return str(error).split("\n\nDebug source:", 1)[0]
64
+
65
+
60
66
  class StorageError(Exception):
61
67
  """A request to the Bucket Provider failed; `cause` is obstore's error."""
62
68
 
63
69
  def __init__(self, cause: Exception) -> None:
64
- super().__init__(str(cause))
70
+ super().__init__(describe(cause))
65
71
  self.cause = cause
66
72
 
67
73
 
@@ -130,6 +136,9 @@ _MESSAGE_CLASSIFIERS: list[tuple[ErrorCode, tuple[str, ...]]] = [
130
136
  ErrorCode.DESTINATION_NOT_FOUND,
131
137
  (
132
138
  "NoSuchBucket", # S3
139
+ # S3, for a bucket in another region than the connection's
140
+ "PermanentRedirect",
141
+ "incorrectly configured region",
133
142
  "ContainerNotFound", # Azure
134
143
  "bucket does not exist", # GCS
135
144
  "status code: 404",
@@ -191,6 +200,17 @@ def failure_sentence(code: ErrorCode, where: str) -> str:
191
200
 
192
201
 
193
202
  def build_store(connection: BucketConnection, credentials: BucketCredentials) -> Any:
203
+ """obstore parses the credentials here, so a malformed GCS key or Azure SAS
204
+ token fails before any request."""
205
+ try:
206
+ return _store(connection, credentials)
207
+ except obstore.exceptions.BaseError as error:
208
+ raise ExportConnectorError(
209
+ ErrorCode.INVALID_CREDENTIALS, f"The credentials couldn't be read: {describe(error)}"
210
+ ) from error
211
+
212
+
213
+ def _store(connection: BucketConnection, credentials: BucketCredentials) -> Any:
194
214
  """ddc pins the provider pairing, so a mismatch here is a bug."""
195
215
  match (connection.root, credentials.root):
196
216
  case (BucketConnection1() as s3, BucketCredentials1() as s3_credentials):
@@ -23,6 +23,14 @@ class ErrorCode(str, Enum):
23
23
  BUCKET_PROBE_NOT_DELETED = "BUCKET_PROBE_NOT_DELETED"
24
24
 
25
25
 
26
+ # ddc's limit on a report message, in characters.
27
+ MAX_MESSAGE_LENGTH = 1000
28
+
29
+
30
+ def truncate(text: str, limit: int) -> str:
31
+ return text if len(text) <= limit else text[: limit - 1] + "…"
32
+
33
+
26
34
  class ExportConnectorError(Exception):
27
35
  """Stops the run and becomes its report's error. `message` is shown to the
28
36
  user, so it must not hold dataset values; credentials are redacted."""
@@ -7,7 +7,7 @@ from typing import Any
7
7
 
8
8
  from dq_export_connector._models.bucket_validation_result import BucketValidationResult
9
9
  from dq_export_connector._models.export_report import ExportReceiptV0, ExportReport
10
- from dq_export_connector.errors import ErrorCode
10
+ from dq_export_connector.errors import MAX_MESSAGE_LENGTH, ErrorCode, truncate
11
11
  from dq_export_connector.redact import Redactor
12
12
 
13
13
 
@@ -31,7 +31,8 @@ class ReportBuilder:
31
31
 
32
32
  def _messages(self, redactor: Redactor) -> dict[str, Any]:
33
33
  def message(code: ErrorCode, text: str) -> dict[str, str]:
34
- return {"code": code.value, "message": redactor.redact(text)}
34
+ # Cut once redacted, so a cut can't leave part of a secret unmasked.
35
+ return {"code": code.value, "message": truncate(redactor.redact(text), MAX_MESSAGE_LENGTH)}
35
36
 
36
37
  return {
37
38
  "error": None if self.error is None else message(*self.error),
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dq-export-connector"
3
- version = "0.1.0.dev8"
3
+ version = "0.1.0.dev9"
4
4
  description = "Worker logic for the Export Connector DCR."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Decentriq" }]
@@ -15,6 +15,7 @@ from obstore.store import LocalStore, MemoryStore
15
15
  from dq_export_connector import runner
16
16
  from dq_export_connector.bucket import export
17
17
  from dq_export_connector.bucket.store import StorageError
18
+ from dq_export_connector.errors import MAX_MESSAGE_LENGTH
18
19
 
19
20
  SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
20
21
  CREDENTIALS = {"bucket": {"s3": {"accessKey": "AKIAEXAMPLE", "secretKey": SECRET_KEY}}}
@@ -171,6 +172,45 @@ def test_a_failed_input_stops_the_run_and_keeps_what_was_written(tmp_path, monke
171
172
  )
172
173
 
173
174
 
175
+ @pytest.mark.parametrize(
176
+ ("corrupt", "reason"),
177
+ [
178
+ (lambda data: data.replace(b"hello world", b"hellO world"), "Bad CRC-32 for file 'a.csv'"),
179
+ (lambda data: data.replace(b"PK\x03\x04", b"PK\x00\x00", 1), "Bad magic number for file header"),
180
+ ],
181
+ )
182
+ def test_a_corrupt_stored_zip_is_unreadable(tmp_path, monkeypatch, corrupt, reason):
183
+ store = MemoryStore()
184
+ config = _config(EXPORT, [("segA", "seg_a")])
185
+ _run(tmp_path, config, {"segA": corrupt(_zip({"a.csv": b"hello world"}))}, store, monkeypatch)
186
+ assert (_objects(store), _report(tmp_path)) == (
187
+ {},
188
+ {
189
+ "version": "V0",
190
+ "error": {"code": "READ_FAILED", "message": f"The dataset for 'seg_a/' couldn't be read: {reason}"},
191
+ "warnings": [],
192
+ "receipt": _receipt([("segA", "seg_a", 0, 0)]),
193
+ },
194
+ )
195
+
196
+
197
+ def test_a_long_message_is_cut_after_its_credentials_are_masked(tmp_path, monkeypatch):
198
+ prefix = (
199
+ "The bucket 'acme' in eu-central-1 returned an error, so writing 'decentriq/seg_a/data' failed after 0 of 1"
200
+ " files for 'seg_a/': "
201
+ )
202
+ # The secret straddles the cut, so cutting first would leave its start unmasked.
203
+ padding = "x" * (MAX_MESSAGE_LENGTH - len(prefix) - 10)
204
+
205
+ def failing(*_):
206
+ raise StorageError(RuntimeError(padding + SECRET_KEY + "y" * 2000))
207
+
208
+ monkeypatch.setattr(export, "upload", failing)
209
+ _run(tmp_path, _config(EXPORT, [("segA", "seg_a")]), {"segA": b"x"}, MemoryStore(), monkeypatch)
210
+ expected = (prefix + padding + "***" + "y" * 2000)[: MAX_MESSAGE_LENGTH - 1] + "…"
211
+ assert _report(tmp_path)["error"] == {"code": "UNKNOWN", "message": expected}
212
+
213
+
174
214
  def test_a_storage_error_is_reported_with_its_code(tmp_path, monkeypatch):
175
215
  read_only = tmp_path / "bucket"
176
216
  read_only.mkdir(mode=0o500)
@@ -0,0 +1,46 @@
1
+ import obstore.exceptions
2
+
3
+ from dq_export_connector._models.export_connector_credentials import BucketCredentials
4
+ from dq_export_connector._models.export_worker_config import BucketConnection
5
+ from dq_export_connector.bucket.store import build_store, classify_error, describe
6
+ from dq_export_connector.errors import ErrorCode, ExportConnectorError
7
+
8
+
9
+ def _build_error(connection, credentials):
10
+ try:
11
+ build_store(BucketConnection.model_validate(connection), BucketCredentials.model_validate(credentials))
12
+ except ExportConnectorError as error:
13
+ return error.code, error.message
14
+ return None
15
+
16
+
17
+ def test_malformed_credentials_are_invalid_before_any_request():
18
+ gcs = {"type": "gcs", "bucket": "b", "pathPrefix": None}
19
+ azure = {"type": "azureBlob", "accountName": "a", "container": "c", "pathPrefix": None}
20
+ assert [
21
+ _build_error(gcs, {"gcs": {"serviceAccountJson": "not json"}}),
22
+ _build_error(azure, {"azureBlob": {"sasToken": "garbage"}}),
23
+ ] == [
24
+ (
25
+ ErrorCode.INVALID_CREDENTIALS,
26
+ "The credentials couldn't be read: Generic GCS error: GCP credential error: Unable to decode service"
27
+ " account file: expected ident at line 1 column 2",
28
+ ),
29
+ (
30
+ ErrorCode.INVALID_CREDENTIALS,
31
+ "The credentials couldn't be read: Generic MicrosoftAzure error: Missing component in SAS query pair",
32
+ ),
33
+ ]
34
+
35
+
36
+ def test_obstores_debug_dump_is_left_out():
37
+ error = obstore.exceptions.GenericError("Generic S3 error: failed\n\nDebug source:\nGeneric {\n store: \"S3\",\n}")
38
+ assert describe(error) == "Generic S3 error: failed"
39
+
40
+
41
+ def test_a_bucket_in_another_region_is_not_found_there():
42
+ error = obstore.exceptions.GenericError(
43
+ "Generic S3 error: Error performing PUT https://s3.us-east-1.amazonaws.com/b/k in 482ms - Received redirect"
44
+ " without LOCATION, this normally indicates an incorrectly configured region"
45
+ )
46
+ assert classify_error(error) == ErrorCode.DESTINATION_NOT_FOUND
@@ -96,7 +96,7 @@ wheels = [
96
96
 
97
97
  [[package]]
98
98
  name = "dq-export-connector"
99
- version = "0.1.0.dev8"
99
+ version = "0.1.0.dev9"
100
100
  source = { editable = "." }
101
101
  dependencies = [
102
102
  { name = "obstore" },