dex-connector-google-forms 0.1.0__py3-none-any.whl
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.
- dex_connector_google_forms-0.1.0.dist-info/METADATA +54 -0
- dex_connector_google_forms-0.1.0.dist-info/RECORD +26 -0
- dex_connector_google_forms-0.1.0.dist-info/WHEEL +4 -0
- dex_connector_google_forms-0.1.0.dist-info/licenses/LICENSE +21 -0
- dex_connectors/google_forms/__init__.py +63 -0
- dex_connectors/google_forms/_generated/__init__.py +2 -0
- dex_connectors/google_forms/_generated/config.py +31 -0
- dex_connectors/google_forms/_generated/connection.py +241 -0
- dex_connectors/google_forms/_generated/definitions.py +75 -0
- dex_connectors/google_forms/_generated/mock.py +200 -0
- dex_connectors/google_forms/_generated/models.py +303 -0
- dex_connectors/google_forms/_generated/refresh.py +9 -0
- dex_connectors/google_forms/_generated/steps.py +187 -0
- dex_connectors/google_forms/_generated/timestamps.py +60 -0
- dex_connectors/google_forms/client.py +128 -0
- dex_connectors/google_forms/connection.py +23 -0
- dex_connectors/google_forms/conversion.py +326 -0
- dex_connectors/google_forms/definitions.py +16 -0
- dex_connectors/google_forms/dex-connector.json +125 -0
- dex_connectors/google_forms/formsmock/__init__.py +6 -0
- dex_connectors/google_forms/json_values.py +23 -0
- dex_connectors/google_forms/models.py +37 -0
- dex_connectors/google_forms/operations.py +357 -0
- dex_connectors/google_forms/py.typed +2 -0
- dex_connectors/google_forms/query_values.py +16 -0
- dex_connectors/google_forms/steps.py +7 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-google-forms
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dex-native Python connector for Google Forms
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Google Forms Python connector
|
|
14
|
+
|
|
15
|
+
The `dex-connector-google-forms` package implements `getForm`,
|
|
16
|
+
`listResponses`, and `getResponse` as Dex Query Steps. It uses the Google Forms
|
|
17
|
+
connection and authorization guidance in the [connector README](../README.md).
|
|
18
|
+
The package requires `dex-connectors-sdk==0.7.0`.
|
|
19
|
+
|
|
20
|
+
The runnable [response recorder](examples/response_recorder/flow.py) reads a
|
|
21
|
+
form, one page of responses, and one response by ID. Its
|
|
22
|
+
[Worker entrypoint](examples/response_recorder/worker.py) loads the static
|
|
23
|
+
`google-forms-intake` connection from Dex project configuration. Configure that
|
|
24
|
+
connection in Dex Web, then start the Worker with:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd connectors/google/forms/python
|
|
28
|
+
uv run python -m examples.response_recorder.worker
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
From this repository, verify Go-recorded provider behavior and Python package
|
|
32
|
+
checks with:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
make test-connector-conformance CONNECTOR_DIRECTORY=connectors/google/forms
|
|
36
|
+
uv run --project connectors/google/forms/python ruff check connectors/google/forms/python
|
|
37
|
+
uv run --project connectors/google/forms/python mypy --strict connectors/google/forms/python/src
|
|
38
|
+
uv run --project connectors/google/forms/python pytest connectors/google/forms/python/tests
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The [Dex integration test](examples/response_recorder/test_integration.py)
|
|
42
|
+
starts a real Worker and Flow against a local Dex service and an in-process
|
|
43
|
+
Forms stand-in. With `dexcli dev` listening on port 39650, run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:39650 \
|
|
47
|
+
uv run --project connectors/google/forms/python pytest \
|
|
48
|
+
connectors/google/forms/python/examples/response_recorder/test_integration.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The connector preserves RFC 3339 timestamps through nine fractional digits in
|
|
52
|
+
provider results, response filters, and Dex codec round trips. The local
|
|
53
|
+
integration test does not exercise live Google OAuth consent, form access, or
|
|
54
|
+
Forms API responses; those require a user-controlled Google connection.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
dex_connectors/google_forms/__init__.py,sha256=RmN_yKodJNXDeFXaNJht_WS9fLM9eUzKFwkuqCeWv3w,1518
|
|
2
|
+
dex_connectors/google_forms/client.py,sha256=Shc3UHXVFeRVLlAnVyDaevJ8QMUw6ETQfSBSwiw76ss,5098
|
|
3
|
+
dex_connectors/google_forms/connection.py,sha256=cealRNjy3b-KBqOx6UgBDdxYuBbZekct1st32fLxYwE,564
|
|
4
|
+
dex_connectors/google_forms/conversion.py,sha256=xXq-4ZpwbxhyUKHjvDr7kvOdomPyC0eIOIR5KwIw0Gw,12601
|
|
5
|
+
dex_connectors/google_forms/definitions.py,sha256=6uqUtaPvGWgE79eL9b7YFnOuEBswolWFqnF3ZMoA-Ts,483
|
|
6
|
+
dex_connectors/google_forms/dex-connector.json,sha256=cKOH4oQdcsLCDyrmzgGd4nBs9-G-WXwUnLzHK5POTaM,2877
|
|
7
|
+
dex_connectors/google_forms/json_values.py,sha256=Gbrjek_lu8d94b3lWzMR1FqThZkdv8SyfNCB_I0RPRQ,694
|
|
8
|
+
dex_connectors/google_forms/models.py,sha256=rTiy73TqC9FCxS00W0NWZN6_msfmrEEZF86ZhCp-3Q4,705
|
|
9
|
+
dex_connectors/google_forms/operations.py,sha256=dfNp6KKap4s5QXy92t2kQxr3lNwA68YHlGbOh1iDP9g,13317
|
|
10
|
+
dex_connectors/google_forms/py.typed,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
11
|
+
dex_connectors/google_forms/query_values.py,sha256=cfrwzNwYUSxfSDfJv5wiI2MCGeh-1hFU9W_yq985RGY,663
|
|
12
|
+
dex_connectors/google_forms/steps.py,sha256=R7jqa1nA6ET0klT-H3dvs2HfU4aJI8hfO5ZzK--k8zw,303
|
|
13
|
+
dex_connectors/google_forms/_generated/__init__.py,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
14
|
+
dex_connectors/google_forms/_generated/config.py,sha256=aDP0LmscW0SXoqdlC5heojngPXveYRKFxFgRGNK_8f4,848
|
|
15
|
+
dex_connectors/google_forms/_generated/connection.py,sha256=iFN-q8RjT7X9lAFGJX38QS5rJlc3KmwW0uI8tkymkhw,12752
|
|
16
|
+
dex_connectors/google_forms/_generated/definitions.py,sha256=2WUpjW6Q3hzt-ZQ4EKwyb3KLhnTOdbrv-Pq98zg44IY,3149
|
|
17
|
+
dex_connectors/google_forms/_generated/mock.py,sha256=K9cgc2g2hFospwUU-JUbPCbIoAnX_4uMt8i-zYQ0Xxs,11819
|
|
18
|
+
dex_connectors/google_forms/_generated/models.py,sha256=GifF8jiryCMmY-_ZrOZRrFbJNyfXl61zZ8ScjIqU78Y,17104
|
|
19
|
+
dex_connectors/google_forms/_generated/refresh.py,sha256=Px7q1fIK3ks-DglxzDNqiEiY89Q6nh7U-0vCc6wOzY4,2650
|
|
20
|
+
dex_connectors/google_forms/_generated/steps.py,sha256=CNufLS-usZxV3VgtbjoYojWv-FtvkSYvrox88zEHvRY,8375
|
|
21
|
+
dex_connectors/google_forms/_generated/timestamps.py,sha256=Z8VwrE60w-33InIMgEMLiMPTFyRjj6oBq8tUro8Ssi8,3164
|
|
22
|
+
dex_connectors/google_forms/formsmock/__init__.py,sha256=sEODfqQ6BJ0_cxRmH7FUHlzuhGC26jntpGD0cmUtm_U,167
|
|
23
|
+
dex_connector_google_forms-0.1.0.dist-info/METADATA,sha256=aoaSkboYfk8uWn__fwFilgQwBR2w2BskPnXucyLK98s,2258
|
|
24
|
+
dex_connector_google_forms-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
25
|
+
dex_connector_google_forms-0.1.0.dist-info/licenses/LICENSE,sha256=WNj87Zd5micrAShl1LujOPM6PDzDqjlNLrryDZ4hE0M,1070
|
|
26
|
+
dex_connector_google_forms-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Google Forms Query operations for Python Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials
|
|
6
|
+
from .connection import Connection, new_connection, new_project_connection
|
|
7
|
+
from .definitions import (
|
|
8
|
+
CONNECTOR_ID,
|
|
9
|
+
GET_FORM_DEFINITION,
|
|
10
|
+
GET_RESPONSE_DEFINITION,
|
|
11
|
+
LIST_RESPONSES_DEFINITION,
|
|
12
|
+
)
|
|
13
|
+
from .models import (
|
|
14
|
+
Form,
|
|
15
|
+
FormAnswer,
|
|
16
|
+
FormAnswerFile,
|
|
17
|
+
FormAnswerGrade,
|
|
18
|
+
FormChoice,
|
|
19
|
+
FormItem,
|
|
20
|
+
FormPublishState,
|
|
21
|
+
FormQuestion,
|
|
22
|
+
FormResponse,
|
|
23
|
+
FormScale,
|
|
24
|
+
GetFormInput,
|
|
25
|
+
GetResponseInput,
|
|
26
|
+
ListResponsesInput,
|
|
27
|
+
ResponsePage,
|
|
28
|
+
)
|
|
29
|
+
from .operations import GetFormOperation, GetResponseOperation, ListResponsesOperation
|
|
30
|
+
from .steps import new_get_form_step, new_get_response_step, new_list_responses_step
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"Client",
|
|
34
|
+
"Config",
|
|
35
|
+
"Credentials",
|
|
36
|
+
"Connection",
|
|
37
|
+
"new_connection",
|
|
38
|
+
"new_project_connection",
|
|
39
|
+
"CONNECTOR_ID",
|
|
40
|
+
"GET_FORM_DEFINITION",
|
|
41
|
+
"GET_RESPONSE_DEFINITION",
|
|
42
|
+
"LIST_RESPONSES_DEFINITION",
|
|
43
|
+
"Form",
|
|
44
|
+
"FormAnswer",
|
|
45
|
+
"FormAnswerFile",
|
|
46
|
+
"FormAnswerGrade",
|
|
47
|
+
"FormChoice",
|
|
48
|
+
"FormItem",
|
|
49
|
+
"FormPublishState",
|
|
50
|
+
"FormQuestion",
|
|
51
|
+
"FormResponse",
|
|
52
|
+
"FormScale",
|
|
53
|
+
"GetFormInput",
|
|
54
|
+
"GetResponseInput",
|
|
55
|
+
"ListResponsesInput",
|
|
56
|
+
"ResponsePage",
|
|
57
|
+
"GetFormOperation",
|
|
58
|
+
"GetResponseOperation",
|
|
59
|
+
"ListResponsesOperation",
|
|
60
|
+
"new_get_form_step",
|
|
61
|
+
"new_get_response_step",
|
|
62
|
+
"new_list_responses_step",
|
|
63
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
endpoint: str = "https://forms.googleapis.com"
|
|
14
|
+
max_response_bytes: int = 1048576
|
|
15
|
+
response_page_size: int = 50
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.google_forms.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
auth_method_id: str = "google-oauth"
|
|
24
|
+
oauth_client_id: str | None = None
|
|
25
|
+
oauth_client_secret: SecretString | None = None
|
|
26
|
+
access_token: SecretString | None = None
|
|
27
|
+
refresh_token: SecretString | None = None
|
|
28
|
+
service_account_key: SecretString | None = None
|
|
29
|
+
delegated_user: str | None = None
|
|
30
|
+
|
|
31
|
+
setattr(Credentials, '__module__', 'dex_connectors.google_forms.client')
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Query, Call, SecretString, CredentialRefreshDriver
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
from dex_connectors.sdk.projectconfig.provider import RefreshingCredentialProvider
|
|
11
|
+
from dex_connectors.sdk.oauthtoken import ManifestCredentialRefreshDriver
|
|
12
|
+
|
|
13
|
+
from ..client import Client, Config, Credentials
|
|
14
|
+
from .definitions import CONNECTOR_ID, PROVIDER, GET_FORM_DEFINITION, GET_RESPONSE_DEFINITION, LIST_RESPONSES_DEFINITION
|
|
15
|
+
from .refresh import AUTHORIZATION, CREDENTIAL_FIELDS
|
|
16
|
+
from ..models import Form, FormResponse, GetFormInput, GetResponseInput, ListResponsesInput, ResponsePage
|
|
17
|
+
|
|
18
|
+
class Connection:
|
|
19
|
+
|
|
20
|
+
__slots__ = ('_get_form', '_list_responses', '_get_response', '_client', 'reference')
|
|
21
|
+
|
|
22
|
+
def __init__(self,
|
|
23
|
+
reference: ConnectionRef,
|
|
24
|
+
get_form: Query[GetFormInput, Form],
|
|
25
|
+
list_responses: Query[ListResponsesInput, ResponsePage],
|
|
26
|
+
get_response: Query[GetResponseInput, FormResponse],
|
|
27
|
+
client: Client | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
reference.validate()
|
|
30
|
+
if reference.provider != PROVIDER or get_form is None or list_responses is None or get_response is None:
|
|
31
|
+
raise ValueError("Google Forms connection provider and operations are required")
|
|
32
|
+
if get_form.definition().operation != GET_FORM_DEFINITION.operation:
|
|
33
|
+
raise ValueError("Google Forms connection operation identity differs")
|
|
34
|
+
if list_responses.definition().operation != LIST_RESPONSES_DEFINITION.operation:
|
|
35
|
+
raise ValueError("Google Forms connection operation identity differs")
|
|
36
|
+
if get_response.definition().operation != GET_RESPONSE_DEFINITION.operation:
|
|
37
|
+
raise ValueError("Google Forms connection operation identity differs")
|
|
38
|
+
self.reference = reference
|
|
39
|
+
self._get_form = get_form
|
|
40
|
+
self._list_responses = list_responses
|
|
41
|
+
self._get_response = get_response
|
|
42
|
+
self._client = client
|
|
43
|
+
|
|
44
|
+
def get_form(self) -> Query[GetFormInput, Form]:
|
|
45
|
+
return self._get_form
|
|
46
|
+
|
|
47
|
+
def list_responses(self) -> Query[ListResponsesInput, ResponsePage]:
|
|
48
|
+
return self._list_responses
|
|
49
|
+
|
|
50
|
+
def get_response(self) -> Query[GetResponseInput, FormResponse]:
|
|
51
|
+
return self._get_response
|
|
52
|
+
|
|
53
|
+
async def aclose(self) -> None:
|
|
54
|
+
if self._client is not None:
|
|
55
|
+
await self._client.aclose()
|
|
56
|
+
|
|
57
|
+
def __repr__(self) -> str:
|
|
58
|
+
return "google_forms.Connection([REDACTED])"
|
|
59
|
+
|
|
60
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
61
|
+
raise TypeError("Google Forms connections cannot be serialized")
|
|
62
|
+
|
|
63
|
+
setattr(Connection, '__module__', 'dex_connectors.google_forms.connection')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
67
|
+
if client is None:
|
|
68
|
+
raise ValueError("Google Forms client is required")
|
|
69
|
+
return Connection(reference, client.get_form(), client.list_responses(), client.get_response(), client)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection, '__module__', 'dex_connectors.google_forms.connection')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def new_connection_with_operations(
|
|
75
|
+
get_form: Query[GetFormInput, Form],
|
|
76
|
+
list_responses: Query[ListResponsesInput, ResponsePage],
|
|
77
|
+
get_response: Query[GetResponseInput, FormResponse],
|
|
78
|
+
reference: ConnectionRef,
|
|
79
|
+
) -> Connection:
|
|
80
|
+
return Connection(reference, get_form, list_responses, get_response)
|
|
81
|
+
|
|
82
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.google_forms.connection')
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
|
|
86
|
+
if not isinstance(material, dict):
|
|
87
|
+
raise ValueError("Google Forms stored credential does not match the connector credential fields")
|
|
88
|
+
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token', 'service_account_key', 'delegated_user', 'auth_method')):
|
|
89
|
+
raise ValueError("Google Forms stored credential does not match the connector credential fields")
|
|
90
|
+
is_shared = shared
|
|
91
|
+
oauth_client_id = material.get("oauth_client_id")
|
|
92
|
+
if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
|
|
93
|
+
raise ValueError("Google Forms credential oauth_client_id has an invalid type")
|
|
94
|
+
oauth_client_secret = material.get("oauth_client_secret")
|
|
95
|
+
if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
|
|
96
|
+
raise ValueError("Google Forms credential oauth_client_secret has an invalid type")
|
|
97
|
+
access_token = material.get("access_token")
|
|
98
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
99
|
+
raise ValueError("Google Forms credential access_token has an invalid type")
|
|
100
|
+
refresh_token = material.get("refresh_token")
|
|
101
|
+
if refresh_token is not None and not (isinstance(refresh_token, str)):
|
|
102
|
+
raise ValueError("Google Forms credential refresh_token has an invalid type")
|
|
103
|
+
service_account_key = material.get("service_account_key")
|
|
104
|
+
if service_account_key is not None and not (isinstance(service_account_key, str)):
|
|
105
|
+
raise ValueError("Google Forms credential service_account_key has an invalid type")
|
|
106
|
+
delegated_user = material.get("delegated_user")
|
|
107
|
+
if delegated_user is not None and not (isinstance(delegated_user, str)):
|
|
108
|
+
raise ValueError("Google Forms credential delegated_user has an invalid type")
|
|
109
|
+
selected_method = material.get('auth_method')
|
|
110
|
+
if selected_method is None:
|
|
111
|
+
selected_method = ''
|
|
112
|
+
if not isinstance(selected_method, str):
|
|
113
|
+
raise ValueError("Google Forms credential auth_method is invalid")
|
|
114
|
+
method = selected_method or "google-oauth"
|
|
115
|
+
values: dict[str, Any] = {'auth_method_id': method}
|
|
116
|
+
if method == "google-oauth":
|
|
117
|
+
if not oauth_client_id:
|
|
118
|
+
raise ValueError("Google Forms credential oauth_client_id is required")
|
|
119
|
+
if oauth_client_id:
|
|
120
|
+
values["oauth_client_id"] = oauth_client_id
|
|
121
|
+
if not oauth_client_secret and not is_shared:
|
|
122
|
+
raise ValueError("Google Forms credential oauth_client_secret is required")
|
|
123
|
+
if oauth_client_secret:
|
|
124
|
+
values["oauth_client_secret"] = SecretString(oauth_client_secret)
|
|
125
|
+
if not access_token:
|
|
126
|
+
raise ValueError("Google Forms credential access_token is required")
|
|
127
|
+
if access_token:
|
|
128
|
+
values["access_token"] = SecretString(access_token)
|
|
129
|
+
if not refresh_token and not is_shared:
|
|
130
|
+
raise ValueError("Google Forms credential refresh_token is required")
|
|
131
|
+
if refresh_token:
|
|
132
|
+
values["refresh_token"] = SecretString(refresh_token)
|
|
133
|
+
elif method == "workspace-domain-delegation":
|
|
134
|
+
if not service_account_key and not is_shared:
|
|
135
|
+
raise ValueError("Google Forms credential service_account_key is required")
|
|
136
|
+
if service_account_key:
|
|
137
|
+
values["service_account_key"] = SecretString(service_account_key)
|
|
138
|
+
if not delegated_user:
|
|
139
|
+
raise ValueError("Google Forms credential delegated_user is required")
|
|
140
|
+
if delegated_user:
|
|
141
|
+
values["delegated_user"] = delegated_user
|
|
142
|
+
if not access_token and is_shared:
|
|
143
|
+
raise ValueError("Google Forms credential access_token is required")
|
|
144
|
+
values["access_token"] = SecretString(access_token or '')
|
|
145
|
+
else:
|
|
146
|
+
raise ValueError("Google Forms credential auth_method is invalid")
|
|
147
|
+
return Credentials(**values)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
151
|
+
return decode_credentials(material, shared=True)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def encode_credentials(credentials: Credentials) -> dict[str, Any]:
|
|
155
|
+
material: dict[str, Any] = {}
|
|
156
|
+
method = credentials.auth_method_id or "google-oauth"
|
|
157
|
+
material['auth_method'] = method
|
|
158
|
+
if method == "google-oauth":
|
|
159
|
+
if credentials.oauth_client_id:
|
|
160
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
161
|
+
if (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else ''):
|
|
162
|
+
material["oauth_client_secret"] = (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else '')
|
|
163
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
164
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
165
|
+
if (credentials.refresh_token.reveal() if credentials.refresh_token is not None else ''):
|
|
166
|
+
material["refresh_token"] = (credentials.refresh_token.reveal() if credentials.refresh_token is not None else '')
|
|
167
|
+
elif method == "workspace-domain-delegation":
|
|
168
|
+
if (credentials.service_account_key.reveal() if credentials.service_account_key is not None else ''):
|
|
169
|
+
material["service_account_key"] = (credentials.service_account_key.reveal() if credentials.service_account_key is not None else '')
|
|
170
|
+
if credentials.delegated_user:
|
|
171
|
+
material["delegated_user"] = credentials.delegated_user
|
|
172
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
173
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
174
|
+
else:
|
|
175
|
+
raise ValueError("Google Forms credential auth_method is invalid")
|
|
176
|
+
decode_credentials(material)
|
|
177
|
+
return material
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class _ProjectCredentialSource:
|
|
181
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey, http_client: httpx.AsyncClient, settings: dict[str, Any]) -> None:
|
|
182
|
+
self.provider = RefreshingCredentialProvider(
|
|
183
|
+
project.connections, key, decode_credentials, encode_credentials, decode_shared_credentials
|
|
184
|
+
)
|
|
185
|
+
self.driver = ManifestCredentialRefreshDriver[Credentials]("Google Forms", AUTHORIZATION, CREDENTIAL_FIELDS, http_client, settings=settings)
|
|
186
|
+
|
|
187
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
188
|
+
return await self.provider.resolve_with_refresh(call, self.driver)
|
|
189
|
+
|
|
190
|
+
async def resolve_with_refresh(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
191
|
+
return await self.provider.resolve_with_refresh(call, driver or self.driver)
|
|
192
|
+
|
|
193
|
+
async def resolve_after_rejection(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
194
|
+
return await self.provider.resolve_after_rejection(call, driver or self.driver)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def new_project_connection(
|
|
198
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
199
|
+
) -> Connection:
|
|
200
|
+
if project is None:
|
|
201
|
+
raise ValueError("Google Forms connection requires loaded project configuration")
|
|
202
|
+
reference = ConnectionRef(PROVIDER, connection_name)
|
|
203
|
+
reference.validate()
|
|
204
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
205
|
+
matching = [
|
|
206
|
+
entry
|
|
207
|
+
for entry in project.configuration.connections
|
|
208
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
209
|
+
]
|
|
210
|
+
if len(matching) != 1:
|
|
211
|
+
raise ValueError("Google Forms project connection is missing or duplicated")
|
|
212
|
+
if matching[0].provider != PROVIDER:
|
|
213
|
+
raise ValueError("Google Forms project connection provider differs")
|
|
214
|
+
config = _decode_config(matching[0].configuration)
|
|
215
|
+
http_client = http_client or httpx.AsyncClient()
|
|
216
|
+
client = Client(config, _ProjectCredentialSource(project, key, http_client, matching[0].configuration), http_client)
|
|
217
|
+
return new_connection(client, reference)
|
|
218
|
+
|
|
219
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.google_forms.connection')
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
223
|
+
if set(value) - {"endpoint", "maxResponseBytes", "responsePageSize"}:
|
|
224
|
+
raise ValueError("Google Forms configuration has unknown fields")
|
|
225
|
+
config_arguments: dict[str, Any] = {}
|
|
226
|
+
if "endpoint" in value:
|
|
227
|
+
endpoint = value["endpoint"]
|
|
228
|
+
if not (isinstance(endpoint, str)):
|
|
229
|
+
raise ValueError("Google Forms configuration endpoint has an invalid type")
|
|
230
|
+
config_arguments['endpoint'] = endpoint
|
|
231
|
+
if "maxResponseBytes" in value:
|
|
232
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
233
|
+
if not (type(max_response_bytes) is int):
|
|
234
|
+
raise ValueError("Google Forms configuration maxResponseBytes has an invalid type")
|
|
235
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
236
|
+
if "responsePageSize" in value:
|
|
237
|
+
response_page_size = value["responsePageSize"]
|
|
238
|
+
if not (type(response_page_size) is int):
|
|
239
|
+
raise ValueError("Google Forms configuration responsePageSize has an invalid type")
|
|
240
|
+
config_arguments['response_page_size'] = response_page_size
|
|
241
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "google-forms"
|
|
18
|
+
PROVIDER = "google"
|
|
19
|
+
GET_FORM_OPERATION_ID = "getForm"
|
|
20
|
+
LIST_RESPONSES_OPERATION_ID = "listResponses"
|
|
21
|
+
GET_RESPONSE_OPERATION_ID = "getResponse"
|
|
22
|
+
DEFECT = "defect"
|
|
23
|
+
FOUND = "found"
|
|
24
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
25
|
+
LISTED = "listed"
|
|
26
|
+
NOT_FOUND = "notFound"
|
|
27
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
28
|
+
|
|
29
|
+
GET_FORM_DEFINITION = QueryDefinition(
|
|
30
|
+
OperationRef(CONNECTOR_ID, GET_FORM_OPERATION_ID),
|
|
31
|
+
(
|
|
32
|
+
BranchDefinition(FOUND, "Google Forms returned the form.", False),
|
|
33
|
+
BranchDefinition(NOT_FOUND, "The form does not exist or the connection cannot see it.", True),
|
|
34
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the read, such as a revoked grant or an account that cannot open the form.", True),
|
|
35
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized form.", True),
|
|
36
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
37
|
+
),
|
|
38
|
+
StepDefaults(
|
|
39
|
+
timedelta(seconds=30),
|
|
40
|
+
2,
|
|
41
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
LIST_RESPONSES_DEFINITION = QueryDefinition(
|
|
46
|
+
OperationRef(CONNECTOR_ID, LIST_RESPONSES_OPERATION_ID),
|
|
47
|
+
(
|
|
48
|
+
BranchDefinition(LISTED, "Google Forms returned one page of responses, which can be empty.", False),
|
|
49
|
+
BranchDefinition(NOT_FOUND, "The form does not exist or the connection cannot see it.", True),
|
|
50
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the listing, such as an account that cannot read the form's responses or an expired page token.", True),
|
|
51
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized page of responses.", True),
|
|
52
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
53
|
+
),
|
|
54
|
+
StepDefaults(
|
|
55
|
+
timedelta(seconds=30),
|
|
56
|
+
2,
|
|
57
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
GET_RESPONSE_DEFINITION = QueryDefinition(
|
|
62
|
+
OperationRef(CONNECTOR_ID, GET_RESPONSE_OPERATION_ID),
|
|
63
|
+
(
|
|
64
|
+
BranchDefinition(FOUND, "Google Forms returned the response.", False),
|
|
65
|
+
BranchDefinition(NOT_FOUND, "The form or the response does not exist or the connection cannot see it.", True),
|
|
66
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the read, such as an account that cannot read the form's responses.", True),
|
|
67
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized response record.", True),
|
|
68
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
69
|
+
),
|
|
70
|
+
StepDefaults(
|
|
71
|
+
timedelta(seconds=30),
|
|
72
|
+
2,
|
|
73
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
74
|
+
),
|
|
75
|
+
)
|