-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathmanifest.yaml
407 lines (401 loc) · 15.4 KB
/
manifest.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
version: 6.7.0
type: DeclarativeSource
check:
type: CheckDynamicStream
stream_count: 1
use_check_availability: false
dynamic_streams:
- type: DynamicDeclarativeStream
stream_template:
type: DeclarativeStream
name: ""
$parameters:
i: 123
primary_key: []
retriever:
type: SimpleRetriever
$parameters:
row_count: 0
sheet_id: ""
batch_size: 0
partition_router:
type: CustomPartitionRouter
class_name: "source_google_sheets.components.partition_routers.RangePartitionRouter"
paginator:
type: NoPagination
record_selector:
decoder:
type: JsonDecoder
extractor:
type: CustomRecordExtractor
class_name: source_google_sheets.components.DpathSchemaMatchingExtractor
description: Extract record list of values (rows) and matches such values to correct schema property to generate individual records.
field_path:
- valueRanges
- "*"
$parameters:
schema_type_identifier:
$ref: "#/definitions/schema_type_identifier"
values_to_match_key: "values"
properties_to_match: ""
type: RecordSelector
$parameters:
name: ""
requester:
$ref: "#/definitions/base_requester"
$parameters:
sheet_id: ""
name: ""
http_method: GET
path: >-
{% if config["spreadsheet_id"] | regex_search("^(https://.*)") %}{{ config["spreadsheet_id"] | regex_search("/([-\\w]{20,})([/]?)") }}{% else %}{{ config["spreadsheet_id"] }}{% endif %}/values:batchGet?ranges={{parameters["sheet_id"] | urlencode}}!{{stream_partition.start_range}}:{{stream_partition.end_range}}&majorDimension=ROWS&alt=json
error_handler:
type: DefaultErrorHandler
backoff_strategies:
- type: ExponentialBackoffStrategy
response_filters:
$ref: "#/definitions/response_filters/response_error_filters"
schema_loader:
type: DynamicSchemaLoader
retriever:
type: SimpleRetriever
paginator:
type: NoPagination
record_selector:
extractor:
type: CustomRecordExtractor
class_name: source_google_sheets.components.DpathSchemaExtractor
parameters:
schema_type_identifier:
$ref: "#/definitions/schema_type_identifier"
field_path:
- sheets
- "*"
- data
- "*"
- rowData
- "*"
type: RecordSelector
requester:
$ref: "#/definitions/base_requester"
$parameters:
sheet_id: ""
http_method: GET
path: >-
{% if config["spreadsheet_id"] | regex_search("^(https://.*)") %}{{ config["spreadsheet_id"] | regex_search("/([-\\w]{20,})([/]?)") }}{% else %}{{ config["spreadsheet_id"] }}{% endif %}?includeGridData=true&ranges={{parameters["sheet_id"] | urlencode}}!1:1&alt=json
error_handler:
type: CompositeErrorHandler
error_handlers:
- type: DefaultErrorHandler
backoff_strategies:
- type: ExponentialBackoffStrategy
response_filters:
$ref: "#/definitions/response_filters/single_sheet_response_error_filters"
schema_type_identifier:
$ref: "#/definitions/schema_type_identifier"
components_resolver:
type: HttpComponentsResolver
description: We use first row of sheet to obtain data.
retriever:
$ref: "#/definitions/retrievers/components_resolver_retriever"
components_mapping:
- field_path:
- name
type: ComponentMappingDefinition
value: "{{components_values['properties']['title']}}"
description: name for dynamic stream.
- field_path:
- schema_loader
- retriever
- requester
- $parameters
- sheet_id
type: ComponentMappingDefinition
value: "{{components_values['properties']['title']}}"
description: sheet_id for dynamic schema loader requester.
- field_path:
- retriever
- requester
- $parameters
- sheet_id
type: ComponentMappingDefinition
value: "{{components_values['properties']['title']}}"
description: sheet_id for dynamic stream retriever requester.
- field_path:
- retriever
- record_selector
- extractor
- $parameters
- properties_to_match
type: ComponentMappingDefinition
value: "{{components_values['data'][0].get('rowData', [{}])[0]}}"
description: indexed_schema to match with row values.
- field_path:
- retriever
- partition_router
- $parameters
- row_count
type: ComponentMappingDefinition
value: "{{components_values['properties']['gridProperties']['rowCount']}}"
- field_path:
- retriever
- partition_router
- $parameters
- sheet_id
type: ComponentMappingDefinition
value: "{{components_values['properties']['title']}}"
description: sheet_id for retriever.
- field_path:
- retriever
- partition_router
- $parameters
- batch_size
type: ComponentMappingDefinition
value: "{{config.get('batch_size', 1000000)}}"
description: batch size count for dynamic stream partition router (slicer).
definitions:
streams:
get_spreadsheet_info_and_sheets:
type: DeclarativeStream
name: get_spreadsheet_info_and_sheets
retriever:
type: SimpleRetriever
requester:
$ref: "#/definitions/base_requester"
path: >-
{% if config["spreadsheet_id"] | regex_search("^(https://.*)") %}{{ config["spreadsheet_id"] | regex_search("/([-\\w]{20,})([/]?)") }}{% else %}{{ config["spreadsheet_id"] }}{% endif %}?includeGridData=false&alt=json
http_method: GET
error_handler:
type: CompositeErrorHandler
error_handlers:
- type: DefaultErrorHandler
backoff_strategies:
- type: ExponentialBackoffStrategy
response_filters:
$ref: "#/definitions/response_filters/response_error_filters"
record_selector:
type: RecordSelector
extractor:
type: DpathExtractor
field_path:
- sheets
- "*"
- properties
record_filter:
type: RecordFilter
condition: '{{ record["sheetType"] == "GRID" and record["gridProperties"]["rowCount"] > 0}}'
schema_loader:
type: InlineSchemaLoader
schema:
$ref: "#/schemas/sheets"
base_requester:
type: HttpRequester
url_base: https://sheets.googleapis.com/v4/spreadsheets/
use_cache: true
authenticator: "#/definitions/authenticator"
retrievers:
components_resolver_retriever:
type: SimpleRetriever
paginator:
type: NoPagination
record_selector:
type: RecordSelector
extractor:
type: DpathExtractor
field_path:
- sheets
partition_router:
type: SubstreamPartitionRouter
parent_stream_configs:
- type: ParentStreamConfig
parent_key: title
partition_field: sheet_id
stream:
$ref: "#/definitions/streams/get_spreadsheet_info_and_sheets"
requester:
$ref: "#/definitions/base_requester"
description: spreadsheet_id can be either the full url to spreadsheet or the spreadsheet id.
http_method: GET
path: >-
{% if config["spreadsheet_id"] | regex_search("^(https://.*)") %}{{ config["spreadsheet_id"] | regex_search("/([-\\w]{20,})([/]?)") }}{% else %}{{ config["spreadsheet_id"] }}{% endif %}?includeGridData=true&ranges={{stream_partition.sheet_id | urlencode}}!1:1&alt=json
error_handler:
type: CompositeErrorHandler
error_handlers:
- type: DefaultErrorHandler
response_filters:
$ref: "#/definitions/response_filters/single_sheet_response_error_filters"
response_filters:
expected_one_sheet:
type: HttpResponseFilter
action: FAIL
predicate: >-
{{ 'sheets' in response and response["sheets"] | length != 1 }}
# error lacks of information as error_message can't interpolate stream_slice["potato"]
error_message: >-
Unable to read the schema of sheet. Error: Unexpected return
result: Sheet was
expected to contain data on exactly 1 sheet.
ignore_duplicate_headers:
type: HttpResponseFilter
action: IGNORE
predicate: >-
{{ response["sheets"][0]["data"][0]["rowData"][0]["values"] |
map(attribute="formattedValue") | list | length !=
response["sheets"][0]["data"][0]["rowData"][0]["values"] |
map(attribute="formattedValue") | list | unique | list | length }}
error_message: >-
{%- set headers_found = response["sheets"][0]["data"][0]["rowData"][0]["values"] | map(attribute="formattedValue") | list -%}
{%- set headers_count = {} -%}
{%- set duplicate_fields = [] -%}
{%- for headerFound in headers_found -%}
{%- if headerFound is not none -%}
{%- set headers_count = headers_count.update({headerFound: headers_count.get(headerFound, 0) + 1}) or headers_count -%}
{%- if headers_count.get(headerFound) > 1 and headerFound not in duplicate_fields -%}
{%- set duplicate_fields = duplicate_fields.append(headerFound) -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
Duplicate headers found in sheet {{ response["sheets"][0]["properties"]["title"] }}.
Ignoring them: {{ duplicate_fields }}
fail_duplicate_headers:
$ref: "#/definitions/response_filters/ignore_duplicate_headers"
action: FAIL
error_message: >-
{%- set headers_found = response["sheets"][0]["data"][0]["rowData"][0]["values"] | map(attribute="formattedValue") | list -%}
{%- set headers_count = {} -%}
{%- set duplicate_fields = [] -%}
{%- for headerFound in headers_found -%}
{%- if headerFound is not none -%}
{%- set headers_count = headers_count.update({headerFound: headers_count.get(headerFound, 0) + 1}) or headers_count -%}
{%- if headers_count.get(headerFound) > 1 and headerFound not in duplicate_fields -%}
{%- set duplicate_fields = duplicate_fields.append(headerFound) -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
The following duplicate headers were found in the sheet.
Please fix them to continue: {{ duplicate_fields }}
server_error:
type: HttpResponseFilter
action: RETRY
http_codes:
- 500
- 502
- 503
error_message: >-
There was an issue
with the Google Sheets API. This is usually a temporary issue from
Google's side. Please try again. If this issue persists, contact
support
forbidden:
type: HttpResponseFilter
action: FAIL
http_codes:
- 403
error_message: >-
The authenticated Google Sheets user does not have permissions to view the
spreadsheet with id {{config["spreadsheet_id"]}}. Please ensure the authenticated user has access
to the Spreadsheet and reauthenticate. If the issue persists, contact support.
The caller does not have right permissions.
not_found:
type: HttpResponseFilter
action: FAIL
http_codes:
- 404
error_message: >-
The requested Google Sheets spreadsheet with id {{config["spreadsheet_id"]}} does not exist.
Please ensure the Spreadsheet Link you have set is valid and the spreadsheet exists. If the issue persists, contact support
rate_limit:
type: HttpResponseFilter
action: RATE_LIMITED
http_codes:
- 429
error_message: >-
Rate limit has been
reached. Please try later or request a higher quota for your account.
single_sheet_response_error_filters:
- $ref: "#/definitions/response_filters/expected_one_sheet"
- $ref: "#/definitions/response_filters/ignore_duplicate_headers"
check_operation_single_sheet_response_error_filters:
- $ref: "#/definitions/response_filters/expected_one_sheet"
- $ref: "#/definitions/response_filters/fail_duplicate_headers"
response_error_filters:
- $ref: "#/definitions/response_filters/server_error"
- $ref: "#/definitions/response_filters/forbidden"
- $ref: "#/definitions/response_filters/not_found"
- $ref: "#/definitions/response_filters/rate_limit"
schema_type_identifier:
key_pointer:
- formattedValue
schema_pointer:
- values
jwt_authenticator:
type: JwtAuthenticator
secret_key: "{{ json_loads(config['credentials']['service_account_info'])['private_key'] }}"
algorithm: "RS256"
token_duration: 3600
jwt_payload:
aud: "{{ json_loads(config['credentials']['service_account_info'])['token_uri'] }}"
iss: "{{ json_loads(config['credentials']['service_account_info'])['client_email'] }}"
additional_jwt_payload:
scope: "https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/drive.readonly"
oauth_authenticator:
type: OAuthAuthenticator
refresh_request_body: {}
token_refresh_endpoint: https://www.googleapis.com/oauth2/v4/token
grant_type: refresh_token
client_id: '{{ config["credentials"]["client_id"] }}'
client_secret: '{{ config["credentials"]["client_secret"] }}'
refresh_token: '{{ config["credentials"]["refresh_token"] }}'
jwt_profile_assertion_oauth_authenticator:
type: OAuthAuthenticator
token_refresh_endpoint: https://oauth2.googleapis.com/token
refresh_request_headers:
Content-Type: application/x-www-form-urlencoded
use_profile_assertion: true
profile_assertion:
$ref: "#/definitions/jwt_authenticator"
authenticator:
type: SelectiveAuthenticator
authenticator_selection_path: ["credentials", "auth_type"]
authenticators:
Client: "#/definitions/oauth_authenticator"
Service: "#/definitions/jwt_profile_assertion_oauth_authenticator"
schemas:
sheets:
type: object
$schema: http://json-schema.org/schema#
additionalProperties: true
properties:
gridProperties:
type:
- object
- "null"
properties:
columnCount:
type:
- number
- "null"
rowCount:
type:
- number
- "null"
index:
type:
- number
- "null"
sheetId:
type:
- number
- "null"
sheetType:
type:
- string
- "null"
title:
type:
- string
- "null"
concurrency_level:
type: ConcurrencyLevel
default_concurrency: 1
max_concurrency: 1