dex-connector-google-docs 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_docs-0.1.0.dist-info/METADATA +25 -0
- dex_connector_google_docs-0.1.0.dist-info/RECORD +25 -0
- dex_connector_google_docs-0.1.0.dist-info/WHEEL +4 -0
- dex_connector_google_docs-0.1.0.dist-info/licenses/LICENSE +21 -0
- dex_connectors/google_docs/__init__.py +50 -0
- dex_connectors/google_docs/_generated/__init__.py +2 -0
- dex_connectors/google_docs/_generated/config.py +32 -0
- dex_connectors/google_docs/_generated/connection.py +254 -0
- dex_connectors/google_docs/_generated/definitions.py +102 -0
- dex_connectors/google_docs/_generated/mock.py +323 -0
- dex_connectors/google_docs/_generated/models.py +211 -0
- dex_connectors/google_docs/_generated/refresh.py +9 -0
- dex_connectors/google_docs/_generated/steps.py +255 -0
- dex_connectors/google_docs/_generated/timestamps.py +60 -0
- dex_connectors/google_docs/client.py +271 -0
- dex_connectors/google_docs/connection.py +12 -0
- dex_connectors/google_docs/create.py +547 -0
- dex_connectors/google_docs/dex-connector.json +183 -0
- dex_connectors/google_docs/docsmock/__init__.py +6 -0
- dex_connectors/google_docs/document.py +222 -0
- dex_connectors/google_docs/json_values.py +23 -0
- dex_connectors/google_docs/models.py +31 -0
- dex_connectors/google_docs/operations.py +630 -0
- dex_connectors/google_docs/query_values.py +16 -0
- dex_connectors/google_docs/steps.py +17 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-google-docs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dex-native Google Docs connector
|
|
5
|
+
Project-URL: Source, https://github.com/superdurable/dex-connectors-library/tree/main/connectors/google/docs/python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
10
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
11
|
+
Requires-Dist: httpx>=0.27
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Google Docs Python connector
|
|
15
|
+
|
|
16
|
+
Dex-native Google Docs operations, with operation-specific Step factories for
|
|
17
|
+
`getDocumentText`, `createDocument`, `replaceDocumentText`, and `appendText`.
|
|
18
|
+
The package requires Connector SDK 0.7.0. Use `new_project_connection` for the
|
|
19
|
+
generated Google OAuth or Workspace domain delegation credential refresh wiring.
|
|
20
|
+
Provider creation timestamps must be valid Go JSON timestamps; invalid values
|
|
21
|
+
fail before a document Result is stored.
|
|
22
|
+
|
|
23
|
+
The [policy read example](examples/policy_read/README.md) shows the static
|
|
24
|
+
connection name, FDG generation, Worker, and Flow starter. See the
|
|
25
|
+
[parent connector README](../README.md) for authorization and operation guidance.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
dex_connectors/google_docs/__init__.py,sha256=Y_vw5mGcetJ1tARjxa_YgKkwKIzjh3mLRqcEfP6Z4_E,1368
|
|
2
|
+
dex_connectors/google_docs/client.py,sha256=oRKzdmgTbKFefUOEc4G-sTCcLEe7emmY7a6j8-aaE-w,10663
|
|
3
|
+
dex_connectors/google_docs/connection.py,sha256=Qe6ULbMNIyuRuv5hcnneSruDr1GxFXj2oLfKHi-E7TU,369
|
|
4
|
+
dex_connectors/google_docs/create.py,sha256=85zT6tPC84MM0vIauNINz8ygZs6IFoPKs4aRndTXrEU,20610
|
|
5
|
+
dex_connectors/google_docs/dex-connector.json,sha256=SP_yJhGMPMZOeUzvCzTf3lKjoHd99AUxm3Z6MgoHOGs,4299
|
|
6
|
+
dex_connectors/google_docs/document.py,sha256=EYeHb64THO1IvZrLKRkgS1LU5iDqWrHULYSrk-eEWpQ,10417
|
|
7
|
+
dex_connectors/google_docs/json_values.py,sha256=Gbrjek_lu8d94b3lWzMR1FqThZkdv8SyfNCB_I0RPRQ,694
|
|
8
|
+
dex_connectors/google_docs/models.py,sha256=llntaOlpr7TUeE2vvZh58JC46wCHbBA9_vYUHYFfe_s,760
|
|
9
|
+
dex_connectors/google_docs/operations.py,sha256=eLzM5MR3nYv51V1sOzCTB2ve3m2BXIx2UfBo7wOqJKU,25724
|
|
10
|
+
dex_connectors/google_docs/query_values.py,sha256=cfrwzNwYUSxfSDfJv5wiI2MCGeh-1hFU9W_yq985RGY,663
|
|
11
|
+
dex_connectors/google_docs/steps.py,sha256=38F5ISkQRnSkXAoKuPfSRGYuPAhst7U9ziGfATSWBsA,427
|
|
12
|
+
dex_connectors/google_docs/_generated/__init__.py,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
13
|
+
dex_connectors/google_docs/_generated/config.py,sha256=7Uqnk1omLHCdYO2oIsVwlsrQ87vqu8z42NlYriAyUqI,906
|
|
14
|
+
dex_connectors/google_docs/_generated/connection.py,sha256=GjozLro627MJdoQUjGaGr6geEbtLVAFpM7__sfHRUmU,14088
|
|
15
|
+
dex_connectors/google_docs/_generated/definitions.py,sha256=rZ2vmTa-DGYmnguxQ8X2c_7mp1EppjZqiaT-Vzyp3_4,5218
|
|
16
|
+
dex_connectors/google_docs/_generated/mock.py,sha256=4u94YOYsGW22fwhrgJHEV5fnzRBqANDlBwJ2MGwb4KA,19367
|
|
17
|
+
dex_connectors/google_docs/_generated/models.py,sha256=1JoNDncu5OR7Yymuyrk-B8JwlJLlUsFHeHZ4XuLVnkU,11718
|
|
18
|
+
dex_connectors/google_docs/_generated/refresh.py,sha256=tspbgt8HuvFfzAL3GtFSTorOAMMG55Z9UwElZxC-Eg8,2602
|
|
19
|
+
dex_connectors/google_docs/_generated/steps.py,sha256=mdzA_0W6PkqQfFb26ZJrb79oDXwdR0cMMWfz4ixdO5M,12243
|
|
20
|
+
dex_connectors/google_docs/_generated/timestamps.py,sha256=Z8VwrE60w-33InIMgEMLiMPTFyRjj6oBq8tUro8Ssi8,3164
|
|
21
|
+
dex_connectors/google_docs/docsmock/__init__.py,sha256=sEODfqQ6BJ0_cxRmH7FUHlzuhGC26jntpGD0cmUtm_U,167
|
|
22
|
+
dex_connector_google_docs-0.1.0.dist-info/METADATA,sha256=hZllwUj1-OHDAtXJZlVgVHxBRpP5S29Y2EwCrXK-pXE,1136
|
|
23
|
+
dex_connector_google_docs-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
24
|
+
dex_connector_google_docs-0.1.0.dist-info/licenses/LICENSE,sha256=WNj87Zd5micrAShl1LujOPM6PDzDqjlNLrryDZ4hE0M,1070
|
|
25
|
+
dex_connector_google_docs-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,50 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Dex-native Google Docs provider operations and Step factories."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials
|
|
6
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
7
|
+
from .models import (
|
|
8
|
+
AppendTextInput,
|
|
9
|
+
AppendTextOutput,
|
|
10
|
+
CreatedDocument,
|
|
11
|
+
CreateDocumentInput,
|
|
12
|
+
CreateDocumentOutput,
|
|
13
|
+
GetDocumentTextInput,
|
|
14
|
+
GetDocumentTextOutput,
|
|
15
|
+
PlaceholderReplacement,
|
|
16
|
+
PlaceholderReplacementResult,
|
|
17
|
+
ReplaceDocumentTextInput,
|
|
18
|
+
ReplaceDocumentTextOutput,
|
|
19
|
+
)
|
|
20
|
+
from .steps import (
|
|
21
|
+
new_append_text_step,
|
|
22
|
+
new_create_document_step,
|
|
23
|
+
new_get_document_text_step,
|
|
24
|
+
new_replace_document_text_step,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"Client",
|
|
29
|
+
"Config",
|
|
30
|
+
"Credentials",
|
|
31
|
+
"Connection",
|
|
32
|
+
"new_connection",
|
|
33
|
+
"new_connection_with_operations",
|
|
34
|
+
"new_project_connection",
|
|
35
|
+
"AppendTextInput",
|
|
36
|
+
"AppendTextOutput",
|
|
37
|
+
"CreatedDocument",
|
|
38
|
+
"CreateDocumentInput",
|
|
39
|
+
"CreateDocumentOutput",
|
|
40
|
+
"GetDocumentTextInput",
|
|
41
|
+
"GetDocumentTextOutput",
|
|
42
|
+
"PlaceholderReplacement",
|
|
43
|
+
"PlaceholderReplacementResult",
|
|
44
|
+
"ReplaceDocumentTextInput",
|
|
45
|
+
"ReplaceDocumentTextOutput",
|
|
46
|
+
"new_append_text_step",
|
|
47
|
+
"new_create_document_step",
|
|
48
|
+
"new_get_document_text_step",
|
|
49
|
+
"new_replace_document_text_step",
|
|
50
|
+
]
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
docs_endpoint: str = "https://docs.googleapis.com"
|
|
14
|
+
drive_endpoint: str = "https://www.googleapis.com"
|
|
15
|
+
max_response_bytes: int = 8388608
|
|
16
|
+
max_text_bytes: int = 1048576
|
|
17
|
+
|
|
18
|
+
setattr(Config, '__module__', 'dex_connectors.google_docs.client')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True, slots=True)
|
|
22
|
+
class Credentials:
|
|
23
|
+
|
|
24
|
+
auth_method_id: str = "google-oauth"
|
|
25
|
+
oauth_client_id: str | None = None
|
|
26
|
+
oauth_client_secret: SecretString | None = None
|
|
27
|
+
access_token: SecretString | None = None
|
|
28
|
+
refresh_token: SecretString | None = None
|
|
29
|
+
service_account_key: SecretString | None = None
|
|
30
|
+
delegated_user: str | None = None
|
|
31
|
+
|
|
32
|
+
setattr(Credentials, '__module__', 'dex_connectors.google_docs.client')
|
|
@@ -0,0 +1,254 @@
|
|
|
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, Mutation, 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, APPEND_TEXT_DEFINITION, CREATE_DOCUMENT_DEFINITION, GET_DOCUMENT_TEXT_DEFINITION, REPLACE_DOCUMENT_TEXT_DEFINITION
|
|
15
|
+
from .refresh import AUTHORIZATION, CREDENTIAL_FIELDS
|
|
16
|
+
from ..models import AppendTextInput, AppendTextOutput, CreateDocumentInput, CreateDocumentOutput, GetDocumentTextInput, GetDocumentTextOutput, ReplaceDocumentTextInput, ReplaceDocumentTextOutput
|
|
17
|
+
|
|
18
|
+
class Connection:
|
|
19
|
+
|
|
20
|
+
__slots__ = ('_get_document_text', '_create_document', '_replace_document_text', '_append_text', '_client', 'reference')
|
|
21
|
+
|
|
22
|
+
def __init__(self,
|
|
23
|
+
reference: ConnectionRef,
|
|
24
|
+
get_document_text: Query[GetDocumentTextInput, GetDocumentTextOutput],
|
|
25
|
+
create_document: Mutation[CreateDocumentInput, CreateDocumentOutput],
|
|
26
|
+
replace_document_text: Mutation[ReplaceDocumentTextInput, ReplaceDocumentTextOutput],
|
|
27
|
+
append_text: Mutation[AppendTextInput, AppendTextOutput],
|
|
28
|
+
client: Client | None = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
reference.validate()
|
|
31
|
+
if reference.provider != PROVIDER or get_document_text is None or create_document is None or replace_document_text is None or append_text is None:
|
|
32
|
+
raise ValueError("Google Docs connection provider and operations are required")
|
|
33
|
+
if get_document_text.definition().operation != GET_DOCUMENT_TEXT_DEFINITION.operation:
|
|
34
|
+
raise ValueError("Google Docs connection operation identity differs")
|
|
35
|
+
if create_document.definition().operation != CREATE_DOCUMENT_DEFINITION.operation:
|
|
36
|
+
raise ValueError("Google Docs connection operation identity differs")
|
|
37
|
+
if replace_document_text.definition().operation != REPLACE_DOCUMENT_TEXT_DEFINITION.operation:
|
|
38
|
+
raise ValueError("Google Docs connection operation identity differs")
|
|
39
|
+
if append_text.definition().operation != APPEND_TEXT_DEFINITION.operation:
|
|
40
|
+
raise ValueError("Google Docs connection operation identity differs")
|
|
41
|
+
self.reference = reference
|
|
42
|
+
self._get_document_text = get_document_text
|
|
43
|
+
self._create_document = create_document
|
|
44
|
+
self._replace_document_text = replace_document_text
|
|
45
|
+
self._append_text = append_text
|
|
46
|
+
self._client = client
|
|
47
|
+
|
|
48
|
+
def get_document_text(self) -> Query[GetDocumentTextInput, GetDocumentTextOutput]:
|
|
49
|
+
return self._get_document_text
|
|
50
|
+
|
|
51
|
+
def create_document(self) -> Mutation[CreateDocumentInput, CreateDocumentOutput]:
|
|
52
|
+
return self._create_document
|
|
53
|
+
|
|
54
|
+
def replace_document_text(self) -> Mutation[ReplaceDocumentTextInput, ReplaceDocumentTextOutput]:
|
|
55
|
+
return self._replace_document_text
|
|
56
|
+
|
|
57
|
+
def append_text(self) -> Mutation[AppendTextInput, AppendTextOutput]:
|
|
58
|
+
return self._append_text
|
|
59
|
+
|
|
60
|
+
async def aclose(self) -> None:
|
|
61
|
+
if self._client is not None:
|
|
62
|
+
await self._client.aclose()
|
|
63
|
+
|
|
64
|
+
def __repr__(self) -> str:
|
|
65
|
+
return "google_docs.Connection([REDACTED])"
|
|
66
|
+
|
|
67
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
68
|
+
raise TypeError("Google Docs connections cannot be serialized")
|
|
69
|
+
|
|
70
|
+
setattr(Connection, '__module__', 'dex_connectors.google_docs.connection')
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
74
|
+
if client is None:
|
|
75
|
+
raise ValueError("Google Docs client is required")
|
|
76
|
+
return Connection(reference, client.get_document_text(), client.create_document(), client.replace_document_text(), client.append_text(), client)
|
|
77
|
+
|
|
78
|
+
setattr(new_connection, '__module__', 'dex_connectors.google_docs.connection')
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def new_connection_with_operations(
|
|
82
|
+
get_document_text: Query[GetDocumentTextInput, GetDocumentTextOutput],
|
|
83
|
+
create_document: Mutation[CreateDocumentInput, CreateDocumentOutput],
|
|
84
|
+
replace_document_text: Mutation[ReplaceDocumentTextInput, ReplaceDocumentTextOutput],
|
|
85
|
+
append_text: Mutation[AppendTextInput, AppendTextOutput],
|
|
86
|
+
reference: ConnectionRef,
|
|
87
|
+
) -> Connection:
|
|
88
|
+
return Connection(reference, get_document_text, create_document, replace_document_text, append_text)
|
|
89
|
+
|
|
90
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.google_docs.connection')
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
|
|
94
|
+
if not isinstance(material, dict):
|
|
95
|
+
raise ValueError("Google Docs stored credential does not match the connector credential fields")
|
|
96
|
+
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token', 'service_account_key', 'delegated_user', 'auth_method')):
|
|
97
|
+
raise ValueError("Google Docs stored credential does not match the connector credential fields")
|
|
98
|
+
is_shared = shared
|
|
99
|
+
oauth_client_id = material.get("oauth_client_id")
|
|
100
|
+
if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
|
|
101
|
+
raise ValueError("Google Docs credential oauth_client_id has an invalid type")
|
|
102
|
+
oauth_client_secret = material.get("oauth_client_secret")
|
|
103
|
+
if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
|
|
104
|
+
raise ValueError("Google Docs credential oauth_client_secret has an invalid type")
|
|
105
|
+
access_token = material.get("access_token")
|
|
106
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
107
|
+
raise ValueError("Google Docs credential access_token has an invalid type")
|
|
108
|
+
refresh_token = material.get("refresh_token")
|
|
109
|
+
if refresh_token is not None and not (isinstance(refresh_token, str)):
|
|
110
|
+
raise ValueError("Google Docs credential refresh_token has an invalid type")
|
|
111
|
+
service_account_key = material.get("service_account_key")
|
|
112
|
+
if service_account_key is not None and not (isinstance(service_account_key, str)):
|
|
113
|
+
raise ValueError("Google Docs credential service_account_key has an invalid type")
|
|
114
|
+
delegated_user = material.get("delegated_user")
|
|
115
|
+
if delegated_user is not None and not (isinstance(delegated_user, str)):
|
|
116
|
+
raise ValueError("Google Docs credential delegated_user has an invalid type")
|
|
117
|
+
selected_method = material.get('auth_method')
|
|
118
|
+
if selected_method is None:
|
|
119
|
+
selected_method = ''
|
|
120
|
+
if not isinstance(selected_method, str):
|
|
121
|
+
raise ValueError("Google Docs credential auth_method is invalid")
|
|
122
|
+
method = selected_method or "google-oauth"
|
|
123
|
+
values: dict[str, Any] = {'auth_method_id': method}
|
|
124
|
+
if method == "google-oauth":
|
|
125
|
+
if not oauth_client_id:
|
|
126
|
+
raise ValueError("Google Docs credential oauth_client_id is required")
|
|
127
|
+
if oauth_client_id:
|
|
128
|
+
values["oauth_client_id"] = oauth_client_id
|
|
129
|
+
if not oauth_client_secret and not is_shared:
|
|
130
|
+
raise ValueError("Google Docs credential oauth_client_secret is required")
|
|
131
|
+
if oauth_client_secret:
|
|
132
|
+
values["oauth_client_secret"] = SecretString(oauth_client_secret)
|
|
133
|
+
if not access_token:
|
|
134
|
+
raise ValueError("Google Docs credential access_token is required")
|
|
135
|
+
if access_token:
|
|
136
|
+
values["access_token"] = SecretString(access_token)
|
|
137
|
+
if not refresh_token and not is_shared:
|
|
138
|
+
raise ValueError("Google Docs credential refresh_token is required")
|
|
139
|
+
if refresh_token:
|
|
140
|
+
values["refresh_token"] = SecretString(refresh_token)
|
|
141
|
+
elif method == "workspace-domain-delegation":
|
|
142
|
+
if not service_account_key and not is_shared:
|
|
143
|
+
raise ValueError("Google Docs credential service_account_key is required")
|
|
144
|
+
if service_account_key:
|
|
145
|
+
values["service_account_key"] = SecretString(service_account_key)
|
|
146
|
+
if not delegated_user:
|
|
147
|
+
raise ValueError("Google Docs credential delegated_user is required")
|
|
148
|
+
if delegated_user:
|
|
149
|
+
values["delegated_user"] = delegated_user
|
|
150
|
+
if not access_token and is_shared:
|
|
151
|
+
raise ValueError("Google Docs credential access_token is required")
|
|
152
|
+
values["access_token"] = SecretString(access_token or '')
|
|
153
|
+
else:
|
|
154
|
+
raise ValueError("Google Docs credential auth_method is invalid")
|
|
155
|
+
return Credentials(**values)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
159
|
+
return decode_credentials(material, shared=True)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def encode_credentials(credentials: Credentials) -> dict[str, Any]:
|
|
163
|
+
material: dict[str, Any] = {}
|
|
164
|
+
method = credentials.auth_method_id or "google-oauth"
|
|
165
|
+
material['auth_method'] = method
|
|
166
|
+
if method == "google-oauth":
|
|
167
|
+
if credentials.oauth_client_id:
|
|
168
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
169
|
+
if (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else ''):
|
|
170
|
+
material["oauth_client_secret"] = (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else '')
|
|
171
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
172
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
173
|
+
if (credentials.refresh_token.reveal() if credentials.refresh_token is not None else ''):
|
|
174
|
+
material["refresh_token"] = (credentials.refresh_token.reveal() if credentials.refresh_token is not None else '')
|
|
175
|
+
elif method == "workspace-domain-delegation":
|
|
176
|
+
if (credentials.service_account_key.reveal() if credentials.service_account_key is not None else ''):
|
|
177
|
+
material["service_account_key"] = (credentials.service_account_key.reveal() if credentials.service_account_key is not None else '')
|
|
178
|
+
if credentials.delegated_user:
|
|
179
|
+
material["delegated_user"] = credentials.delegated_user
|
|
180
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
181
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
182
|
+
else:
|
|
183
|
+
raise ValueError("Google Docs credential auth_method is invalid")
|
|
184
|
+
decode_credentials(material)
|
|
185
|
+
return material
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class _ProjectCredentialSource:
|
|
189
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey, http_client: httpx.AsyncClient, settings: dict[str, Any]) -> None:
|
|
190
|
+
self.provider = RefreshingCredentialProvider(
|
|
191
|
+
project.connections, key, decode_credentials, encode_credentials, decode_shared_credentials
|
|
192
|
+
)
|
|
193
|
+
self.driver = ManifestCredentialRefreshDriver[Credentials]("Google Docs", AUTHORIZATION, CREDENTIAL_FIELDS, http_client, settings=settings)
|
|
194
|
+
|
|
195
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
196
|
+
return await self.provider.resolve_with_refresh(call, self.driver)
|
|
197
|
+
|
|
198
|
+
async def resolve_with_refresh(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
199
|
+
return await self.provider.resolve_with_refresh(call, driver or self.driver)
|
|
200
|
+
|
|
201
|
+
async def resolve_after_rejection(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
202
|
+
return await self.provider.resolve_after_rejection(call, driver or self.driver)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def new_project_connection(
|
|
206
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
207
|
+
) -> Connection:
|
|
208
|
+
if project is None:
|
|
209
|
+
raise ValueError("Google Docs connection requires loaded project configuration")
|
|
210
|
+
reference = ConnectionRef(PROVIDER, connection_name)
|
|
211
|
+
reference.validate()
|
|
212
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
213
|
+
matching = [
|
|
214
|
+
entry
|
|
215
|
+
for entry in project.configuration.connections
|
|
216
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
217
|
+
]
|
|
218
|
+
if len(matching) != 1:
|
|
219
|
+
raise ValueError("Google Docs project connection is missing or duplicated")
|
|
220
|
+
if matching[0].provider != PROVIDER:
|
|
221
|
+
raise ValueError("Google Docs project connection provider differs")
|
|
222
|
+
config = _decode_config(matching[0].configuration)
|
|
223
|
+
http_client = http_client or httpx.AsyncClient()
|
|
224
|
+
client = Client(config, _ProjectCredentialSource(project, key, http_client, matching[0].configuration), http_client)
|
|
225
|
+
return new_connection(client, reference)
|
|
226
|
+
|
|
227
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.google_docs.connection')
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
231
|
+
if set(value) - {"docsEndpoint", "driveEndpoint", "maxResponseBytes", "maxTextBytes"}:
|
|
232
|
+
raise ValueError("Google Docs configuration has unknown fields")
|
|
233
|
+
config_arguments: dict[str, Any] = {}
|
|
234
|
+
if "docsEndpoint" in value:
|
|
235
|
+
docs_endpoint = value["docsEndpoint"]
|
|
236
|
+
if not (isinstance(docs_endpoint, str)):
|
|
237
|
+
raise ValueError("Google Docs configuration docsEndpoint has an invalid type")
|
|
238
|
+
config_arguments['docs_endpoint'] = docs_endpoint
|
|
239
|
+
if "driveEndpoint" in value:
|
|
240
|
+
drive_endpoint = value["driveEndpoint"]
|
|
241
|
+
if not (isinstance(drive_endpoint, str)):
|
|
242
|
+
raise ValueError("Google Docs configuration driveEndpoint has an invalid type")
|
|
243
|
+
config_arguments['drive_endpoint'] = drive_endpoint
|
|
244
|
+
if "maxResponseBytes" in value:
|
|
245
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
246
|
+
if not (type(max_response_bytes) is int):
|
|
247
|
+
raise ValueError("Google Docs configuration maxResponseBytes has an invalid type")
|
|
248
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
249
|
+
if "maxTextBytes" in value:
|
|
250
|
+
max_text_bytes = value["maxTextBytes"]
|
|
251
|
+
if not (type(max_text_bytes) is int):
|
|
252
|
+
raise ValueError("Google Docs configuration maxTextBytes has an invalid type")
|
|
253
|
+
config_arguments['max_text_bytes'] = max_text_bytes
|
|
254
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,102 @@
|
|
|
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-docs"
|
|
18
|
+
PROVIDER = "google"
|
|
19
|
+
GET_DOCUMENT_TEXT_OPERATION_ID = "getDocumentText"
|
|
20
|
+
CREATE_DOCUMENT_OPERATION_ID = "createDocument"
|
|
21
|
+
REPLACE_DOCUMENT_TEXT_OPERATION_ID = "replaceDocumentText"
|
|
22
|
+
APPEND_TEXT_OPERATION_ID = "appendText"
|
|
23
|
+
APPENDED = "appended"
|
|
24
|
+
CREATED = "created"
|
|
25
|
+
DEFECT = "defect"
|
|
26
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
27
|
+
NOT_FOUND = "notFound"
|
|
28
|
+
PLACEHOLDER_NOT_FOUND = "placeholderNotFound"
|
|
29
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
30
|
+
READ = "read"
|
|
31
|
+
REPLACED = "replaced"
|
|
32
|
+
REVISION_CHANGED = "revisionChanged"
|
|
33
|
+
TOO_LARGE = "tooLarge"
|
|
34
|
+
UNCERTAIN = "uncertain"
|
|
35
|
+
|
|
36
|
+
GET_DOCUMENT_TEXT_DEFINITION = QueryDefinition(
|
|
37
|
+
OperationRef(CONNECTOR_ID, GET_DOCUMENT_TEXT_OPERATION_ID),
|
|
38
|
+
(
|
|
39
|
+
BranchDefinition(READ, "The document text was rendered within the configured limit.", False),
|
|
40
|
+
BranchDefinition(NOT_FOUND, "The document does not exist or the connection cannot see it.", True),
|
|
41
|
+
BranchDefinition(TOO_LARGE, "The document response or its rendered text exceeds the configured limit.", True),
|
|
42
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the read, such as a revoked grant or a missing permission.", True),
|
|
43
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid document response.", True),
|
|
44
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
45
|
+
),
|
|
46
|
+
StepDefaults(
|
|
47
|
+
timedelta(seconds=30),
|
|
48
|
+
2,
|
|
49
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
CREATE_DOCUMENT_DEFINITION = MutationDefinition(
|
|
54
|
+
OperationRef(CONNECTOR_ID, CREATE_DOCUMENT_OPERATION_ID),
|
|
55
|
+
(
|
|
56
|
+
BranchDefinition(CREATED, "Google created the document or returned the one an earlier attempt of the same Step execution created.", False),
|
|
57
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the creation or the duplicate lookup, such as a missing parent folder; no document was created.", True),
|
|
58
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized duplicate-lookup response before the creation was sent.", True),
|
|
59
|
+
BranchDefinition(UNCERTAIN, "A creation may have been sent but its outcome cannot be confirmed, so the document may exist; the connector sends nothing after selecting this branch.", True),
|
|
60
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
61
|
+
),
|
|
62
|
+
StepDefaults(
|
|
63
|
+
timedelta(seconds=30),
|
|
64
|
+
1,
|
|
65
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=60), 5, timedelta(seconds=300)),
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
REPLACE_DOCUMENT_TEXT_DEFINITION = MutationDefinition(
|
|
70
|
+
OperationRef(CONNECTOR_ID, REPLACE_DOCUMENT_TEXT_OPERATION_ID),
|
|
71
|
+
(
|
|
72
|
+
BranchDefinition(REPLACED, "The document holds the requested text, written by this attempt or an earlier attempt of the same Step execution.", False),
|
|
73
|
+
BranchDefinition(PLACEHOLDER_NOT_FOUND, "A requested placeholder does not occur in the body at the required revision; nothing was written.", True),
|
|
74
|
+
BranchDefinition(REVISION_CHANGED, "The document changed after the required revision and does not hold the requested text; nothing was written.", True),
|
|
75
|
+
BranchDefinition(NOT_FOUND, "The document does not exist or the connection cannot see it.", True),
|
|
76
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the change, such as a connection without edit access.", True),
|
|
77
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized document response.", True),
|
|
78
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
79
|
+
),
|
|
80
|
+
StepDefaults(
|
|
81
|
+
timedelta(seconds=30),
|
|
82
|
+
2,
|
|
83
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
APPEND_TEXT_DEFINITION = MutationDefinition(
|
|
88
|
+
OperationRef(CONNECTOR_ID, APPEND_TEXT_OPERATION_ID),
|
|
89
|
+
(
|
|
90
|
+
BranchDefinition(APPENDED, "The document ends with the requested text, appended by this attempt or an earlier attempt of the same Step execution.", False),
|
|
91
|
+
BranchDefinition(REVISION_CHANGED, "The document changed after the required revision and does not end with the requested text; nothing was written.", True),
|
|
92
|
+
BranchDefinition(NOT_FOUND, "The document does not exist or the connection cannot see it.", True),
|
|
93
|
+
BranchDefinition(PROVIDER_REJECTED, "Google conclusively rejected the change, such as a connection without edit access.", True),
|
|
94
|
+
BranchDefinition(INVALID_RESPONSE, "Google returned an invalid or oversized document response.", True),
|
|
95
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
96
|
+
),
|
|
97
|
+
StepDefaults(
|
|
98
|
+
timedelta(seconds=30),
|
|
99
|
+
2,
|
|
100
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
101
|
+
),
|
|
102
|
+
)
|