dq-export-connector 0.1.0.dev28__tar.gz → 0.1.0.dev29__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.dev28 → dq_export_connector-0.1.0.dev29}/PKG-INFO +6 -5
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/README.md +5 -4
- dq_export_connector-0.1.0.dev29/dq_export_connector/_models/destination_account_listing.py +48 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_worker_config.py +50 -56
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/http.py +1 -1
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/errors.py +11 -1
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/__init__.py +4 -4
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/oauth.py +12 -6
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/outcome.py +20 -1
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/runner.py +33 -42
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/accounts.py +4 -4
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/client.py +2 -2
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/session.py +2 -2
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/pyproject.toml +1 -1
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/scripts/codegen-models.sh +1 -1
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_http_and_oauth.py +3 -3
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_oauth.py +14 -6
- dq_export_connector-0.1.0.dev29/tests/test_outcome.py +23 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_runner.py +0 -18
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_snap_runner.py +15 -7
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/uv.lock +1 -1
- dq_export_connector-0.1.0.dev28/dq_export_connector/_models/destination_accounts.py +0 -25
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/.gitignore +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/.python-version +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/application_message.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/bucket_validation_result.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_connector_credentials.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_receipt.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/snap_validation_result.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/classify.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/identifiers.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/inputs.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/sync.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/export.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/paths.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/store.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/upload.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/validate.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/datasets.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/log.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/bucket.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/snap.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/redact.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/destination.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/export.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/validate.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/scripts/_local.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/scripts/run_local.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/conftest.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/fakes/__init__.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/fakes/snap_fake.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_identifiers_and_inputs.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_live_buckets.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_live_snap.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_models_are_current.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_paths.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_redact.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_scripts.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_store.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_sync_input.py +0 -0
- {dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/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.dev29
|
|
4
4
|
Summary: Worker logic for the Export Connector DCR.
|
|
5
5
|
Author: Decentriq
|
|
6
6
|
Requires-Python: >=3.12
|
|
@@ -67,14 +67,15 @@ uv run mypy dq_export_connector tests scripts
|
|
|
67
67
|
|
|
68
68
|
## Snap
|
|
69
69
|
|
|
70
|
-
A Snap connector's config names the ad account (set after consent, from
|
|
71
|
-
`
|
|
70
|
+
A Snap connector's config names the ad account (set after consent, from a
|
|
71
|
+
`ValidateConnection` in `list` mode) and, per Input, a Segment, the identifier type its
|
|
72
72
|
lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
|
|
73
73
|
Grant of the Snap user who consented; each run turns it into an Access Token
|
|
74
74
|
with `dq_export_connector.oauth`. Decentriq's Snap app is the
|
|
75
75
|
`export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
|
|
76
|
-
mounted at `/input/oauth_app.json`. `
|
|
77
|
-
accounts of every organization the grant reaches
|
|
76
|
+
mounted at `/input/oauth_app.json`. `ValidateConnection` in `list` mode lists
|
|
77
|
+
the ad accounts of every organization the grant reaches; in `check` mode it
|
|
78
|
+
reads the picked one.
|
|
78
79
|
|
|
79
80
|
A run looks each Segment up by name in the ad account and creates it when
|
|
80
81
|
there is none, marked `Managed by Decentriq`. It writes into a same-named
|
|
@@ -54,14 +54,15 @@ uv run mypy dq_export_connector tests scripts
|
|
|
54
54
|
|
|
55
55
|
## Snap
|
|
56
56
|
|
|
57
|
-
A Snap connector's config names the ad account (set after consent, from
|
|
58
|
-
`
|
|
57
|
+
A Snap connector's config names the ad account (set after consent, from a
|
|
58
|
+
`ValidateConnection` in `list` mode) and, per Input, a Segment, the identifier type its
|
|
59
59
|
lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
|
|
60
60
|
Grant of the Snap user who consented; each run turns it into an Access Token
|
|
61
61
|
with `dq_export_connector.oauth`. Decentriq's Snap app is the
|
|
62
62
|
`export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
|
|
63
|
-
mounted at `/input/oauth_app.json`. `
|
|
64
|
-
accounts of every organization the grant reaches
|
|
63
|
+
mounted at `/input/oauth_app.json`. `ValidateConnection` in `list` mode lists
|
|
64
|
+
the ad accounts of every organization the grant reaches; in `check` mode it
|
|
65
|
+
reads the picked one.
|
|
65
66
|
|
|
66
67
|
A run looks each Segment up by name in the ad account and creates it when
|
|
67
68
|
there is none, marked `Managed by Decentriq`. It writes into a same-named
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# generated by datamodel-codegen:
|
|
2
|
+
# filename: destination_account_listing.json
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Annotated, Any
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ApplicationMessage(BaseModel):
|
|
12
|
+
model_config = ConfigDict(
|
|
13
|
+
populate_by_name=True,
|
|
14
|
+
)
|
|
15
|
+
code: Annotated[
|
|
16
|
+
str,
|
|
17
|
+
Field(
|
|
18
|
+
description='SCREAMING_SNAKE_CASE, such as `ACCESS_DENIED`. A string rather than an\nenum, so a worker release can add codes that readers built against an\nolder ddc still accept.'
|
|
19
|
+
),
|
|
20
|
+
]
|
|
21
|
+
details: Annotated[
|
|
22
|
+
dict[str, Any] | None, Field(description='Shaped by the `code`.')
|
|
23
|
+
] = None
|
|
24
|
+
message: Annotated[
|
|
25
|
+
str,
|
|
26
|
+
Field(
|
|
27
|
+
description='Safe to show to the user: no credentials and no dataset values.'
|
|
28
|
+
),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DestinationAccount(BaseModel):
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
populate_by_name=True,
|
|
35
|
+
)
|
|
36
|
+
id: str
|
|
37
|
+
name: str
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class DestinationAccountListing(BaseModel):
|
|
41
|
+
model_config = ConfigDict(
|
|
42
|
+
populate_by_name=True,
|
|
43
|
+
)
|
|
44
|
+
destination_accounts: Annotated[
|
|
45
|
+
list[DestinationAccount], Field(alias='destinationAccounts')
|
|
46
|
+
]
|
|
47
|
+
error: ApplicationMessage | None = None
|
|
48
|
+
warnings: list[ApplicationMessage]
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import Annotated,
|
|
7
|
+
from typing import Annotated, Literal
|
|
8
8
|
|
|
9
9
|
from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel
|
|
10
10
|
|
|
@@ -62,16 +62,6 @@ class ClientAuth(Enum):
|
|
|
62
62
|
http_basic = 'httpBasic'
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
class ExportConnectorDcrComputeActionListDestinationAccounts(BaseModel):
|
|
66
|
-
model_config = ConfigDict(
|
|
67
|
-
extra='forbid',
|
|
68
|
-
populate_by_name=True,
|
|
69
|
-
)
|
|
70
|
-
list_destination_accounts: Annotated[
|
|
71
|
-
dict[str, Any], Field(alias='listDestinationAccounts')
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
|
|
75
65
|
class ExportConnectorKindBucket(BaseModel):
|
|
76
66
|
model_config = ConfigDict(
|
|
77
67
|
populate_by_name=True,
|
|
@@ -180,17 +170,9 @@ class ValidateConnectionParamsBucket(BaseModel):
|
|
|
180
170
|
type: Literal['bucket']
|
|
181
171
|
|
|
182
172
|
|
|
183
|
-
class
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
187
|
-
type: Literal['snap']
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
class ValidateConnectionParams(
|
|
191
|
-
RootModel[ValidateConnectionParamsBucket | ValidateConnectionParamsSnap]
|
|
192
|
-
):
|
|
193
|
-
root: ValidateConnectionParamsBucket | ValidateConnectionParamsSnap
|
|
173
|
+
class ValidationMode(Enum):
|
|
174
|
+
check = 'check'
|
|
175
|
+
list = 'list'
|
|
194
176
|
|
|
195
177
|
|
|
196
178
|
class BucketExportConfig(BaseModel):
|
|
@@ -208,23 +190,6 @@ class BucketExportConfig(BaseModel):
|
|
|
208
190
|
inputs: list[BucketInput]
|
|
209
191
|
|
|
210
192
|
|
|
211
|
-
class ValidateConnection(BaseModel):
|
|
212
|
-
model_config = ConfigDict(
|
|
213
|
-
populate_by_name=True,
|
|
214
|
-
)
|
|
215
|
-
params: ValidateConnectionParams
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
class ExportConnectorDcrComputeActionValidateConnection(BaseModel):
|
|
219
|
-
model_config = ConfigDict(
|
|
220
|
-
extra='forbid',
|
|
221
|
-
populate_by_name=True,
|
|
222
|
-
)
|
|
223
|
-
validate_connection: Annotated[
|
|
224
|
-
ValidateConnection, Field(alias='validateConnection')
|
|
225
|
-
]
|
|
226
|
-
|
|
227
|
-
|
|
228
193
|
class Export(BaseModel):
|
|
229
194
|
model_config = ConfigDict(
|
|
230
195
|
populate_by_name=True,
|
|
@@ -240,23 +205,6 @@ class ExportConnectorDcrComputeActionExport(BaseModel):
|
|
|
240
205
|
export: Export
|
|
241
206
|
|
|
242
207
|
|
|
243
|
-
class ExportConnectorDcrComputeAction(
|
|
244
|
-
RootModel[
|
|
245
|
-
ExportConnectorDcrComputeActionValidateConnection
|
|
246
|
-
| ExportConnectorDcrComputeActionExport
|
|
247
|
-
| ExportConnectorDcrComputeActionListDestinationAccounts
|
|
248
|
-
]
|
|
249
|
-
):
|
|
250
|
-
root: Annotated[
|
|
251
|
-
ExportConnectorDcrComputeActionValidateConnection
|
|
252
|
-
| ExportConnectorDcrComputeActionExport
|
|
253
|
-
| ExportConnectorDcrComputeActionListDestinationAccounts,
|
|
254
|
-
Field(
|
|
255
|
-
description='Compute actions for an Export Connector DCR, started through `POST /jobs`.'
|
|
256
|
-
),
|
|
257
|
-
]
|
|
258
|
-
|
|
259
|
-
|
|
260
208
|
class ExportConnectorKindSnap(BaseModel):
|
|
261
209
|
model_config = ConfigDict(
|
|
262
210
|
populate_by_name=True,
|
|
@@ -292,6 +240,52 @@ class SnapExportConfig(BaseModel):
|
|
|
292
240
|
inputs: list[SnapInput]
|
|
293
241
|
|
|
294
242
|
|
|
243
|
+
class ValidateConnectionParamsSnap(BaseModel):
|
|
244
|
+
model_config = ConfigDict(
|
|
245
|
+
populate_by_name=True,
|
|
246
|
+
)
|
|
247
|
+
mode: ValidationMode
|
|
248
|
+
type: Literal['snap']
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class ValidateConnectionParams(
|
|
252
|
+
RootModel[ValidateConnectionParamsBucket | ValidateConnectionParamsSnap]
|
|
253
|
+
):
|
|
254
|
+
root: ValidateConnectionParamsBucket | ValidateConnectionParamsSnap
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
class ValidateConnection(BaseModel):
|
|
258
|
+
model_config = ConfigDict(
|
|
259
|
+
populate_by_name=True,
|
|
260
|
+
)
|
|
261
|
+
params: ValidateConnectionParams
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
class ExportConnectorDcrComputeActionValidateConnection(BaseModel):
|
|
265
|
+
model_config = ConfigDict(
|
|
266
|
+
extra='forbid',
|
|
267
|
+
populate_by_name=True,
|
|
268
|
+
)
|
|
269
|
+
validate_connection: Annotated[
|
|
270
|
+
ValidateConnection, Field(alias='validateConnection')
|
|
271
|
+
]
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
class ExportConnectorDcrComputeAction(
|
|
275
|
+
RootModel[
|
|
276
|
+
ExportConnectorDcrComputeActionValidateConnection
|
|
277
|
+
| ExportConnectorDcrComputeActionExport
|
|
278
|
+
]
|
|
279
|
+
):
|
|
280
|
+
root: Annotated[
|
|
281
|
+
ExportConnectorDcrComputeActionValidateConnection
|
|
282
|
+
| ExportConnectorDcrComputeActionExport,
|
|
283
|
+
Field(
|
|
284
|
+
description='Compute actions for an Export Connector DCR, started through `POST /jobs`.'
|
|
285
|
+
),
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
|
|
295
289
|
class ExportWorkerConfig(BaseModel):
|
|
296
290
|
model_config = ConfigDict(
|
|
297
291
|
populate_by_name=True,
|
|
@@ -31,7 +31,7 @@ class Authenticator(Protocol):
|
|
|
31
31
|
def auth_headers(self) -> dict[str, str]: ...
|
|
32
32
|
|
|
33
33
|
def on_unauthorized(self) -> None:
|
|
34
|
-
"""Refresh after a 401, or raise
|
|
34
|
+
"""Refresh after a 401, or raise if that's impossible."""
|
|
35
35
|
...
|
|
36
36
|
|
|
37
37
|
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/errors.py
RENAMED
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import traceback
|
|
8
8
|
from dataclasses import dataclass
|
|
9
|
+
from datetime import datetime, timezone
|
|
9
10
|
from enum import Enum
|
|
10
11
|
from typing import Generic, TypeVar
|
|
11
12
|
|
|
@@ -20,7 +21,6 @@ class ErrorCode(str, Enum):
|
|
|
20
21
|
UNKNOWN = "UNKNOWN"
|
|
21
22
|
READ_FAILED = "READ_FAILED"
|
|
22
23
|
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
23
|
-
OAUTH_REAUTHORISATION_NEEDED = "OAUTH_REAUTHORISATION_NEEDED"
|
|
24
24
|
OAUTH_APP_CREDENTIALS_REJECTED = "OAUTH_APP_CREDENTIALS_REJECTED"
|
|
25
25
|
BUCKET_INVALID_PATH = "BUCKET_INVALID_PATH"
|
|
26
26
|
RATE_LIMITED = "RATE_LIMITED"
|
|
@@ -81,6 +81,16 @@ class Issue(Generic[Code]):
|
|
|
81
81
|
message: str
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
def check_unexpired(expire_at: datetime | None, now: datetime) -> None:
|
|
85
|
+
"""A provider answers expired credentials like rejected ones, so a run
|
|
86
|
+
checks the expiry before its first request."""
|
|
87
|
+
if expire_at is not None and expire_at <= now:
|
|
88
|
+
raise ExportConnectorError(
|
|
89
|
+
ErrorCode.CREDENTIALS_EXPIRED,
|
|
90
|
+
f"The credentials expired at {expire_at.astimezone(timezone.utc):%Y-%m-%d %H:%M:%S} UTC: replace them",
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
84
94
|
def internal_error_message(error: BaseException, activity: str) -> str:
|
|
85
95
|
"""Names the error's type and where it was raised, but not its message,
|
|
86
96
|
which could hold dataset values."""
|
|
@@ -3,14 +3,13 @@ schemas. The types of every Connector Kind are here, a kind's own types in its
|
|
|
3
3
|
submodule."""
|
|
4
4
|
|
|
5
5
|
from dq_export_connector._models.application_message import ApplicationMessage
|
|
6
|
-
from dq_export_connector._models.
|
|
6
|
+
from dq_export_connector._models.destination_account_listing import DestinationAccount, DestinationAccountListing
|
|
7
7
|
from dq_export_connector._models.export_connector_credentials import ExportConnectorCredentials
|
|
8
8
|
from dq_export_connector._models.export_receipt import ExportReceipt, ExportReceiptV0, ExportTotals
|
|
9
9
|
from dq_export_connector._models.export_worker_config import (
|
|
10
10
|
Export,
|
|
11
11
|
ExportConnectorDcrComputeAction,
|
|
12
12
|
ExportConnectorDcrComputeActionExport,
|
|
13
|
-
ExportConnectorDcrComputeActionListDestinationAccounts,
|
|
14
13
|
ExportConnectorDcrComputeActionValidateConnection,
|
|
15
14
|
ExportConnectorKind,
|
|
16
15
|
ExportParams,
|
|
@@ -19,17 +18,17 @@ from dq_export_connector._models.export_worker_config import (
|
|
|
19
18
|
ProvisionedPolicy,
|
|
20
19
|
ValidateConnection,
|
|
21
20
|
ValidateConnectionParams,
|
|
21
|
+
ValidationMode,
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
__all__ = [
|
|
25
25
|
"ApplicationMessage",
|
|
26
26
|
"DestinationAccount",
|
|
27
|
-
"
|
|
27
|
+
"DestinationAccountListing",
|
|
28
28
|
"Export",
|
|
29
29
|
"ExportConnectorCredentials",
|
|
30
30
|
"ExportConnectorDcrComputeAction",
|
|
31
31
|
"ExportConnectorDcrComputeActionExport",
|
|
32
|
-
"ExportConnectorDcrComputeActionListDestinationAccounts",
|
|
33
32
|
"ExportConnectorDcrComputeActionValidateConnection",
|
|
34
33
|
"ExportConnectorKind",
|
|
35
34
|
"ExportParams",
|
|
@@ -41,4 +40,5 @@ __all__ = [
|
|
|
41
40
|
"ProvisionedPolicy",
|
|
42
41
|
"ValidateConnection",
|
|
43
42
|
"ValidateConnectionParams",
|
|
43
|
+
"ValidationMode",
|
|
44
44
|
]
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/oauth.py
RENAMED
|
@@ -4,7 +4,9 @@ Profile reaches the worker as `config.json`'s `oauth` key, and the OAuth App's
|
|
|
4
4
|
`{clientId, clientSecret}` as the Platform Secret at `/input/oauth_app.json`.
|
|
5
5
|
|
|
6
6
|
A kind whose provider reports a dead grant in its own way passes its own
|
|
7
|
-
classifier and retry policy; the default follows RFC 6749.
|
|
7
|
+
classifier and retry policy; the default follows RFC 6749. A dead grant is
|
|
8
|
+
`UNAUTHENTICATED`, as any rejected credentials are: the owner sets new ones,
|
|
9
|
+
which for OAuth means connecting again.
|
|
8
10
|
"""
|
|
9
11
|
|
|
10
12
|
from __future__ import annotations
|
|
@@ -17,10 +19,11 @@ import urllib.parse
|
|
|
17
19
|
import urllib.request
|
|
18
20
|
from collections.abc import Callable
|
|
19
21
|
from dataclasses import dataclass
|
|
22
|
+
from datetime import datetime, timezone
|
|
20
23
|
from pathlib import Path
|
|
21
24
|
from typing import Any, NamedTuple, TypeVar
|
|
22
25
|
|
|
23
|
-
from dq_export_connector.errors import ErrorCode, ExportConnectorError, WarningCode
|
|
26
|
+
from dq_export_connector.errors import ErrorCode, ExportConnectorError, WarningCode, check_unexpired
|
|
24
27
|
from dq_export_connector.log import logger
|
|
25
28
|
from dq_export_connector.models import OAuthWorkerConfig
|
|
26
29
|
from dq_export_connector.outcome import RunOutcome
|
|
@@ -66,7 +69,7 @@ def classify_refresh_response(status: int, body: dict[str, Any]) -> Verdict:
|
|
|
66
69
|
if 200 <= status < 300:
|
|
67
70
|
return None
|
|
68
71
|
if error == "invalid_grant":
|
|
69
|
-
return ErrorCode.
|
|
72
|
+
return ErrorCode.UNAUTHENTICATED
|
|
70
73
|
if error in ("invalid_client", "unauthorized_client") or status == 401:
|
|
71
74
|
return ErrorCode.OAUTH_APP_CREDENTIALS_REJECTED
|
|
72
75
|
if status >= 500:
|
|
@@ -105,6 +108,7 @@ class AccessTokenProvider:
|
|
|
105
108
|
*,
|
|
106
109
|
classify: Classifier = classify_refresh_response,
|
|
107
110
|
retry: RetryPolicy = RetryPolicy(),
|
|
111
|
+
expires_at: datetime | None = None,
|
|
108
112
|
post: Post = default_post,
|
|
109
113
|
sleep: Callable[[float], None] = time.sleep,
|
|
110
114
|
) -> None:
|
|
@@ -114,6 +118,7 @@ class AccessTokenProvider:
|
|
|
114
118
|
self._outcome = outcome
|
|
115
119
|
self._classify = classify
|
|
116
120
|
self._retry = retry
|
|
121
|
+
self._expires_at = expires_at
|
|
117
122
|
self._post = post
|
|
118
123
|
self._sleep = sleep
|
|
119
124
|
self._token: str | None = None
|
|
@@ -139,15 +144,16 @@ class AccessTokenProvider:
|
|
|
139
144
|
result = do(self.refresh())
|
|
140
145
|
if is_unauthorised(result):
|
|
141
146
|
raise ExportConnectorError(
|
|
142
|
-
ErrorCode.
|
|
147
|
+
ErrorCode.UNAUTHENTICATED,
|
|
143
148
|
"The provider refuses the access the owner granted: connect the Export Connector again",
|
|
144
149
|
)
|
|
145
150
|
return result
|
|
146
151
|
|
|
147
152
|
def _mint(self) -> str:
|
|
153
|
+
check_unexpired(self._expires_at, datetime.now(timezone.utc))
|
|
148
154
|
if self._grant["clientId"] != self._app["clientId"]:
|
|
149
155
|
raise ExportConnectorError(
|
|
150
|
-
ErrorCode.
|
|
156
|
+
ErrorCode.UNAUTHENTICATED,
|
|
151
157
|
"The OAuth App changed since the owner connected: connect the Export Connector again",
|
|
152
158
|
)
|
|
153
159
|
token = self._grant["token"]
|
|
@@ -223,7 +229,7 @@ def _json_object(body: bytes) -> dict[str, Any]:
|
|
|
223
229
|
|
|
224
230
|
def _failure_sentence(code: ErrorCode) -> str:
|
|
225
231
|
return {
|
|
226
|
-
ErrorCode.
|
|
232
|
+
ErrorCode.UNAUTHENTICATED: "The provider no longer honours the owner's consent: connect the Export Connector again",
|
|
227
233
|
ErrorCode.OAUTH_APP_CREDENTIALS_REJECTED: "The provider rejected Decentriq's OAuth App credentials",
|
|
228
234
|
ErrorCode.UNREACHABLE: "The provider's token endpoint couldn't be reached",
|
|
229
235
|
}.get(code, "The provider's token endpoint answered unexpectedly")
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/outcome.py
RENAMED
|
@@ -6,7 +6,13 @@ from __future__ import annotations
|
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
8
|
from dq_export_connector.errors import MAX_MESSAGE_LENGTH, MAX_PROVIDER_ERROR_LENGTH, ErrorCode, WarningCode, truncate
|
|
9
|
-
from dq_export_connector.models import
|
|
9
|
+
from dq_export_connector.models import (
|
|
10
|
+
ApplicationMessage,
|
|
11
|
+
DestinationAccount,
|
|
12
|
+
DestinationAccountListing,
|
|
13
|
+
ExportReceipt,
|
|
14
|
+
ExportReceiptV0,
|
|
15
|
+
)
|
|
10
16
|
from dq_export_connector.models.bucket import BucketValidationResult
|
|
11
17
|
from dq_export_connector.models.snap import SnapValidationResult
|
|
12
18
|
from dq_export_connector.redact import Redactor
|
|
@@ -47,6 +53,19 @@ class RunOutcome:
|
|
|
47
53
|
"warnings": [_application_message(*warning, redactor) for warning in self.warnings],
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
def destination_account_listing(
|
|
57
|
+
self, accounts: list[DestinationAccount], redactor: Redactor
|
|
58
|
+
) -> DestinationAccountListing:
|
|
59
|
+
"""The result of a `ValidateConnection` in `list` mode: the accounts, or
|
|
60
|
+
the error that stopped the listing."""
|
|
61
|
+
return DestinationAccountListing.model_validate(
|
|
62
|
+
{
|
|
63
|
+
"error": None if self.error is None else _application_message(*self.error, redactor),
|
|
64
|
+
"warnings": [_application_message(*warning, redactor) for warning in self.warnings],
|
|
65
|
+
"destinationAccounts": [] if self.error is not None else accounts,
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
50
69
|
|
|
51
70
|
def _application_message(code: ErrorCode | WarningCode, text: str, provider_error: str | None, redactor: Redactor) -> dict[str, Any]:
|
|
52
71
|
# Cut once redacted, so a cut can't leave part of a secret unmasked.
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/runner.py
RENAMED
|
@@ -11,6 +11,7 @@ from __future__ import annotations
|
|
|
11
11
|
import json
|
|
12
12
|
from collections.abc import Callable, Iterator
|
|
13
13
|
from contextlib import contextmanager
|
|
14
|
+
from functools import partial
|
|
14
15
|
from datetime import datetime, timezone
|
|
15
16
|
from importlib.metadata import version
|
|
16
17
|
from pathlib import Path
|
|
@@ -18,20 +19,24 @@ from typing import Any
|
|
|
18
19
|
|
|
19
20
|
from pydantic import BaseModel
|
|
20
21
|
|
|
21
|
-
from dq_export_connector.errors import ErrorCode, ExportConnectorError, internal_error_message
|
|
22
|
+
from dq_export_connector.errors import ErrorCode, ExportConnectorError, check_unexpired, internal_error_message
|
|
22
23
|
from dq_export_connector.log import configure_logger, logger
|
|
23
24
|
from dq_export_connector.models import (
|
|
24
25
|
ApplicationMessage,
|
|
26
|
+
DestinationAccount,
|
|
25
27
|
ExportConnectorCredentials,
|
|
26
|
-
DestinationAccounts,
|
|
27
28
|
ExportConnectorDcrComputeActionExport,
|
|
28
|
-
ExportConnectorDcrComputeActionListDestinationAccounts,
|
|
29
29
|
ExportConnectorDcrComputeActionValidateConnection,
|
|
30
30
|
ExportWorkerConfig,
|
|
31
|
+
ValidationMode,
|
|
31
32
|
)
|
|
32
33
|
from dq_export_connector.oauth import APP_SECRET_PATH
|
|
33
34
|
from dq_export_connector.models.bucket import ExportConnectorCredentialsBucket, ExportConnectorKindBucket
|
|
34
|
-
from dq_export_connector.models.snap import
|
|
35
|
+
from dq_export_connector.models.snap import (
|
|
36
|
+
ExportConnectorCredentialsSnap,
|
|
37
|
+
ExportConnectorKindSnap,
|
|
38
|
+
ValidateConnectionParamsSnap,
|
|
39
|
+
)
|
|
35
40
|
from dq_export_connector.outcome import RunOutcome
|
|
36
41
|
from dq_export_connector.redact import Redactor, secret_values
|
|
37
42
|
|
|
@@ -41,10 +46,6 @@ INPUTS_DIR = Path("/input/inputs")
|
|
|
41
46
|
OUTPUT_DIR = Path("/output")
|
|
42
47
|
INTERNAL_DIR = Path("/internal")
|
|
43
48
|
|
|
44
|
-
# Lists the Destination Accounts a Connector Kind's credentials reach, by the
|
|
45
|
-
# kind's tag. A kind registers its lister here.
|
|
46
|
-
DESTINATION_LISTERS: dict[str, Callable[[ExportWorkerConfig, Any, RunOutcome], DestinationAccounts]] = {}
|
|
47
|
-
|
|
48
49
|
VALIDATION_RESULT_FILE = "result.json"
|
|
49
50
|
REPORT_FILE = "report"
|
|
50
51
|
APPLICATION_WARNINGS_FILE = "application_warnings"
|
|
@@ -123,7 +124,7 @@ def run(
|
|
|
123
124
|
)
|
|
124
125
|
case _:
|
|
125
126
|
raise ValueError("The credentials are for another Connector Kind")
|
|
126
|
-
validate, export, validation_result
|
|
127
|
+
validate, export, validation_result = kind
|
|
127
128
|
match config.action.root:
|
|
128
129
|
case ExportConnectorDcrComputeActionValidateConnection():
|
|
129
130
|
with _record_failure(outcome, "connection test"):
|
|
@@ -134,11 +135,6 @@ def run(
|
|
|
134
135
|
result = validation_result(redactor)
|
|
135
136
|
_write(output_dir / VALIDATION_RESULT_FILE, result.model_dump_json(by_alias=True, exclude_none=True))
|
|
136
137
|
return None
|
|
137
|
-
case ExportConnectorDcrComputeActionListDestinationAccounts():
|
|
138
|
-
with _record_failure(outcome, "listing"):
|
|
139
|
-
accounts = _list_destination_accounts(config, credentials, outcome, list_accounts)
|
|
140
|
-
if outcome.error is None:
|
|
141
|
-
_write(output_dir / VALIDATION_RESULT_FILE, accounts.model_dump_json(by_alias=True))
|
|
142
138
|
case ExportConnectorDcrComputeActionExport():
|
|
143
139
|
with _record_failure(outcome, "export"):
|
|
144
140
|
export()
|
|
@@ -148,13 +144,12 @@ def run(
|
|
|
148
144
|
return _write_application_outputs(internal_dir, outcome, redactor)
|
|
149
145
|
|
|
150
146
|
|
|
151
|
-
# A kind's `ValidateConnection
|
|
152
|
-
#
|
|
147
|
+
# A kind's `ValidateConnection` in the action's mode, its `Export`, and how it
|
|
148
|
+
# shapes the `ValidateConnection` result.
|
|
153
149
|
_KindActions = tuple[
|
|
154
150
|
Callable[[], None],
|
|
155
151
|
Callable[[], None],
|
|
156
152
|
Callable[[Redactor], BaseModel],
|
|
157
|
-
Callable[[], DestinationAccounts] | None,
|
|
158
153
|
]
|
|
159
154
|
|
|
160
155
|
|
|
@@ -179,7 +174,6 @@ def _bucket(
|
|
|
179
174
|
lambda: validate_connection(connector.connection, bucket_credentials, checked_store, outcome),
|
|
180
175
|
lambda: export(connector, config.policies, bucket_credentials, inputs_dir, now, checked_store, outcome),
|
|
181
176
|
outcome.validation_result,
|
|
182
|
-
None,
|
|
183
177
|
)
|
|
184
178
|
|
|
185
179
|
|
|
@@ -205,29 +199,30 @@ def _snap(
|
|
|
205
199
|
transport = transport or Transport()
|
|
206
200
|
grant = credentials.model_dump(by_alias=True)["credentials"]["grant"]
|
|
207
201
|
app = read_app_secret(app_secret_path)
|
|
202
|
+
validate: Callable[[], None]
|
|
203
|
+
validation_result: Callable[[Redactor], BaseModel]
|
|
204
|
+
if _lists_destination_accounts(config):
|
|
205
|
+
accounts: list[DestinationAccount] = []
|
|
206
|
+
validate = lambda: accounts.extend(
|
|
207
|
+
list_destination_accounts(connect_client(grant, profile, app, redactor, transport, outcome))
|
|
208
|
+
)
|
|
209
|
+
validation_result = partial(outcome.destination_account_listing, accounts)
|
|
210
|
+
else:
|
|
211
|
+
validate = lambda: validate_connection(connector, grant, profile, app, redactor, transport, outcome)
|
|
212
|
+
validation_result = outcome.snap_validation_result
|
|
208
213
|
return (
|
|
209
|
-
|
|
210
|
-
lambda: export(
|
|
211
|
-
|
|
212
|
-
),
|
|
213
|
-
outcome.snap_validation_result,
|
|
214
|
-
lambda: list_destination_accounts(connect_client(grant, profile, app, redactor, transport, outcome)),
|
|
214
|
+
validate,
|
|
215
|
+
lambda: export(connector, config.policies, grant, profile, app, inputs_dir, redactor, transport, outcome),
|
|
216
|
+
validation_result,
|
|
215
217
|
)
|
|
216
218
|
|
|
217
219
|
|
|
218
|
-
def
|
|
219
|
-
config
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
)
|
|
224
|
-
"""Names never go into an error, which api-platform reads."""
|
|
225
|
-
if list_accounts is not None:
|
|
226
|
-
return list_accounts()
|
|
227
|
-
lister = DESTINATION_LISTERS.get(config.connector.root.type)
|
|
228
|
-
if lister is None:
|
|
229
|
-
raise ExportConnectorError(ErrorCode.INTERNAL_ERROR, "This Connector Kind has no Destination Account listing")
|
|
230
|
-
return lister(config, credentials, outcome)
|
|
220
|
+
def _lists_destination_accounts(config: ExportWorkerConfig) -> bool:
|
|
221
|
+
action = config.action.root
|
|
222
|
+
if not isinstance(action, ExportConnectorDcrComputeActionValidateConnection):
|
|
223
|
+
return False
|
|
224
|
+
params = action.validate_connection.params.root
|
|
225
|
+
return isinstance(params, ValidateConnectionParamsSnap) and params.mode is ValidationMode.list
|
|
231
226
|
|
|
232
227
|
|
|
233
228
|
def _write_application_outputs(internal_dir: Path, outcome: RunOutcome, redactor: Redactor) -> ApplicationMessage | None:
|
|
@@ -248,11 +243,7 @@ def _with_expiry_check(
|
|
|
248
243
|
the store, which comes before any request, fails on them first."""
|
|
249
244
|
|
|
250
245
|
def build(connection: Any, credentials: Any) -> Any:
|
|
251
|
-
|
|
252
|
-
raise ExportConnectorError(
|
|
253
|
-
ErrorCode.CREDENTIALS_EXPIRED,
|
|
254
|
-
f"The credentials expired at {expire_at.astimezone(timezone.utc):%Y-%m-%d %H:%M:%S} UTC: replace them",
|
|
255
|
-
)
|
|
246
|
+
check_unexpired(expire_at, now)
|
|
256
247
|
return build_store(connection, credentials)
|
|
257
248
|
|
|
258
249
|
return build
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"""The Snap `
|
|
1
|
+
"""The Snap `ValidateConnection` in `list` mode: the ad accounts the grant reaches."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from dq_export_connector.log import logger
|
|
6
|
-
from dq_export_connector.models import DestinationAccount
|
|
6
|
+
from dq_export_connector.models import DestinationAccount
|
|
7
7
|
from dq_export_connector.snap.client import SnapClient
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def list_destination_accounts(client: SnapClient) ->
|
|
10
|
+
def list_destination_accounts(client: SnapClient) -> list[DestinationAccount]:
|
|
11
11
|
"""Ad accounts of every organization, once each in Snap's order."""
|
|
12
12
|
accounts: dict[str, DestinationAccount] = {}
|
|
13
13
|
for ad_account in client.list_ad_accounts():
|
|
@@ -15,4 +15,4 @@ def list_destination_accounts(client: SnapClient) -> DestinationAccounts:
|
|
|
15
15
|
if isinstance(account_id, str) and account_id and account_id not in accounts:
|
|
16
16
|
accounts[account_id] = DestinationAccount(id=account_id, name=name if isinstance(name, str) else account_id)
|
|
17
17
|
logger.info("Listed %d Snap ad accounts", len(accounts))
|
|
18
|
-
return
|
|
18
|
+
return list(accounts.values())
|
|
@@ -73,9 +73,9 @@ class SnapClient:
|
|
|
73
73
|
)
|
|
74
74
|
except ExportConnectorError as e:
|
|
75
75
|
if e.code is ErrorCode.UNAUTHENTICATED:
|
|
76
|
-
#
|
|
76
|
+
# Refused after a refresh, or the refresh found the grant dead.
|
|
77
77
|
raise ExportConnectorError(
|
|
78
|
-
ErrorCode.
|
|
78
|
+
ErrorCode.UNAUTHENTICATED,
|
|
79
79
|
"Snap refuses the access the owner granted: connect the Export Connector again",
|
|
80
80
|
possibly_applied=e.possibly_applied,
|
|
81
81
|
) from None
|
|
@@ -41,9 +41,9 @@ class Transport:
|
|
|
41
41
|
def classify_snap_refresh(status: int, body: dict[str, Any]) -> Verdict:
|
|
42
42
|
"""Snap answers an unknown or dead refresh token with HTTP 500
|
|
43
43
|
`server_error`, the same as an outage: retried first, then taken as a dead
|
|
44
|
-
grant
|
|
44
|
+
grant, which is `UNAUTHENTICATED`. Only a run's first refresh is judged this way."""
|
|
45
45
|
if status >= 500:
|
|
46
|
-
return Retry(exhausted=ErrorCode.
|
|
46
|
+
return Retry(exhausted=ErrorCode.UNAUTHENTICATED)
|
|
47
47
|
return classify_refresh_response(status, body)
|
|
48
48
|
|
|
49
49
|
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/scripts/codegen-models.sh
RENAMED
|
@@ -7,7 +7,7 @@ cd "$(dirname "$0")/.."
|
|
|
7
7
|
schemas=../../dcr-compiler/decentriq_dcr_compiler/schemas
|
|
8
8
|
out=${1:-dq_export_connector/_models}
|
|
9
9
|
mkdir -p "$out"
|
|
10
|
-
for name in export_worker_config export_connector_credentials export_receipt application_message bucket_validation_result
|
|
10
|
+
for name in export_worker_config export_connector_credentials export_receipt application_message bucket_validation_result destination_account_listing snap_validation_result; do
|
|
11
11
|
uvx --from "datamodel-code-generator[black,isort]==0.91.0" datamodel-codegen \
|
|
12
12
|
--input "$schemas/$name.json" \
|
|
13
13
|
--input-file-type jsonschema \
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_http_and_oauth.py
RENAMED
|
@@ -238,7 +238,7 @@ def test_snap_dead_refresh_token_is_retried_then_reauthorisation_needed():
|
|
|
238
238
|
http, auth = make(fake)
|
|
239
239
|
with pytest.raises(ExportConnectorError) as e:
|
|
240
240
|
http.request("GET", URL, endpoint="e", idempotency=Idempotency.REPEATABLE, auth=auth)
|
|
241
|
-
assert e.value.code is ErrorCode.
|
|
241
|
+
assert e.value.code is ErrorCode.UNAUTHENTICATED
|
|
242
242
|
assert "connect the Export Connector again" in e.value.message and "server_error" not in e.value.message
|
|
243
243
|
token_calls = [r for r in fake.requests if "oauth2" in r[1]]
|
|
244
244
|
assert len(token_calls) == TOKEN_MAX_ATTEMPTS
|
|
@@ -264,7 +264,7 @@ def test_a_changed_app_needs_the_owner_to_connect_again_without_a_token_call():
|
|
|
264
264
|
http, auth = make(fake, app={"clientId": "another-app", "clientSecret": CLIENT_SECRET})
|
|
265
265
|
with pytest.raises(ExportConnectorError) as e:
|
|
266
266
|
auth.auth_headers()
|
|
267
|
-
assert e.value.code is ErrorCode.
|
|
267
|
+
assert e.value.code is ErrorCode.UNAUTHENTICATED and fake.refresh_count == 0
|
|
268
268
|
|
|
269
269
|
|
|
270
270
|
def test_rotation_is_warned_once():
|
|
@@ -281,7 +281,7 @@ def test_a_401_that_survives_a_refresh_asks_the_owner_to_connect_again():
|
|
|
281
281
|
http, auth = make(fake)
|
|
282
282
|
with pytest.raises(ExportConnectorError) as e:
|
|
283
283
|
snap_client.SnapClient(http, auth).get_ad_account("acc-1")
|
|
284
|
-
assert e.value.code is ErrorCode.
|
|
284
|
+
assert e.value.code is ErrorCode.UNAUTHENTICATED
|
|
285
285
|
assert fake.refresh_count == 2
|
|
286
286
|
|
|
287
287
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""The OAuth helper against a fake token endpoint."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
from datetime import datetime, timezone
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
import pytest
|
|
@@ -97,17 +98,24 @@ def test_an_access_token_grant_is_returned_as_it_is():
|
|
|
97
98
|
assert endpoint.requests == []
|
|
98
99
|
|
|
99
100
|
|
|
101
|
+
def test_an_expired_grant_fails_without_calling_the_provider():
|
|
102
|
+
endpoint = FakeEndpoint()
|
|
103
|
+
error = _error(_provider(endpoint, expires_at=datetime(2026, 1, 1, tzinfo=timezone.utc)).token)
|
|
104
|
+
assert error.code is ErrorCode.CREDENTIALS_EXPIRED
|
|
105
|
+
assert endpoint.requests == []
|
|
106
|
+
|
|
107
|
+
|
|
100
108
|
def test_a_grant_of_another_oauth_app_fails_without_calling_the_provider():
|
|
101
109
|
endpoint = FakeEndpoint()
|
|
102
110
|
error = _error(_provider(endpoint, grant={**GRANT, "clientId": "other"}).token)
|
|
103
|
-
assert error.code is ErrorCode.
|
|
111
|
+
assert error.code is ErrorCode.UNAUTHENTICATED
|
|
104
112
|
assert endpoint.requests == []
|
|
105
113
|
|
|
106
114
|
|
|
107
115
|
@pytest.mark.parametrize(
|
|
108
116
|
("status", "body", "code"),
|
|
109
117
|
[
|
|
110
|
-
(400, {"error": "invalid_grant"}, ErrorCode.
|
|
118
|
+
(400, {"error": "invalid_grant"}, ErrorCode.UNAUTHENTICATED),
|
|
111
119
|
(400, {"error": "invalid_client"}, ErrorCode.OAUTH_APP_CREDENTIALS_REJECTED),
|
|
112
120
|
(400, {"error": "unauthorized_client"}, ErrorCode.OAUTH_APP_CREDENTIALS_REJECTED),
|
|
113
121
|
(401, {}, ErrorCode.OAUTH_APP_CREDENTIALS_REJECTED),
|
|
@@ -136,16 +144,16 @@ def test_a_retry_that_succeeds_returns_the_token():
|
|
|
136
144
|
|
|
137
145
|
def test_a_kind_can_say_what_exhausted_retries_mean():
|
|
138
146
|
def snap_like(status, body):
|
|
139
|
-
return Retry(ErrorCode.
|
|
147
|
+
return Retry(ErrorCode.UNAUTHENTICATED) if status >= 500 else classify_refresh_response(status, body)
|
|
140
148
|
|
|
141
149
|
endpoint = FakeEndpoint(_answer(500, {}), _answer(500, {}), _answer(500, {}))
|
|
142
150
|
error = _error(_provider(endpoint, classify=snap_like).token)
|
|
143
|
-
assert error.code is ErrorCode.
|
|
151
|
+
assert error.code is ErrorCode.UNAUTHENTICATED
|
|
144
152
|
|
|
145
153
|
|
|
146
154
|
def test_after_a_good_refresh_a_server_error_is_an_outage():
|
|
147
155
|
def snap_like(status, body):
|
|
148
|
-
return Retry(ErrorCode.
|
|
156
|
+
return Retry(ErrorCode.UNAUTHENTICATED) if status >= 500 else classify_refresh_response(status, body)
|
|
149
157
|
|
|
150
158
|
endpoint = FakeEndpoint(_answer(200, {"access_token": "a"}), _answer(500, {}), _answer(500, {}), _answer(500, {}))
|
|
151
159
|
provider = _provider(endpoint, classify=snap_like)
|
|
@@ -182,4 +190,4 @@ def test_a_refused_call_is_retried_with_a_new_token():
|
|
|
182
190
|
def test_a_call_that_is_still_refused_needs_reauthorisation():
|
|
183
191
|
endpoint = FakeEndpoint(_answer(200, {"access_token": "a"}), _answer(200, {"access_token": "b"}))
|
|
184
192
|
error = _error(lambda: _provider(endpoint).call(lambda token: 401, lambda status: status == 401))
|
|
185
|
-
assert error.code is ErrorCode.
|
|
193
|
+
assert error.code is ErrorCode.UNAUTHENTICATED
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from dq_export_connector.errors import ErrorCode
|
|
2
|
+
from dq_export_connector.models import DestinationAccount
|
|
3
|
+
from dq_export_connector.outcome import RunOutcome
|
|
4
|
+
from dq_export_connector.redact import Redactor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _listing(outcome: RunOutcome) -> dict:
|
|
8
|
+
accounts = [DestinationAccount(id="a1", name="Acme DE")]
|
|
9
|
+
return outcome.destination_account_listing(accounts, Redactor([])).model_dump(by_alias=True, exclude_none=True)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_a_listing_holds_the_accounts():
|
|
13
|
+
assert _listing(RunOutcome()) == {"warnings": [], "destinationAccounts": [{"id": "a1", "name": "Acme DE"}]}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_a_listing_that_failed_holds_its_error_and_no_accounts():
|
|
17
|
+
outcome = RunOutcome()
|
|
18
|
+
outcome.fail(ErrorCode.UNAUTHENTICATED, "Connect again")
|
|
19
|
+
assert _listing(outcome) == {
|
|
20
|
+
"error": {"code": "UNAUTHENTICATED", "message": "Connect again"},
|
|
21
|
+
"warnings": [],
|
|
22
|
+
"destinationAccounts": [],
|
|
23
|
+
}
|
|
@@ -526,21 +526,3 @@ def test_a_failure_outside_the_action_fails_the_worker_without_its_message(tmp_p
|
|
|
526
526
|
runner.main(tmp_path / "config.json", tmp_path / "credentials.json", tmp_path, tmp_path / "out")
|
|
527
527
|
assert raised.value.__cause__ is None
|
|
528
528
|
|
|
529
|
-
|
|
530
|
-
def test_a_kind_without_a_destination_account_listing_fails_with_an_internal_error(tmp_path, monkeypatch):
|
|
531
|
-
listing: dict[str, dict] = {"listDestinationAccounts": {}}
|
|
532
|
-
assert _run(tmp_path, _config(listing, []), {}, MemoryStore(), monkeypatch) is True
|
|
533
|
-
error = json.loads((tmp_path / "internal" / "application_error").read_text())
|
|
534
|
-
assert error["code"] == "INTERNAL_ERROR"
|
|
535
|
-
assert not (tmp_path / "output" / "result.json").exists()
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
def test_a_listing_writes_its_accounts_to_the_result(tmp_path, monkeypatch):
|
|
539
|
-
from dq_export_connector.models import DestinationAccounts
|
|
540
|
-
|
|
541
|
-
accounts = {"destinationAccounts": [{"id": "a1", "name": "Acme DE"}]}
|
|
542
|
-
monkeypatch.setitem(
|
|
543
|
-
runner.DESTINATION_LISTERS, "bucket", lambda _config, _credentials, _outcome: DestinationAccounts.model_validate(accounts)
|
|
544
|
-
)
|
|
545
|
-
assert _run(tmp_path, _config({"listDestinationAccounts": {}}, []), {}, MemoryStore(), monkeypatch) is False
|
|
546
|
-
assert json.loads((tmp_path / "output" / "result.json").read_text()) == accounts
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_snap_runner.py
RENAMED
|
@@ -40,7 +40,7 @@ def sha(s: str) -> str:
|
|
|
40
40
|
def config(*inputs: dict, mode: str = "export", ad_account_id: str | None = AD_ACCOUNT_ID) -> dict:
|
|
41
41
|
action = {"export": {"export": {"params": {"type": "snap"}}}}.get(
|
|
42
42
|
mode,
|
|
43
|
-
{"
|
|
43
|
+
{"validateConnection": {"params": {"type": "snap", "mode": "list" if mode == "list" else "check"}}},
|
|
44
44
|
)
|
|
45
45
|
return {
|
|
46
46
|
"action": action,
|
|
@@ -565,7 +565,7 @@ def test_auth_failure_stops_the_run_without_uploading(env):
|
|
|
565
565
|
write("segA", EMAILS)
|
|
566
566
|
write("segB", EMAILS)
|
|
567
567
|
report = run(config(spec(), spec(leaf="segB", name="Autumn")))
|
|
568
|
-
assert error_code(report) == "
|
|
568
|
+
assert error_code(report) == "UNAUTHENTICATED"
|
|
569
569
|
assert fake.mutating_requests() == []
|
|
570
570
|
# Only the pre-flight's refresh ran; the Inputs were never tried.
|
|
571
571
|
assert len([r for r in fake.requests if r[1] == TOKEN_ROUTE]) == TOKEN_MAX_ATTEMPTS
|
|
@@ -608,7 +608,7 @@ def test_access_denied_says_the_fix_is_in_the_platform(env):
|
|
|
608
608
|
def test_validate_reports_dead_grant(env):
|
|
609
609
|
fake, write, run = env
|
|
610
610
|
fake.valid_refresh_tokens.clear()
|
|
611
|
-
assert error_code(run(config(spec(), mode="validate"))) == "
|
|
611
|
+
assert error_code(run(config(spec(), mode="validate"))) == "UNAUTHENTICATED"
|
|
612
612
|
|
|
613
613
|
|
|
614
614
|
def test_a_changed_app_is_reported_without_asking_snap(env):
|
|
@@ -616,7 +616,7 @@ def test_a_changed_app_is_reported_without_asking_snap(env):
|
|
|
616
616
|
credentials = json.loads(json.dumps(CREDENTIALS))
|
|
617
617
|
credentials["credentials"]["grant"]["clientId"] = "the-previous-app"
|
|
618
618
|
result = run(config(spec(), mode="validate"), credentials)
|
|
619
|
-
assert error_code(result) == "
|
|
619
|
+
assert error_code(result) == "UNAUTHENTICATED" and fake.refresh_count == 0
|
|
620
620
|
|
|
621
621
|
|
|
622
622
|
def test_listing_flattens_every_organizations_ad_accounts_once_each(env):
|
|
@@ -627,18 +627,26 @@ def test_listing_flattens_every_organizations_ad_accounts_once_each(env):
|
|
|
627
627
|
}
|
|
628
628
|
result = run(config(mode="list", ad_account_id=None))
|
|
629
629
|
assert result == {
|
|
630
|
+
"warnings": [],
|
|
630
631
|
"destinationAccounts": [
|
|
631
632
|
{"id": AD_ACCOUNT_ID, "name": "Acme DE"},
|
|
632
633
|
{"id": "11111111-1111-4111-8111-111111111111", "name": "Acme FR"},
|
|
633
|
-
]
|
|
634
|
+
],
|
|
634
635
|
}
|
|
635
636
|
|
|
636
637
|
|
|
637
|
-
def
|
|
638
|
+
def test_listing_with_a_dead_grant_reports_it_in_the_result(env):
|
|
638
639
|
fake, write, run = env
|
|
639
640
|
fake.valid_refresh_tokens.clear()
|
|
640
641
|
result = run(config(mode="list", ad_account_id=None))
|
|
641
|
-
assert
|
|
642
|
+
assert result == {
|
|
643
|
+
"error": {
|
|
644
|
+
"code": "UNAUTHENTICATED",
|
|
645
|
+
"message": "Snap refuses the access the owner granted: connect the Export Connector again",
|
|
646
|
+
},
|
|
647
|
+
"warnings": [],
|
|
648
|
+
"destinationAccounts": [],
|
|
649
|
+
}
|
|
642
650
|
|
|
643
651
|
|
|
644
652
|
def test_the_app_secret_is_redacted_even_when_snap_echoes_it(env, log_lines):
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# generated by datamodel-codegen:
|
|
2
|
-
# filename: destination_accounts.json
|
|
3
|
-
|
|
4
|
-
from __future__ import annotations
|
|
5
|
-
|
|
6
|
-
from typing import Annotated
|
|
7
|
-
|
|
8
|
-
from pydantic import BaseModel, ConfigDict, Field
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class DestinationAccount(BaseModel):
|
|
12
|
-
model_config = ConfigDict(
|
|
13
|
-
populate_by_name=True,
|
|
14
|
-
)
|
|
15
|
-
id: str
|
|
16
|
-
name: str
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class DestinationAccounts(BaseModel):
|
|
20
|
-
model_config = ConfigDict(
|
|
21
|
-
populate_by_name=True,
|
|
22
|
-
)
|
|
23
|
-
destination_accounts: Annotated[
|
|
24
|
-
list[DestinationAccount], Field(alias='destinationAccounts')
|
|
25
|
-
]
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/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
|
|
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.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/datasets.py
RENAMED
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/log.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/dq_export_connector/redact.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
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/fakes/snap_fake.py
RENAMED
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_live_buckets.py
RENAMED
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_models_are_current.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dq_export_connector-0.1.0.dev28 → dq_export_connector-0.1.0.dev29}/tests/test_sync_input.py
RENAMED
|
File without changes
|
|
File without changes
|