dq-export-connector 0.1.0.dev1__tar.gz → 0.1.0.dev4__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.dev4/.python-version +1 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/PKG-INFO +2 -2
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/export.py +8 -5
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/store.py +49 -6
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/upload.py +7 -2
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/validate.py +12 -7
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/pyproject.toml +6 -3
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/scripts/codegen-models.sh +4 -2
- dq_export_connector-0.1.0.dev4/uv.lock +617 -0
- dq_export_connector-0.1.0.dev1/uv.lock +0 -1189
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/.gitignore +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/README.md +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/_models/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/_models/bucket_validation_result.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/_models/export_connector_credentials.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/_models/export_receipt.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/_models/export_worker_config.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/datasets.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/bucket/paths.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/log.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/redact.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/dq_export_connector/runner.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_live_buckets.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_models_are_current.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_paths.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_redact.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_runner.py +0 -0
- {dq_export_connector-0.1.0.dev1 → dq_export_connector-0.1.0.dev4}/tests/test_upload.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.10
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dq-export-connector
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev4
|
|
4
4
|
Summary: Worker logic for the Export Connector DCR.
|
|
5
5
|
Author: Decentriq
|
|
6
6
|
Requires-Python: >=3.10
|
|
7
7
|
Requires-Dist: obstore<0.12,>=0.11.1
|
|
8
|
-
Requires-Dist: pydantic<
|
|
8
|
+
Requires-Dist: pydantic<2.8,>=2.7
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
10
|
|
|
11
11
|
# dq-export-connector
|
|
@@ -10,8 +10,6 @@ from datetime import datetime
|
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
|
-
import obstore.exceptions
|
|
14
|
-
|
|
15
13
|
from dq_export_connector._models.export_connector_credentials import BucketCredentials
|
|
16
14
|
from dq_export_connector._models.export_receipt import (
|
|
17
15
|
BucketInputReceipt,
|
|
@@ -25,7 +23,12 @@ from dq_export_connector._models.export_receipt import (
|
|
|
25
23
|
from dq_export_connector._models.export_worker_config import BucketInput, ExportConnectorKind1, ProvisionedPolicy
|
|
26
24
|
from dq_export_connector.bucket.datasets import open_dataset
|
|
27
25
|
from dq_export_connector.bucket.paths import InvalidPathError, check_dataset_path, check_key, fill_date_tokens, join_key
|
|
28
|
-
from dq_export_connector.bucket.store import
|
|
26
|
+
from dq_export_connector.bucket.store import (
|
|
27
|
+
INVALID_CREDENTIALS,
|
|
28
|
+
InvalidCredentialsError,
|
|
29
|
+
StorageError,
|
|
30
|
+
classify_error,
|
|
31
|
+
)
|
|
29
32
|
from dq_export_connector.bucket.upload import plan_upload, upload
|
|
30
33
|
from dq_export_connector.log import logger
|
|
31
34
|
from dq_export_connector.redact import Redactor
|
|
@@ -123,8 +126,8 @@ def _export_input(
|
|
|
123
126
|
exported.append(ExportedFile(path=key, bytes=file.size, rows=None))
|
|
124
127
|
except InvalidPathError as error:
|
|
125
128
|
return _input_failed(leaf_id, exported, warnings, INVALID_PATH, str(error), started, redactor)
|
|
126
|
-
except
|
|
127
|
-
return _input_failed(leaf_id, exported, warnings, classify_error(error), str(error), started, redactor)
|
|
129
|
+
except StorageError as error:
|
|
130
|
+
return _input_failed(leaf_id, exported, warnings, classify_error(error.cause), str(error), started, redactor)
|
|
128
131
|
except OSError as error:
|
|
129
132
|
message = f"Reading the dataset failed: {error}"
|
|
130
133
|
return _input_failed(leaf_id, exported, warnings, READ_FAILED, message, started, redactor)
|
|
@@ -3,8 +3,9 @@ failures map to."""
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
+
from collections.abc import Callable
|
|
6
7
|
from datetime import timedelta
|
|
7
|
-
from typing import TYPE_CHECKING, Any
|
|
8
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
8
9
|
|
|
9
10
|
import obstore.exceptions
|
|
10
11
|
from obstore.store import AzureStore, GCSStore, S3Store
|
|
@@ -59,16 +60,56 @@ UNREACHABLE = "UNREACHABLE"
|
|
|
59
60
|
UNKNOWN = "UNKNOWN"
|
|
60
61
|
|
|
61
62
|
|
|
63
|
+
T = TypeVar("T")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class StorageError(Exception):
|
|
67
|
+
"""A request to the Bucket Provider failed; `cause` is obstore's error."""
|
|
68
|
+
|
|
69
|
+
def __init__(self, cause: Exception) -> None:
|
|
70
|
+
super().__init__(str(cause))
|
|
71
|
+
self.cause = cause
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# obstore raises its own exceptions, except for a missing object or bucket
|
|
75
|
+
# (the built-in FileNotFoundError) and an unsupported operation
|
|
76
|
+
# (NotImplementedError).
|
|
77
|
+
_OBSTORE_ERRORS = (obstore.exceptions.BaseError, FileNotFoundError, NotImplementedError)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def storage_call(call: Callable[[], T]) -> T:
|
|
81
|
+
"""Runs a request to the Bucket Provider, so its failures can't be
|
|
82
|
+
mistaken for failing to read a dataset."""
|
|
83
|
+
try:
|
|
84
|
+
return call()
|
|
85
|
+
except _OBSTORE_ERRORS as error:
|
|
86
|
+
raise StorageError(error) from error
|
|
87
|
+
|
|
88
|
+
|
|
62
89
|
class InvalidCredentialsError(ValueError):
|
|
63
90
|
"""Credentials that can't be used as given, such as an empty Azure SAS token
|
|
64
91
|
or a SAS URL pasted where the token belongs."""
|
|
65
92
|
|
|
66
93
|
|
|
94
|
+
# Provider error codes that mean bad credentials. They are checked before the
|
|
95
|
+
# error's type: S3's SignatureDoesNotMatch and InvalidAccessKeyId arrive as a
|
|
96
|
+
# 403, which object_store raises as permission denied.
|
|
97
|
+
_CREDENTIAL_CODES: tuple[str, ...] = (
|
|
98
|
+
# S3
|
|
99
|
+
"SignatureDoesNotMatch",
|
|
100
|
+
"InvalidAccessKeyId",
|
|
101
|
+
"InvalidSecurityToken",
|
|
102
|
+
"ExpiredToken",
|
|
103
|
+
# Azure
|
|
104
|
+
"AuthenticationFailed",
|
|
105
|
+
# GCS
|
|
106
|
+
"invalid_grant",
|
|
107
|
+
"Invalid JWT",
|
|
108
|
+
)
|
|
109
|
+
|
|
67
110
|
# Provider error codes recognised in an error's message, checked in order.
|
|
68
111
|
# object_store wraps many non-2xx responses in a generic error, so the
|
|
69
|
-
# provider's code in the message is often the only signal.
|
|
70
|
-
# codes come before the bare-403 fallback: S3's SignatureDoesNotMatch arrives as
|
|
71
|
-
# a 403 but means bad keys.
|
|
112
|
+
# provider's code in the message is often the only signal.
|
|
72
113
|
_MESSAGE_CLASSIFIERS: list[tuple[str, tuple[str, ...]]] = [
|
|
73
114
|
(
|
|
74
115
|
UNAUTHENTICATED,
|
|
@@ -120,15 +161,17 @@ _MESSAGE_CLASSIFIERS: list[tuple[str, tuple[str, ...]]] = [
|
|
|
120
161
|
|
|
121
162
|
def classify_error(error: Exception) -> str:
|
|
122
163
|
"""Maps a storage error to a code, the same for every Bucket Provider."""
|
|
164
|
+
message = str(error)
|
|
123
165
|
if isinstance(error, InvalidCredentialsError):
|
|
124
166
|
return INVALID_CREDENTIALS
|
|
167
|
+
if any(code in message for code in _CREDENTIAL_CODES):
|
|
168
|
+
return UNAUTHENTICATED
|
|
125
169
|
if isinstance(error, obstore.exceptions.UnauthenticatedError):
|
|
126
170
|
return UNAUTHENTICATED
|
|
127
171
|
if isinstance(error, obstore.exceptions.PermissionDeniedError):
|
|
128
172
|
return ACCESS_DENIED
|
|
129
|
-
if isinstance(error,
|
|
173
|
+
if isinstance(error, FileNotFoundError):
|
|
130
174
|
return NOT_FOUND
|
|
131
|
-
message = str(error)
|
|
132
175
|
for code, needles in _MESSAGE_CLASSIFIERS:
|
|
133
176
|
if any(needle in message for needle in needles):
|
|
134
177
|
return code
|
|
@@ -14,6 +14,8 @@ from typing import Any, BinaryIO
|
|
|
14
14
|
|
|
15
15
|
import obstore
|
|
16
16
|
|
|
17
|
+
from dq_export_connector.bucket.store import storage_call
|
|
18
|
+
|
|
17
19
|
MIB = 1024 * 1024
|
|
18
20
|
MIN_PART_SIZE = 8 * MIB
|
|
19
21
|
MAX_PARTS = 10_000
|
|
@@ -36,9 +38,12 @@ def plan_upload(size: int) -> UploadPlan:
|
|
|
36
38
|
def upload(store: Any, key: str, source: BinaryIO, plan: UploadPlan) -> None:
|
|
37
39
|
if plan.multipart:
|
|
38
40
|
chunks = _chunks(source, plan.part_size)
|
|
39
|
-
|
|
41
|
+
storage_call(
|
|
42
|
+
lambda: obstore.put(store, key, chunks, chunk_size=plan.part_size, max_concurrency=MAX_CONCURRENCY)
|
|
43
|
+
)
|
|
40
44
|
else:
|
|
41
|
-
|
|
45
|
+
content = source.read()
|
|
46
|
+
storage_call(lambda: obstore.put(store, key, content, use_multipart=False))
|
|
42
47
|
|
|
43
48
|
|
|
44
49
|
def _chunks(source: BinaryIO, size: int) -> Iterator[bytes]:
|
|
@@ -9,7 +9,6 @@ from collections.abc import Callable
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
import obstore
|
|
12
|
-
import obstore.exceptions
|
|
13
12
|
|
|
14
13
|
from dq_export_connector._models.bucket_validation_result import (
|
|
15
14
|
BucketValidationResult,
|
|
@@ -21,7 +20,13 @@ from dq_export_connector._models.bucket_validation_result import (
|
|
|
21
20
|
from dq_export_connector._models.export_connector_credentials import BucketCredentials
|
|
22
21
|
from dq_export_connector._models.export_worker_config import BucketConnection
|
|
23
22
|
from dq_export_connector.bucket.paths import join_key
|
|
24
|
-
from dq_export_connector.bucket.store import
|
|
23
|
+
from dq_export_connector.bucket.store import (
|
|
24
|
+
INVALID_CREDENTIALS,
|
|
25
|
+
InvalidCredentialsError,
|
|
26
|
+
StorageError,
|
|
27
|
+
classify_error,
|
|
28
|
+
storage_call,
|
|
29
|
+
)
|
|
25
30
|
from dq_export_connector.log import logger
|
|
26
31
|
from dq_export_connector.redact import Redactor
|
|
27
32
|
|
|
@@ -48,16 +53,16 @@ def validate_connection(
|
|
|
48
53
|
|
|
49
54
|
key = probe_key(connection.root.path_prefix)
|
|
50
55
|
try:
|
|
51
|
-
obstore.put(store, key, PROBE_CONTENT)
|
|
52
|
-
except
|
|
53
|
-
code = classify_error(error)
|
|
56
|
+
storage_call(lambda: obstore.put(store, key, PROBE_CONTENT))
|
|
57
|
+
except StorageError as error:
|
|
58
|
+
code = classify_error(error.cause)
|
|
54
59
|
logger.error("Writing the probe %r failed with %s: %s", key, code, error)
|
|
55
60
|
return _error(code, f"Writing the connection test object {key} failed: {error}", redactor)
|
|
56
61
|
logger.info("Wrote the probe %r", key)
|
|
57
62
|
|
|
58
63
|
try:
|
|
59
|
-
obstore.delete(store, key)
|
|
60
|
-
except
|
|
64
|
+
storage_call(lambda: obstore.delete(store, key))
|
|
65
|
+
except StorageError as error:
|
|
61
66
|
logger.warning("Deleting the probe %r failed: %s", key, error)
|
|
62
67
|
message = f"The connection test object {key} was written but couldn't be deleted: {error}"
|
|
63
68
|
warning = ExportMessage(code=PROBE_NOT_DELETED, message=redactor.redact(message))
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dq-export-connector"
|
|
3
|
-
version = "0.1.0.
|
|
3
|
+
version = "0.1.0.dev4"
|
|
4
4
|
description = "Worker logic for the Export Connector DCR."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Decentriq" }]
|
|
7
7
|
requires-python = ">=3.10"
|
|
8
|
+
# The task's Python environment puts the worker image's site-packages ahead of
|
|
9
|
+
# its own, so a package the image ships, such as typing_extensions, shadows the
|
|
10
|
+
# locked one. pydantic stays at the version dq_validation runs in that image;
|
|
11
|
+
# newer ones need a newer typing_extensions.
|
|
8
12
|
dependencies = [
|
|
9
13
|
"obstore>=0.11.1,<0.12",
|
|
10
|
-
"pydantic>=2.7,<
|
|
14
|
+
"pydantic>=2.7,<2.8",
|
|
11
15
|
]
|
|
12
16
|
|
|
13
17
|
[dependency-groups]
|
|
14
18
|
dev = [
|
|
15
|
-
"datamodel-code-generator[black,isort]==0.91.0",
|
|
16
19
|
"mypy>=1.13",
|
|
17
20
|
"pytest>=8.3",
|
|
18
21
|
]
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Generates dq_export_connector/_models from the JSON schemas ddc writes when
|
|
3
|
-
# decentriq_dcr_compiler builds. Takes an optional output directory.
|
|
3
|
+
# decentriq_dcr_compiler builds. Takes an optional output directory. The
|
|
4
|
+
# generator runs in an environment of its own: it needs a newer pydantic than
|
|
5
|
+
# the worker can depend on.
|
|
4
6
|
set -euo pipefail
|
|
5
7
|
cd "$(dirname "$0")/.."
|
|
6
8
|
schemas=../../dcr-compiler/decentriq_dcr_compiler/schemas
|
|
7
9
|
out=${1:-dq_export_connector/_models}
|
|
8
10
|
mkdir -p "$out"
|
|
9
11
|
for name in export_worker_config export_connector_credentials export_receipt bucket_validation_result; do
|
|
10
|
-
|
|
12
|
+
uvx --from "datamodel-code-generator[black,isort]==0.91.0" datamodel-codegen \
|
|
11
13
|
--input "$schemas/$name.json" \
|
|
12
14
|
--input-file-type jsonschema \
|
|
13
15
|
--output-model-type pydantic_v2.BaseModel \
|