dq-export-connector 0.1.0.dev8__tar.gz → 0.1.0.dev10__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.dev8 → dq_export_connector-0.1.0.dev10}/PKG-INFO +2 -2
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/README.md +1 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/_models/bucket_validation_result.py +1 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/_models/export_report.py +1 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/datasets.py +11 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/export.py +7 -3
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/store.py +57 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/errors.py +8 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/report.py +3 -2
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/pyproject.toml +1 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_runner.py +66 -0
- dq_export_connector-0.1.0.dev10/tests/test_store.py +110 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/uv.lock +1 -1
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/.gitignore +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/.python-version +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/_models/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/_models/export_connector_credentials.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/_models/export_worker_config.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/paths.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/upload.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/bucket/validate.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/log.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/redact.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/runner.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/scripts/codegen-models.sh +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_live_buckets.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_models_are_current.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_paths.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_redact.py +0 -0
- {dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/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.dev10
|
|
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,7 @@ 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. Writers\ncut it to 1,000 characters, marking the cut with `…`.'
|
|
25
25
|
),
|
|
26
26
|
]
|
|
27
27
|
|
|
@@ -61,7 +61,7 @@ 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. Writers\ncut it to 1,000 characters, marking the cut with `…`.'
|
|
65
65
|
),
|
|
66
66
|
]
|
|
67
67
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""How an Input's dataset maps to files. A ZIP whose entries are all stored
|
|
2
2
|
without compression is unpacked, each entry keeping its path. Anything else,
|
|
3
|
-
including a ZIP with a compressed entry, is one raw file named `data`.
|
|
3
|
+
including a ZIP with a compressed entry, is one raw file named `data`. A
|
|
4
|
+
stored ZIP with an encrypted entry can't be read."""
|
|
4
5
|
|
|
5
6
|
from __future__ import annotations
|
|
6
7
|
|
|
@@ -12,6 +13,12 @@ from pathlib import Path
|
|
|
12
13
|
from typing import BinaryIO
|
|
13
14
|
|
|
14
15
|
RAW_FILE_NAME = "data"
|
|
16
|
+
# The ZIP general purpose flag of an encrypted entry.
|
|
17
|
+
_ENCRYPTED = 0x1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class UnreadableDatasetError(Exception):
|
|
21
|
+
pass
|
|
15
22
|
|
|
16
23
|
|
|
17
24
|
@dataclass(frozen=True)
|
|
@@ -46,6 +53,9 @@ def open_dataset(dataset_path: Path) -> Iterator[tuple[Layout, _Reader]]:
|
|
|
46
53
|
size = dataset_path.stat().st_size
|
|
47
54
|
yield Layout([DatasetFile(RAW_FILE_NAME, size)], "a ZIP with compressed entries"), _RawReader(dataset_path)
|
|
48
55
|
return
|
|
56
|
+
encrypted = [entry.filename for entry in entries if entry.flag_bits & _ENCRYPTED]
|
|
57
|
+
if encrypted:
|
|
58
|
+
raise UnreadableDatasetError(f"its ZIP entry '{encrypted[0]}' is encrypted")
|
|
49
59
|
files = [DatasetFile(entry.filename, entry.file_size) for entry in entries if not entry.is_dir()]
|
|
50
60
|
yield Layout(files, None), _ZipReader(archive)
|
|
51
61
|
|
|
@@ -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
|
|
@@ -20,7 +21,7 @@ from dq_export_connector._models.export_report import (
|
|
|
20
21
|
ExportTotals,
|
|
21
22
|
)
|
|
22
23
|
from dq_export_connector._models.export_worker_config import BucketInput, ExportConnectorKind1, ProvisionedPolicy
|
|
23
|
-
from dq_export_connector.bucket.datasets import DatasetFile, open_dataset
|
|
24
|
+
from dq_export_connector.bucket.datasets import DatasetFile, UnreadableDatasetError, open_dataset
|
|
24
25
|
from dq_export_connector.bucket.paths import InvalidPathError, check_dataset_path, check_key, fill_date_tokens, join_key
|
|
25
26
|
from dq_export_connector.bucket.store import StorageError, classify_error, failure_sentence, location
|
|
26
27
|
from dq_export_connector.bucket.upload import plan_upload, upload
|
|
@@ -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, UnreadableDatasetError) as error:
|
|
153
156
|
raise ExportConnectorError(
|
|
154
|
-
ErrorCode.READ_FAILED,
|
|
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
|
|
|
@@ -3,6 +3,7 @@ failures map to."""
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
+
import re
|
|
6
7
|
from collections.abc import Callable
|
|
7
8
|
from datetime import timedelta
|
|
8
9
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
@@ -24,6 +25,7 @@ from dq_export_connector._models.export_worker_config import (
|
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
from dq_export_connector.errors import ErrorCode, ExportConnectorError
|
|
28
|
+
from dq_export_connector.redact import MASK
|
|
27
29
|
|
|
28
30
|
if TYPE_CHECKING:
|
|
29
31
|
from obstore.store import ClientConfig, RetryConfig
|
|
@@ -57,11 +59,30 @@ CLIENT_CONFIG: ClientConfig = {
|
|
|
57
59
|
T = TypeVar("T")
|
|
58
60
|
|
|
59
61
|
|
|
62
|
+
_HTTP_ERROR = re.compile(r"HttpError \{\s*kind: (?P<kind>\w+),\s*source: reqwest::Error \{(?P<source>.*)", re.DOTALL)
|
|
63
|
+
_STRING_LITERAL = re.compile(r'"((?:[^"\\]|\\.)*)"')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def describe(error: Exception) -> str:
|
|
67
|
+
"""obstore's message without the `Debug source:` dump it appends. For a
|
|
68
|
+
request that couldn't be sent, the message stops at "error sending
|
|
69
|
+
request", so the causes the dump holds, such as a DNS failure or a refused
|
|
70
|
+
connection, are appended."""
|
|
71
|
+
message, _, dump = str(error).partition("\n\nDebug source:")
|
|
72
|
+
http_error = _HTTP_ERROR.search(dump)
|
|
73
|
+
if http_error is None:
|
|
74
|
+
return message
|
|
75
|
+
causes = _STRING_LITERAL.findall(http_error["source"])
|
|
76
|
+
if http_error["kind"] == "Timeout":
|
|
77
|
+
causes.append("timed out")
|
|
78
|
+
return ": ".join([message, *causes])
|
|
79
|
+
|
|
80
|
+
|
|
60
81
|
class StorageError(Exception):
|
|
61
82
|
"""A request to the Bucket Provider failed; `cause` is obstore's error."""
|
|
62
83
|
|
|
63
84
|
def __init__(self, cause: Exception) -> None:
|
|
64
|
-
super().__init__(
|
|
85
|
+
super().__init__(describe(cause))
|
|
65
86
|
self.cause = cause
|
|
66
87
|
|
|
67
88
|
|
|
@@ -130,6 +151,9 @@ _MESSAGE_CLASSIFIERS: list[tuple[ErrorCode, tuple[str, ...]]] = [
|
|
|
130
151
|
ErrorCode.DESTINATION_NOT_FOUND,
|
|
131
152
|
(
|
|
132
153
|
"NoSuchBucket", # S3
|
|
154
|
+
# S3, for a bucket in another region than the connection's
|
|
155
|
+
"PermanentRedirect",
|
|
156
|
+
"incorrectly configured region",
|
|
133
157
|
"ContainerNotFound", # Azure
|
|
134
158
|
"bucket does not exist", # GCS
|
|
135
159
|
"status code: 404",
|
|
@@ -190,7 +214,39 @@ def failure_sentence(code: ErrorCode, where: str) -> str:
|
|
|
190
214
|
return f"The {where} returned an error"
|
|
191
215
|
|
|
192
216
|
|
|
217
|
+
# How obstore's errors for credentials it can't parse begin. S3's keys are only
|
|
218
|
+
# checked by a request.
|
|
219
|
+
_CREDENTIAL_PARSE_ERRORS = (
|
|
220
|
+
"Generic MicrosoftAzure error: Missing component in SAS query pair",
|
|
221
|
+
"Generic MicrosoftAzure error: Failed parsing an SAS key",
|
|
222
|
+
"Generic GCS error: GCP credential error:",
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# A value serde rejects, echoed in quotes or backticks with Rust's escaping,
|
|
226
|
+
# which the redactor's variants don't always match. Backticked identifiers are
|
|
227
|
+
# field names and stay.
|
|
228
|
+
_ECHOED_VALUE = re.compile(r'"(?:[^"\\]|\\.)*"|`(?![A-Za-z_][A-Za-z0-9_]*`)[^`]*`')
|
|
229
|
+
|
|
230
|
+
|
|
193
231
|
def build_store(connection: BucketConnection, credentials: BucketCredentials) -> Any:
|
|
232
|
+
"""obstore parses the credentials here, so a malformed GCS key or Azure SAS
|
|
233
|
+
token fails before any request, as does an address no URL can hold, such as
|
|
234
|
+
an Azure account name with a space."""
|
|
235
|
+
try:
|
|
236
|
+
return _store(connection, credentials)
|
|
237
|
+
except obstore.exceptions.BaseError as error:
|
|
238
|
+
message = describe(error)
|
|
239
|
+
if message.startswith(_CREDENTIAL_PARSE_ERRORS):
|
|
240
|
+
without_values = _ECHOED_VALUE.sub(lambda value: f"{value[0][0]}{MASK}{value[0][-1]}", message)
|
|
241
|
+
raise ExportConnectorError(
|
|
242
|
+
ErrorCode.INVALID_CREDENTIALS, f"The credentials couldn't be read: {without_values}"
|
|
243
|
+
) from error
|
|
244
|
+
raise ExportConnectorError(
|
|
245
|
+
ErrorCode.UNREACHABLE, f"{failure_sentence(ErrorCode.UNREACHABLE, location(connection.root))}: {message}"
|
|
246
|
+
) from error
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _store(connection: BucketConnection, credentials: BucketCredentials) -> Any:
|
|
194
250
|
"""ddc pins the provider pairing, so a mismatch here is a bug."""
|
|
195
251
|
match (connection.root, credentials.root):
|
|
196
252
|
case (BucketConnection1() as s3, BucketCredentials1() as s3_credentials):
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/errors.py
RENAMED
|
@@ -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."""
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/report.py
RENAMED
|
@@ -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
|
-
|
|
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),
|
|
@@ -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,71 @@ def test_a_failed_input_stops_the_run_and_keeps_what_was_written(tmp_path, monke
|
|
|
171
172
|
)
|
|
172
173
|
|
|
173
174
|
|
|
175
|
+
def _encrypted(data):
|
|
176
|
+
"""Sets the encryption flag in the local and the central header."""
|
|
177
|
+
data = bytearray(data)
|
|
178
|
+
for signature, flags_offset in ((b"PK\x03\x04", 6), (b"PK\x01\x02", 8)):
|
|
179
|
+
data[data.index(signature) + flags_offset] |= 0x1
|
|
180
|
+
return bytes(data)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@pytest.mark.parametrize(
|
|
184
|
+
("entries", "corrupt", "reason"),
|
|
185
|
+
[
|
|
186
|
+
({"a.csv": b"hello world"}, lambda data: data.replace(b"hello world", b"hellO world"), "Bad CRC-32 for file 'a.csv'"),
|
|
187
|
+
({"a.csv": b"hello world"}, lambda data: data.replace(b"PK\x03\x04", b"PK\x00\x00", 1), "Bad magic number for file header"),
|
|
188
|
+
({"a.csv": b"hello world"}, _encrypted, "its ZIP entry 'a.csv' is encrypted"),
|
|
189
|
+
# Over 8 MiB, so the entry is read inside obstore's multipart upload.
|
|
190
|
+
({"big.csv": b"x" * 8 * 1024 * 1024 + b"y"}, lambda data: data.replace(b"xy", b"xz"), "Bad CRC-32 for file 'big.csv'"),
|
|
191
|
+
],
|
|
192
|
+
)
|
|
193
|
+
def test_a_corrupt_stored_zip_is_unreadable(tmp_path, monkeypatch, entries, corrupt, reason):
|
|
194
|
+
store = MemoryStore()
|
|
195
|
+
config = _config(EXPORT, [("segA", "seg_a")])
|
|
196
|
+
_run(tmp_path, config, {"segA": corrupt(_zip(entries))}, store, monkeypatch)
|
|
197
|
+
assert (_objects(store), _report(tmp_path)) == (
|
|
198
|
+
{},
|
|
199
|
+
{
|
|
200
|
+
"version": "V0",
|
|
201
|
+
"error": {"code": "READ_FAILED", "message": f"The dataset for 'seg_a/' couldn't be read: {reason}"},
|
|
202
|
+
"warnings": [],
|
|
203
|
+
"receipt": _receipt([("segA", "seg_a", 0, 0)]),
|
|
204
|
+
},
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def test_an_entry_cut_short_is_unreadable(tmp_path, monkeypatch):
|
|
209
|
+
# zipfile raises a bare EOFError for an entry that ends before its size.
|
|
210
|
+
# The tests' Python checks for overlapped entries and raises BadZipFile
|
|
211
|
+
# first, so the read is replaced.
|
|
212
|
+
def cut_short(*_):
|
|
213
|
+
raise EOFError
|
|
214
|
+
|
|
215
|
+
monkeypatch.setattr(export, "upload", cut_short)
|
|
216
|
+
_run(tmp_path, _config(EXPORT, [("segA", "seg_a")]), {"segA": _zip({"a.csv": b"x"})}, MemoryStore(), monkeypatch)
|
|
217
|
+
assert _report(tmp_path)["error"] == {
|
|
218
|
+
"code": "READ_FAILED",
|
|
219
|
+
"message": "The dataset for 'seg_a/' couldn't be read: EOFError",
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_a_long_message_is_cut_after_its_credentials_are_masked(tmp_path, monkeypatch):
|
|
224
|
+
prefix = (
|
|
225
|
+
"The bucket 'acme' in eu-central-1 returned an error, so writing 'decentriq/seg_a/data' failed after 0 of 1"
|
|
226
|
+
" files for 'seg_a/': "
|
|
227
|
+
)
|
|
228
|
+
# The secret straddles the cut, so cutting first would leave its start unmasked.
|
|
229
|
+
padding = "x" * (MAX_MESSAGE_LENGTH - len(prefix) - 10)
|
|
230
|
+
|
|
231
|
+
def failing(*_):
|
|
232
|
+
raise StorageError(RuntimeError(padding + SECRET_KEY + "y" * 2000))
|
|
233
|
+
|
|
234
|
+
monkeypatch.setattr(export, "upload", failing)
|
|
235
|
+
_run(tmp_path, _config(EXPORT, [("segA", "seg_a")]), {"segA": b"x"}, MemoryStore(), monkeypatch)
|
|
236
|
+
expected = (prefix + padding + "***" + "y" * 2000)[: MAX_MESSAGE_LENGTH - 1] + "…"
|
|
237
|
+
assert _report(tmp_path)["error"] == {"code": "UNKNOWN", "message": expected}
|
|
238
|
+
|
|
239
|
+
|
|
174
240
|
def test_a_storage_error_is_reported_with_its_code(tmp_path, monkeypatch):
|
|
175
241
|
read_only = tmp_path / "bucket"
|
|
176
242
|
read_only.mkdir(mode=0o500)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import socket
|
|
3
|
+
from datetime import timedelta
|
|
4
|
+
|
|
5
|
+
import obstore
|
|
6
|
+
import obstore.exceptions
|
|
7
|
+
from obstore.store import S3Store
|
|
8
|
+
|
|
9
|
+
from dq_export_connector._models.export_connector_credentials import BucketCredentials
|
|
10
|
+
from dq_export_connector._models.export_worker_config import BucketConnection
|
|
11
|
+
from dq_export_connector.bucket.store import build_store, classify_error, describe
|
|
12
|
+
from dq_export_connector.errors import ErrorCode, ExportConnectorError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _build_error(connection, credentials):
|
|
16
|
+
try:
|
|
17
|
+
build_store(BucketConnection.model_validate(connection), BucketCredentials.model_validate(credentials))
|
|
18
|
+
except ExportConnectorError as error:
|
|
19
|
+
return error.code, error.message
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_malformed_credentials_are_invalid_before_any_request():
|
|
24
|
+
gcs = {"type": "gcs", "bucket": "b", "pathPrefix": None}
|
|
25
|
+
azure = {"type": "azureBlob", "accountName": "a", "container": "c", "pathPrefix": None}
|
|
26
|
+
decode_error = (
|
|
27
|
+
"The credentials couldn't be read: Generic GCS error: GCP credential error: Unable to decode service account"
|
|
28
|
+
" file: "
|
|
29
|
+
)
|
|
30
|
+
assert [
|
|
31
|
+
_build_error(gcs, {"gcs": {"serviceAccountJson": "not json"}}),
|
|
32
|
+
_build_error(gcs, {"gcs": {"serviceAccountJson": json.dumps({"private_key": 5})}}),
|
|
33
|
+
_build_error(gcs, {"gcs": {"serviceAccountJson": json.dumps({"client_email": "a@b"})}}),
|
|
34
|
+
_build_error(azure, {"azureBlob": {"sasToken": "garbage"}}),
|
|
35
|
+
] == [
|
|
36
|
+
(ErrorCode.INVALID_CREDENTIALS, decode_error + "expected ident at line 1 column 2"),
|
|
37
|
+
(ErrorCode.INVALID_CREDENTIALS, decode_error + "invalid type: integer `***`, expected a string at line 1 column 17"),
|
|
38
|
+
(ErrorCode.INVALID_CREDENTIALS, decode_error + "missing field `private_key` at line 1 column 23"),
|
|
39
|
+
(
|
|
40
|
+
ErrorCode.INVALID_CREDENTIALS,
|
|
41
|
+
"The credentials couldn't be read: Generic MicrosoftAzure error: Missing component in SAS query pair",
|
|
42
|
+
),
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_a_rejected_credential_is_masked_however_rust_escapes_it():
|
|
47
|
+
gcs = {"type": "gcs", "bucket": "b", "pathPrefix": None}
|
|
48
|
+
# serde quotes a rejected string as Rust's Debug does, with \u{1} for the
|
|
49
|
+
# control character, which neither of the redactor's variants matches.
|
|
50
|
+
assert _build_error(gcs, {"gcs": {"serviceAccountJson": json.dumps("SECRET\u0001KEY")}}) == (
|
|
51
|
+
ErrorCode.INVALID_CREDENTIALS,
|
|
52
|
+
"The credentials couldn't be read: Generic GCS error: GCP credential error: Unable to decode service account"
|
|
53
|
+
' file: invalid type: string "***", expected struct ServiceAccountCredentials at line 1 column 17',
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_an_address_no_url_can_hold_is_unreachable():
|
|
58
|
+
azure = {"type": "azureBlob", "accountName": "my account", "container": "c", "pathPrefix": None}
|
|
59
|
+
assert _build_error(azure, {"azureBlob": {"sasToken": "sv=1&sig=2"}}) == (
|
|
60
|
+
ErrorCode.UNREACHABLE,
|
|
61
|
+
"The container 'c' of account 'my account' couldn't be reached: Generic MicrosoftAzure error: Unable parse"
|
|
62
|
+
" source url. Url: https://my account.blob.core.windows.net, Error: invalid international domain name",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _put_error(port, **client_options):
|
|
67
|
+
store = S3Store(
|
|
68
|
+
bucket="b",
|
|
69
|
+
region="eu-west-1",
|
|
70
|
+
access_key_id="a",
|
|
71
|
+
secret_access_key="s",
|
|
72
|
+
endpoint=f"http://127.0.0.1:{port}",
|
|
73
|
+
retry_config={"max_retries": 0},
|
|
74
|
+
client_options={"allow_http": True, **client_options},
|
|
75
|
+
)
|
|
76
|
+
try:
|
|
77
|
+
obstore.put(store, "k", b"x")
|
|
78
|
+
except obstore.exceptions.BaseError as error:
|
|
79
|
+
# Leaves out the request's URL and duration.
|
|
80
|
+
return describe(error).split(" - ", 1)[1]
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_a_request_that_couldnt_be_sent_keeps_its_cause():
|
|
85
|
+
with socket.socket() as closed:
|
|
86
|
+
closed.bind(("127.0.0.1", 0))
|
|
87
|
+
closed_port = closed.getsockname()[1]
|
|
88
|
+
# The kernel completes connections to a listening socket that never
|
|
89
|
+
# accepts them, so the request gets no response.
|
|
90
|
+
with socket.socket() as silent:
|
|
91
|
+
silent.bind(("127.0.0.1", 0))
|
|
92
|
+
silent.listen()
|
|
93
|
+
errors = [_put_error(closed_port), _put_error(silent.getsockname()[1], read_timeout=timedelta(milliseconds=200))]
|
|
94
|
+
assert errors == [
|
|
95
|
+
"HTTP error: error sending request: tcp connect error: Connection refused",
|
|
96
|
+
"HTTP error: error sending request: timed out",
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_obstores_debug_dump_is_left_out():
|
|
101
|
+
error = obstore.exceptions.GenericError("Generic S3 error: failed\n\nDebug source:\nGeneric {\n store: \"S3\",\n}")
|
|
102
|
+
assert describe(error) == "Generic S3 error: failed"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_a_bucket_in_another_region_is_not_found_there():
|
|
106
|
+
error = obstore.exceptions.GenericError(
|
|
107
|
+
"Generic S3 error: Error performing PUT https://s3.us-east-1.amazonaws.com/b/k in 482ms - Received redirect"
|
|
108
|
+
" without LOCATION, this normally indicates an incorrectly configured region"
|
|
109
|
+
)
|
|
110
|
+
assert classify_error(error) == ErrorCode.DESTINATION_NOT_FOUND
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/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
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/log.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/redact.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/dq_export_connector/runner.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/scripts/codegen-models.sh
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_live_buckets.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev8 → dq_export_connector-0.1.0.dev10}/tests/test_models_are_current.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|