dq-export-connector 0.1.0.dev27__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.
Files changed (70) hide show
  1. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/.gitignore +1 -1
  2. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/PKG-INFO +14 -18
  3. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/README.md +13 -17
  4. dq_export_connector-0.1.0.dev29/dq_export_connector/_models/destination_account_listing.py +48 -0
  5. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_connector_credentials.py +42 -4
  6. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_worker_config.py +71 -53
  7. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/classify.py +0 -17
  8. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/http.py +1 -1
  9. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/errors.py +13 -5
  10. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/__init__.py +7 -0
  11. dq_export_connector-0.1.0.dev29/dq_export_connector/oauth.py +235 -0
  12. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/outcome.py +20 -1
  13. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/redact.py +4 -2
  14. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/runner.py +58 -24
  15. dq_export_connector-0.1.0.dev29/dq_export_connector/snap/accounts.py +18 -0
  16. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/client.py +27 -1
  17. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/destination.py +1 -37
  18. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/export.py +28 -38
  19. dq_export_connector-0.1.0.dev29/dq_export_connector/snap/session.py +103 -0
  20. dq_export_connector-0.1.0.dev29/dq_export_connector/snap/validate.py +29 -0
  21. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/pyproject.toml +1 -1
  22. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/scripts/_local.py +33 -7
  23. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/scripts/codegen-models.sh +1 -1
  24. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/scripts/run_local.py +11 -3
  25. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/fakes/snap_fake.py +29 -0
  26. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_http_and_oauth.py +50 -89
  27. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_live_snap.py +42 -20
  28. dq_export_connector-0.1.0.dev29/tests/test_oauth.py +193 -0
  29. dq_export_connector-0.1.0.dev29/tests/test_outcome.py +23 -0
  30. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_redact.py +5 -0
  31. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_runner.py +1 -0
  32. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_snap_runner.py +72 -28
  33. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/uv.lock +1 -1
  34. dq_export_connector-0.1.0.dev27/dq_export_connector/audience/oauth.py +0 -321
  35. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/session.py +0 -70
  36. dq_export_connector-0.1.0.dev27/dq_export_connector/snap/validate.py +0 -37
  37. dq_export_connector-0.1.0.dev27/scripts/consent.py +0 -99
  38. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/.python-version +0 -0
  39. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/__init__.py +0 -0
  40. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/__init__.py +0 -0
  41. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/application_message.py +0 -0
  42. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/bucket_validation_result.py +0 -0
  43. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/export_receipt.py +0 -0
  44. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/_models/snap_validation_result.py +0 -0
  45. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/__init__.py +0 -0
  46. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/identifiers.py +0 -0
  47. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/inputs.py +0 -0
  48. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/audience/sync.py +0 -0
  49. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/__init__.py +0 -0
  50. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/export.py +0 -0
  51. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/paths.py +0 -0
  52. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/store.py +0 -0
  53. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/upload.py +0 -0
  54. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/bucket/validate.py +0 -0
  55. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/datasets.py +0 -0
  56. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/log.py +0 -0
  57. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/bucket.py +0 -0
  58. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/models/snap.py +0 -0
  59. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/dq_export_connector/snap/__init__.py +0 -0
  60. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/__init__.py +0 -0
  61. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/conftest.py +0 -0
  62. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/fakes/__init__.py +0 -0
  63. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_identifiers_and_inputs.py +0 -0
  64. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_live_buckets.py +0 -0
  65. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_models_are_current.py +0 -0
  66. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_paths.py +0 -0
  67. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_scripts.py +0 -0
  68. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_store.py +0 -0
  69. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_sync_input.py +0 -0
  70. {dq_export_connector-0.1.0.dev27 → dq_export_connector-0.1.0.dev29}/tests/test_upload.py +0 -0
@@ -1,4 +1,4 @@
1
- # Local secrets for the consent CLI and the local runner.
1
+ # Local secrets for the local runner.
2
2
  credentials*.json
3
3
  platform_secrets*.json
4
4
  local/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dq-export-connector
3
- Version: 0.1.0.dev27
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,11 +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 and, per Input, a Segment, the
71
- identifier type its lines hold and a Merge Mode. ddc validates it. The
72
- credentials are the refresh token of the Snap user who consented; Decentriq's
73
- Snap app is the `export_connector_snap_app` platform secret
74
- (`{"clientId", "clientSecret"}`).
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
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
73
+ Grant of the Snap user who consented; each run turns it into an Access Token
74
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
75
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
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.
75
79
 
76
80
  A run looks each Segment up by name in the ad account and creates it when
77
81
  there is none, marked `Managed by Decentriq`. It writes into a same-named
@@ -121,18 +125,10 @@ warning or error message), never with the values themselves:
121
125
  The local files are gitignored in this directory:
122
126
 
123
127
  - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
124
- - `credentials.json`: written by the consent CLI.
125
- - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
128
+ - `credentials.json`: `{"type": "snap", "credentials": {"refreshToken": …}}`, a refresh token the owner got through consent on a dev environment. Snap doesn't rotate it, so it can be reused.
129
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
126
130
 
127
- 1. Consent, as the Snap user who has a role on the test ad account. The
128
- redirect URI must be an https URI registered on the app; only the URL the
129
- browser lands on matters.
130
-
131
- ```sh
132
- uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
133
- --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
134
- ```
135
- 2. Run:
131
+ 1. Run:
136
132
 
137
133
  ```sh
138
134
  mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
@@ -141,7 +137,7 @@ The local files are gitignored in this directory:
141
137
  uv run python scripts/run_local.py --config config.json --credentials credentials.json \
142
138
  --platform-secrets platform_secrets.json
143
139
  ```
144
- 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
140
+ 2. Live tests, including the check that Snap doesn't rotate refresh tokens:
145
141
 
146
142
  ```sh
147
143
  DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
@@ -54,11 +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 and, per Input, a Segment, the
58
- identifier type its lines hold and a Merge Mode. ddc validates it. The
59
- credentials are the refresh token of the Snap user who consented; Decentriq's
60
- Snap app is the `export_connector_snap_app` platform secret
61
- (`{"clientId", "clientSecret"}`).
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
+ lines hold and a Merge Mode. ddc validates it. The credentials are the OAuth
60
+ Grant of the Snap user who consented; each run turns it into an Access Token
61
+ with `dq_export_connector.oauth`. Decentriq's Snap app is the
62
+ `export_connector_snap_app` platform secret (`{"clientId", "clientSecret"}`),
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.
62
66
 
63
67
  A run looks each Segment up by name in the ad account and creates it when
64
68
  there is none, marked `Managed by Decentriq`. It writes into a same-named
@@ -108,18 +112,10 @@ warning or error message), never with the values themselves:
108
112
  The local files are gitignored in this directory:
109
113
 
110
114
  - `platform_secrets.json`: `{"export_connector_snap_app": {"clientId": …, "clientSecret": …}}`, the dev app.
111
- - `credentials.json`: written by the consent CLI.
112
- - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "grantExpiresAt": null, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
115
+ - `credentials.json`: `{"type": "snap", "credentials": {"refreshToken": …}}`, a refresh token the owner got through consent on a dev environment. Snap doesn't rotate it, so it can be reused.
116
+ - `config.json`: `{"connector": {"type": "snap", "adAccountId": …, "inputs": [{"leafId": "segA", "segmentName": …, "identifierType": "EMAIL", "mergeMode": "ADD", "retentionDays": 180}]}}`.
113
117
 
114
- 1. Consent, as the Snap user who has a role on the test ad account. The
115
- redirect URI must be an https URI registered on the app; only the URL the
116
- browser lands on matters.
117
-
118
- ```sh
119
- uv run python scripts/consent.py snap --platform-secrets platform_secrets.json \
120
- --redirect-uri "$REDIRECT_URI" --out credentials.json --config config.json
121
- ```
122
- 2. Run:
118
+ 1. Run:
123
119
 
124
120
  ```sh
125
121
  mkdir -p local/inputs && printf 'a@example.com\nb@example.com\n' > local/inputs/segA
@@ -128,7 +124,7 @@ The local files are gitignored in this directory:
128
124
  uv run python scripts/run_local.py --config config.json --credentials credentials.json \
129
125
  --platform-secrets platform_secrets.json
130
126
  ```
131
- 3. Live tests, including the check that Snap doesn't rotate refresh tokens:
127
+ 2. Live tests, including the check that Snap doesn't rotate refresh tokens:
132
128
 
133
129
  ```sh
134
130
  DQ_EXPORT_LIVE_SNAP_DIR=$PWD uv run pytest -m live -s tests/test_live_snap.py
@@ -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]
@@ -56,17 +56,55 @@ class BucketExportCredentials(
56
56
  ]
57
57
 
58
58
 
59
- class SnapExportCredentials(BaseModel):
59
+ class GrantTokenRefreshToken(BaseModel):
60
60
  model_config = ConfigDict(
61
61
  populate_by_name=True,
62
62
  )
63
- refresh_token: Annotated[
63
+ type: Literal['refreshToken']
64
+ value: str
65
+
66
+
67
+ class GrantTokenAccessToken(BaseModel):
68
+ model_config = ConfigDict(
69
+ populate_by_name=True,
70
+ )
71
+ type: Literal['accessToken']
72
+ value: str
73
+
74
+
75
+ class GrantToken(RootModel[GrantTokenRefreshToken | GrantTokenAccessToken]):
76
+ root: GrantTokenRefreshToken | GrantTokenAccessToken
77
+
78
+
79
+ class OAuthGrant(BaseModel):
80
+ model_config = ConfigDict(
81
+ populate_by_name=True,
82
+ )
83
+ client_id: Annotated[
64
84
  str,
65
85
  Field(
66
- alias='refreshToken',
67
- description="The refresh token of the Snap user who consented. Snap doesn't rotate it.",
86
+ alias='clientId',
87
+ description='The OAuth App the grant was issued to; it only works with that app.',
68
88
  ),
69
89
  ]
90
+ obtained_at: Annotated[
91
+ str, Field(alias='obtainedAt', description='RFC 3339, in UTC.')
92
+ ]
93
+ token: GrantToken
94
+
95
+
96
+ class SnapExportCredentialsOauth(BaseModel):
97
+ model_config = ConfigDict(
98
+ populate_by_name=True,
99
+ )
100
+ grant: OAuthGrant
101
+ type: Literal['oauth']
102
+
103
+
104
+ class SnapExportCredentials(RootModel[SnapExportCredentialsOauth]):
105
+ root: Annotated[
106
+ SnapExportCredentialsOauth, Field(description='What is sealed for Snap.')
107
+ ]
70
108
 
71
109
 
72
110
  class ExportConnectorCredentialsBucket(BaseModel):
@@ -57,6 +57,11 @@ class BucketInput(BaseModel):
57
57
  leaf_id: Annotated[str, Field(alias='leafId')]
58
58
 
59
59
 
60
+ class ClientAuth(Enum):
61
+ form_body = 'formBody'
62
+ http_basic = 'httpBasic'
63
+
64
+
60
65
  class ExportConnectorKindBucket(BaseModel):
61
66
  model_config = ConfigDict(
62
67
  populate_by_name=True,
@@ -107,6 +112,15 @@ class MergeMode(Enum):
107
112
  replace = 'REPLACE'
108
113
 
109
114
 
115
+ class OAuthWorkerConfig(BaseModel):
116
+ model_config = ConfigDict(
117
+ populate_by_name=True,
118
+ )
119
+ client_auth: Annotated[ClientAuth, Field(alias='clientAuth')]
120
+ platform_secret: Annotated[str, Field(alias='platformSecret')]
121
+ token_url: Annotated[str, Field(alias='tokenUrl')]
122
+
123
+
110
124
  class ProvisionedPolicy(BaseModel):
111
125
  model_config = ConfigDict(
112
126
  populate_by_name=True,
@@ -156,17 +170,9 @@ class ValidateConnectionParamsBucket(BaseModel):
156
170
  type: Literal['bucket']
157
171
 
158
172
 
159
- class ValidateConnectionParamsSnap(BaseModel):
160
- model_config = ConfigDict(
161
- populate_by_name=True,
162
- )
163
- type: Literal['snap']
164
-
165
-
166
- class ValidateConnectionParams(
167
- RootModel[ValidateConnectionParamsBucket | ValidateConnectionParamsSnap]
168
- ):
169
- root: ValidateConnectionParamsBucket | ValidateConnectionParamsSnap
173
+ class ValidationMode(Enum):
174
+ check = 'check'
175
+ list = 'list'
170
176
 
171
177
 
172
178
  class BucketExportConfig(BaseModel):
@@ -184,23 +190,6 @@ class BucketExportConfig(BaseModel):
184
190
  inputs: list[BucketInput]
185
191
 
186
192
 
187
- class ValidateConnection(BaseModel):
188
- model_config = ConfigDict(
189
- populate_by_name=True,
190
- )
191
- params: ValidateConnectionParams
192
-
193
-
194
- class ExportConnectorDcrComputeActionValidateConnection(BaseModel):
195
- model_config = ConfigDict(
196
- extra='forbid',
197
- populate_by_name=True,
198
- )
199
- validate_connection: Annotated[
200
- ValidateConnection, Field(alias='validateConnection')
201
- ]
202
-
203
-
204
193
  class Export(BaseModel):
205
194
  model_config = ConfigDict(
206
195
  populate_by_name=True,
@@ -216,33 +205,15 @@ class ExportConnectorDcrComputeActionExport(BaseModel):
216
205
  export: Export
217
206
 
218
207
 
219
- class ExportConnectorDcrComputeAction(
220
- RootModel[
221
- ExportConnectorDcrComputeActionValidateConnection
222
- | ExportConnectorDcrComputeActionExport
223
- ]
224
- ):
225
- root: Annotated[
226
- ExportConnectorDcrComputeActionValidateConnection
227
- | ExportConnectorDcrComputeActionExport,
228
- Field(
229
- description='Compute actions for an Export Connector DCR, started through `POST /jobs`.'
230
- ),
231
- ]
232
-
233
-
234
208
  class ExportConnectorKindSnap(BaseModel):
235
209
  model_config = ConfigDict(
236
210
  populate_by_name=True,
237
211
  )
238
212
  ad_account_id: Annotated[
239
- str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
240
- ]
241
- grant_expires_at: Annotated[
242
213
  str | None,
243
214
  Field(
244
- alias='grantExpiresAt',
245
- description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
215
+ alias='adAccountId',
216
+ description='A canonical, lowercase UUID. `None` until the owner picks one from the\nad accounts the grant reaches.',
246
217
  ),
247
218
  ] = None
248
219
  inputs: list[SnapInput]
@@ -260,18 +231,61 @@ class SnapExportConfig(BaseModel):
260
231
  populate_by_name=True,
261
232
  )
262
233
  ad_account_id: Annotated[
263
- str, Field(alias='adAccountId', description='A canonical, lowercase UUID.')
264
- ]
265
- grant_expires_at: Annotated[
266
234
  str | None,
267
235
  Field(
268
- alias='grantExpiresAt',
269
- description='RFC 3339. When the grant behind the credentials expires; runs warn as\nit nears.',
236
+ alias='adAccountId',
237
+ description='A canonical, lowercase UUID. `None` until the owner picks one from the\nad accounts the grant reaches.',
270
238
  ),
271
239
  ] = None
272
240
  inputs: list[SnapInput]
273
241
 
274
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
+
275
289
  class ExportWorkerConfig(BaseModel):
276
290
  model_config = ConfigDict(
277
291
  populate_by_name=True,
@@ -282,4 +296,8 @@ class ExportWorkerConfig(BaseModel):
282
296
  AwareDatetime | None,
283
297
  Field(alias='credentialsExpireAt', description='From the Credentials Info.'),
284
298
  ] = None
299
+ oauth: Annotated[
300
+ OAuthWorkerConfig | None,
301
+ Field(description='For a kind whose credentials are an OAuth Grant.'),
302
+ ] = None
285
303
  policies: list[ProvisionedPolicy]
@@ -79,20 +79,3 @@ def classify_status(status: int, raw_code: object = None, platform_message: obje
79
79
  return Classification(Verdict.RETRY, ErrorCode.UNKNOWN, code, message)
80
80
  return Classification(Verdict.FAIL, ErrorCode.UNKNOWN, code, message)
81
81
 
82
-
83
- def classify_oauth_token_response(response: requests.Response) -> Classification:
84
- """RFC 6749 token endpoint errors (Snap, LinkedIn)."""
85
- body = json_body(response)
86
- error = platform_code(body.get("error"))
87
- description = body.get("error_description")
88
- if 200 <= response.status_code < 300:
89
- return Classification(Verdict.OK)
90
- if error == "invalid_grant":
91
- return Classification(Verdict.FAIL, ErrorCode.UNAUTHENTICATED, error, platform_text(description))
92
- if error in ("invalid_client", "unauthorized_client"):
93
- return Classification(Verdict.FAIL, ErrorCode.APP_CREDENTIALS_REJECTED, error, platform_text(description))
94
- result = classify_status(response.status_code, error, description)
95
- if result.code is ErrorCode.UNAUTHENTICATED:
96
- # A 401 from the token endpoint means the client authentication failed.
97
- return Classification(Verdict.FAIL, ErrorCode.APP_CREDENTIALS_REJECTED, error, result.platform_message)
98
- return result
@@ -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 REAUTHORISATION_NEEDED if that's impossible."""
34
+ """Refresh after a 401, or raise if that's impossible."""
35
35
  ...
36
36
 
37
37
 
@@ -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,23 +21,20 @@ class ErrorCode(str, Enum):
20
21
  UNKNOWN = "UNKNOWN"
21
22
  READ_FAILED = "READ_FAILED"
22
23
  INTERNAL_ERROR = "INTERNAL_ERROR"
24
+ OAUTH_APP_CREDENTIALS_REJECTED = "OAUTH_APP_CREDENTIALS_REJECTED"
23
25
  BUCKET_INVALID_PATH = "BUCKET_INVALID_PATH"
24
- # Decentriq's own app credentials for the platform were rejected.
25
- APP_CREDENTIALS_REJECTED = "APP_CREDENTIALS_REJECTED"
26
26
  RATE_LIMITED = "RATE_LIMITED"
27
27
  AMBIGUOUS_SEGMENT = "AMBIGUOUS_SEGMENT"
28
28
  TOO_MANY_INVALID_ROWS = "TOO_MANY_INVALID_ROWS"
29
29
  # A request that isn't safe to repeat may or may not have been applied.
30
30
  OUTCOME_UNKNOWN = "OUTCOME_UNKNOWN"
31
- # The platform issued a new refresh token, which the worker can't store.
32
- REFRESH_TOKEN_ROTATED = "REFRESH_TOKEN_ROTATED"
33
31
 
34
32
 
35
33
  class WarningCode(str, Enum):
36
34
  EMPTY_DATASET = "EMPTY_DATASET"
35
+ OAUTH_REFRESH_TOKEN_ROTATED = "OAUTH_REFRESH_TOKEN_ROTATED"
37
36
  BUCKET_PROBE_NOT_DELETED = "BUCKET_PROBE_NOT_DELETED"
38
37
  BUCKET_PARTS_MAY_REMAIN = "BUCKET_PARTS_MAY_REMAIN"
39
- REAUTHORISATION_DUE = "REAUTHORISATION_DUE"
40
38
  INVALID_ROWS = "INVALID_ROWS"
41
39
  SEGMENT_SETTINGS_DIFFER = "SEGMENT_SETTINGS_DIFFER"
42
40
  # The run wrote into a Segment this connector didn't create.
@@ -83,6 +81,16 @@ class Issue(Generic[Code]):
83
81
  message: str
84
82
 
85
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
+
86
94
  def internal_error_message(error: BaseException, activity: str) -> str:
87
95
  """Names the error's type and where it was raised, but not its message,
88
96
  which could hold dataset values."""
@@ -3,6 +3,7 @@ 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.destination_account_listing import DestinationAccount, DestinationAccountListing
6
7
  from dq_export_connector._models.export_connector_credentials import ExportConnectorCredentials
7
8
  from dq_export_connector._models.export_receipt import ExportReceipt, ExportReceiptV0, ExportTotals
8
9
  from dq_export_connector._models.export_worker_config import (
@@ -13,13 +14,17 @@ from dq_export_connector._models.export_worker_config import (
13
14
  ExportConnectorKind,
14
15
  ExportParams,
15
16
  ExportWorkerConfig,
17
+ OAuthWorkerConfig,
16
18
  ProvisionedPolicy,
17
19
  ValidateConnection,
18
20
  ValidateConnectionParams,
21
+ ValidationMode,
19
22
  )
20
23
 
21
24
  __all__ = [
22
25
  "ApplicationMessage",
26
+ "DestinationAccount",
27
+ "DestinationAccountListing",
23
28
  "Export",
24
29
  "ExportConnectorCredentials",
25
30
  "ExportConnectorDcrComputeAction",
@@ -31,7 +36,9 @@ __all__ = [
31
36
  "ExportReceiptV0",
32
37
  "ExportTotals",
33
38
  "ExportWorkerConfig",
39
+ "OAuthWorkerConfig",
34
40
  "ProvisionedPolicy",
35
41
  "ValidateConnection",
36
42
  "ValidateConnectionParams",
43
+ "ValidationMode",
37
44
  ]