dex-connector-github 0.1.0__tar.gz → 0.2.0__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.
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/.gitignore +4 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/PKG-INFO +17 -3
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/README.md +16 -2
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/integration_test.py +4 -1
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/pyproject.toml +1 -1
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/config.py +5 -4
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/connection.py +92 -31
- dex_connector_github-0.2.0/src/dex_connectors/github/_generated/refresh.py +9 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/client.py +54 -13
- dex_connector_github-0.2.0/src/dex_connectors/github/dex-connector.json +489 -0
- dex_connector_github-0.2.0/tests/refresh_agreement_cases.json +1258 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/tests/test_client.py +87 -2
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/tests/test_conformance.py +22 -7
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/uv.lock +1 -1
- dex_connector_github-0.1.0/src/dex_connectors/github/_generated/refresh.py +0 -9
- dex_connector_github-0.1.0/src/dex_connectors/github/dex-connector.json +0 -304
- dex_connector_github-0.1.0/tests/refresh_agreement_cases.json +0 -649
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/LICENSE +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/README.md +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/__init__.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/flow.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/main.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/__init__.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/__init__.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/definitions.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/mock.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/models.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/steps.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/_generated/timestamps.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/connection.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/githubmock/__init__.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/models.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/operations.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/steps.py +0 -0
- {dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/tests/test_refresh_agreement.py +0 -0
|
@@ -5,9 +5,13 @@ node_modules/
|
|
|
5
5
|
dist/
|
|
6
6
|
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
7
|
/.bin/dexcli
|
|
8
|
+
/dexcli
|
|
8
9
|
/.bin/dex-server-zd
|
|
10
|
+
/connectorsmcp/examples/hackernews_agent/.bin/
|
|
11
|
+
/connectorsmcp/examples/hackernews_agent/.venv/
|
|
9
12
|
/sdkpython/.dexcli-data/
|
|
10
13
|
site/.catalog.yaml
|
|
14
|
+
site/.catalog-language-tags
|
|
11
15
|
coverage/
|
|
12
16
|
*.out
|
|
13
17
|
*.test
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dex-connector-github
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Dex-native GitHub connector
|
|
5
5
|
Project-URL: Source, https://github.com/superdurable/dex-connectors-library/tree/main/connectors/github/python
|
|
6
6
|
License-Expression: MIT
|
|
@@ -16,8 +16,10 @@ Description-Content-Type: text/markdown
|
|
|
16
16
|
`dex-connector-github` implements the six GitHub Query operations declared in
|
|
17
17
|
[`connector.yaml`](../connector.yaml): `getAuthenticatedProfile`,
|
|
18
18
|
`listPublicRepositories`, `listMergedPullRequests`, `listPullRequestFiles`,
|
|
19
|
-
`listReleases`, and `listCommits`. Its Python release is `v0.
|
|
20
|
-
version remains independent.
|
|
19
|
+
`listReleases`, and `listCommits`. Its Python release is `v0.2.0`; the Go release
|
|
20
|
+
version remains independent. The Go-only `listIssues` and `createIssue`
|
|
21
|
+
operations and their `github-oauth-repository` authorization method are not
|
|
22
|
+
implemented here, and the conformance test replays only the six Queries.
|
|
21
23
|
|
|
22
24
|
The generated project connection resolves credentials at call time and uses the
|
|
23
25
|
manifest-driven OAuth refresh driver. It requests `read:user`, `user:email`, and
|
|
@@ -26,6 +28,18 @@ exactly `read:user` and `user:email` in `X-OAuth-Scopes`; broader scopes select
|
|
|
26
28
|
`insufficientScope`. The package never stores tokens in Flow input, Attributes,
|
|
27
29
|
Results, receipts, or logs.
|
|
28
30
|
|
|
31
|
+
A credential failure selects `defect` only when reconnection is required: the
|
|
32
|
+
connection needs reauthorization, is missing or not selected, the credential
|
|
33
|
+
broker refused it, or the stored material is malformed. Every other credential
|
|
34
|
+
failure, such as an unavailable broker, returns Retry without contacting GitHub.
|
|
35
|
+
|
|
36
|
+
The manifest declares two authorization methods, so the generated `Credentials`
|
|
37
|
+
dataclass begins with `auth_method_id`, which defaults to `github-oauth`, and
|
|
38
|
+
its other fields are optional. Construct it with keyword arguments, such as
|
|
39
|
+
`Credentials(oauth_client_id=..., oauth_client_secret=..., access_token=...,
|
|
40
|
+
refresh_token=...)`. A credential stored without a method decodes as
|
|
41
|
+
`github-oauth`.
|
|
42
|
+
|
|
29
43
|
The [profile example](examples/profile/README.md) is the runnable consuming
|
|
30
44
|
application. Its Worker entrypoint is `examples/profile/main.py`; the Flow
|
|
31
45
|
source is `examples/profile/flow.py`. The real Dex integration test runs that
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
`dex-connector-github` implements the six GitHub Query operations declared in
|
|
4
4
|
[`connector.yaml`](../connector.yaml): `getAuthenticatedProfile`,
|
|
5
5
|
`listPublicRepositories`, `listMergedPullRequests`, `listPullRequestFiles`,
|
|
6
|
-
`listReleases`, and `listCommits`. Its Python release is `v0.
|
|
7
|
-
version remains independent.
|
|
6
|
+
`listReleases`, and `listCommits`. Its Python release is `v0.2.0`; the Go release
|
|
7
|
+
version remains independent. The Go-only `listIssues` and `createIssue`
|
|
8
|
+
operations and their `github-oauth-repository` authorization method are not
|
|
9
|
+
implemented here, and the conformance test replays only the six Queries.
|
|
8
10
|
|
|
9
11
|
The generated project connection resolves credentials at call time and uses the
|
|
10
12
|
manifest-driven OAuth refresh driver. It requests `read:user`, `user:email`, and
|
|
@@ -13,6 +15,18 @@ exactly `read:user` and `user:email` in `X-OAuth-Scopes`; broader scopes select
|
|
|
13
15
|
`insufficientScope`. The package never stores tokens in Flow input, Attributes,
|
|
14
16
|
Results, receipts, or logs.
|
|
15
17
|
|
|
18
|
+
A credential failure selects `defect` only when reconnection is required: the
|
|
19
|
+
connection needs reauthorization, is missing or not selected, the credential
|
|
20
|
+
broker refused it, or the stored material is malformed. Every other credential
|
|
21
|
+
failure, such as an unavailable broker, returns Retry without contacting GitHub.
|
|
22
|
+
|
|
23
|
+
The manifest declares two authorization methods, so the generated `Credentials`
|
|
24
|
+
dataclass begins with `auth_method_id`, which defaults to `github-oauth`, and
|
|
25
|
+
its other fields are optional. Construct it with keyword arguments, such as
|
|
26
|
+
`Credentials(oauth_client_id=..., oauth_client_secret=..., access_token=...,
|
|
27
|
+
refresh_token=...)`. A credential stored without a method decodes as
|
|
28
|
+
`github-oauth`.
|
|
29
|
+
|
|
16
30
|
The [profile example](examples/profile/README.md) is the runnable consuming
|
|
17
31
|
application. Its Worker entrypoint is `examples/profile/main.py`; the Flow
|
|
18
32
|
source is `examples/profile/flow.py`. The real Dex integration test runs that
|
{dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/examples/profile/integration_test.py
RENAMED
|
@@ -60,7 +60,10 @@ async def test_profile_flow_through_real_dex() -> None:
|
|
|
60
60
|
server_thread.start()
|
|
61
61
|
reference = ConnectionRef("github", CONNECTION_NAME)
|
|
62
62
|
credentials = Credentials(
|
|
63
|
-
"client-id",
|
|
63
|
+
oauth_client_id="client-id",
|
|
64
|
+
oauth_client_secret=SecretString("client-secret"),
|
|
65
|
+
access_token=SecretString("inert-token"),
|
|
66
|
+
refresh_token=SecretString(""),
|
|
64
67
|
)
|
|
65
68
|
client = Client(
|
|
66
69
|
Config(base_url=f"http://127.0.0.1:{stand_in.server_port}"),
|
|
@@ -26,9 +26,10 @@ setattr(Config, '__module__', 'dex_connectors.github.client')
|
|
|
26
26
|
@dataclass(frozen=True, slots=True)
|
|
27
27
|
class Credentials:
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
auth_method_id: str = "github-oauth"
|
|
30
|
+
oauth_client_id: str | None = None
|
|
31
|
+
oauth_client_secret: SecretString | None = None
|
|
32
|
+
access_token: SecretString | None = None
|
|
33
|
+
refresh_token: SecretString = SecretString('')
|
|
33
34
|
|
|
34
35
|
setattr(Credentials, '__module__', 'dex_connectors.github.client')
|
|
@@ -106,31 +106,78 @@ def new_connection_with_operations(
|
|
|
106
106
|
setattr(new_connection_with_operations, '__module__', 'dex_connectors.github.connection')
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
class CredentialMaterialError(ValueError):
|
|
110
|
+
"Stored GitHub credential material fails the connector credential checks, so no retry can succeed."
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def is_credential_material_error(error: BaseException) -> bool:
|
|
114
|
+
"""Report malformed stored credential material, also behind the SDK provider's decoding ValueError."""
|
|
115
|
+
if isinstance(error, CredentialMaterialError):
|
|
116
|
+
return True
|
|
117
|
+
# Only the SDK decoding wrapper qualifies; other errors may be transient.
|
|
118
|
+
return (
|
|
119
|
+
type(error) is ValueError
|
|
120
|
+
and str(error) in {'project credential decoding failed', 'shared project credential decoding failed'}
|
|
121
|
+
and isinstance(error.__context__, CredentialMaterialError)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
109
125
|
def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
|
|
110
126
|
if not isinstance(material, dict):
|
|
111
|
-
raise
|
|
112
|
-
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token')):
|
|
113
|
-
raise
|
|
127
|
+
raise CredentialMaterialError("GitHub stored credential does not match the connector credential fields")
|
|
128
|
+
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token', 'auth_method')):
|
|
129
|
+
raise CredentialMaterialError("GitHub stored credential does not match the connector credential fields")
|
|
114
130
|
is_shared = shared
|
|
115
131
|
oauth_client_id = material.get("oauth_client_id")
|
|
116
132
|
if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
|
|
117
|
-
raise
|
|
133
|
+
raise CredentialMaterialError("GitHub credential oauth_client_id has an invalid type")
|
|
118
134
|
oauth_client_secret = material.get("oauth_client_secret")
|
|
119
135
|
if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
|
|
120
|
-
raise
|
|
136
|
+
raise CredentialMaterialError("GitHub credential oauth_client_secret has an invalid type")
|
|
121
137
|
access_token = material.get("access_token")
|
|
122
138
|
if access_token is not None and not (isinstance(access_token, str)):
|
|
123
|
-
raise
|
|
139
|
+
raise CredentialMaterialError("GitHub credential access_token has an invalid type")
|
|
124
140
|
refresh_token = material.get("refresh_token")
|
|
125
141
|
if refresh_token is not None and not (isinstance(refresh_token, str)):
|
|
126
|
-
raise
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
raise CredentialMaterialError("GitHub credential refresh_token has an invalid type")
|
|
143
|
+
selected_method = material.get('auth_method')
|
|
144
|
+
if selected_method is None:
|
|
145
|
+
selected_method = ''
|
|
146
|
+
if not isinstance(selected_method, str):
|
|
147
|
+
raise CredentialMaterialError("GitHub credential auth_method is invalid")
|
|
148
|
+
method = selected_method or "github-oauth"
|
|
149
|
+
values: dict[str, Any] = {'auth_method_id': method}
|
|
150
|
+
if method == "github-oauth":
|
|
151
|
+
if not oauth_client_id:
|
|
152
|
+
raise CredentialMaterialError("GitHub credential oauth_client_id is required")
|
|
153
|
+
if oauth_client_id:
|
|
154
|
+
values["oauth_client_id"] = oauth_client_id
|
|
155
|
+
if not oauth_client_secret and not is_shared:
|
|
156
|
+
raise CredentialMaterialError("GitHub credential oauth_client_secret is required")
|
|
157
|
+
if oauth_client_secret:
|
|
158
|
+
values["oauth_client_secret"] = SecretString(oauth_client_secret)
|
|
159
|
+
if not access_token:
|
|
160
|
+
raise CredentialMaterialError("GitHub credential access_token is required")
|
|
161
|
+
if access_token:
|
|
162
|
+
values["access_token"] = SecretString(access_token)
|
|
163
|
+
values["refresh_token"] = SecretString(refresh_token or '')
|
|
164
|
+
elif method == "github-oauth-repository":
|
|
165
|
+
if not oauth_client_id:
|
|
166
|
+
raise CredentialMaterialError("GitHub credential oauth_client_id is required")
|
|
167
|
+
if oauth_client_id:
|
|
168
|
+
values["oauth_client_id"] = oauth_client_id
|
|
169
|
+
if not oauth_client_secret and not is_shared:
|
|
170
|
+
raise CredentialMaterialError("GitHub credential oauth_client_secret is required")
|
|
171
|
+
if oauth_client_secret:
|
|
172
|
+
values["oauth_client_secret"] = SecretString(oauth_client_secret)
|
|
173
|
+
if not access_token:
|
|
174
|
+
raise CredentialMaterialError("GitHub credential access_token is required")
|
|
175
|
+
if access_token:
|
|
176
|
+
values["access_token"] = SecretString(access_token)
|
|
177
|
+
values["refresh_token"] = SecretString(refresh_token or '')
|
|
178
|
+
else:
|
|
179
|
+
raise CredentialMaterialError("GitHub credential auth_method is invalid")
|
|
180
|
+
return Credentials(**values)
|
|
134
181
|
|
|
135
182
|
|
|
136
183
|
def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
@@ -139,14 +186,28 @@ def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
|
139
186
|
|
|
140
187
|
def encode_credentials(credentials: Credentials) -> dict[str, Any]:
|
|
141
188
|
material: dict[str, Any] = {}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
189
|
+
method = credentials.auth_method_id or "github-oauth"
|
|
190
|
+
material['auth_method'] = method
|
|
191
|
+
if method == "github-oauth":
|
|
192
|
+
if credentials.oauth_client_id:
|
|
193
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
194
|
+
if (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else ''):
|
|
195
|
+
material["oauth_client_secret"] = (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else '')
|
|
196
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
197
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
198
|
+
if (credentials.refresh_token.reveal() if credentials.refresh_token is not None else ''):
|
|
199
|
+
material["refresh_token"] = (credentials.refresh_token.reveal() if credentials.refresh_token is not None else '')
|
|
200
|
+
elif method == "github-oauth-repository":
|
|
201
|
+
if credentials.oauth_client_id:
|
|
202
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
203
|
+
if (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else ''):
|
|
204
|
+
material["oauth_client_secret"] = (credentials.oauth_client_secret.reveal() if credentials.oauth_client_secret is not None else '')
|
|
205
|
+
if (credentials.access_token.reveal() if credentials.access_token is not None else ''):
|
|
206
|
+
material["access_token"] = (credentials.access_token.reveal() if credentials.access_token is not None else '')
|
|
207
|
+
if (credentials.refresh_token.reveal() if credentials.refresh_token is not None else ''):
|
|
208
|
+
material["refresh_token"] = (credentials.refresh_token.reveal() if credentials.refresh_token is not None else '')
|
|
209
|
+
else:
|
|
210
|
+
raise ValueError("GitHub credential auth_method is invalid")
|
|
150
211
|
decode_credentials(material)
|
|
151
212
|
return material
|
|
152
213
|
|
|
@@ -197,47 +258,47 @@ def _decode_config(value: dict[str, Any]) -> Config:
|
|
|
197
258
|
if set(value) - {"baseUrl", "apiVersion", "timeout", "maxResponseBytes", "defaultRepositoryLimit", "maxRepositories", "maxPullRequestBodyCharacters", "maxPatchCharacters", "maxCommitMessageCharacters"}:
|
|
198
259
|
raise ValueError("GitHub configuration has unknown fields")
|
|
199
260
|
config_arguments: dict[str, Any] = {}
|
|
200
|
-
if "baseUrl" in value
|
|
261
|
+
if "baseUrl" in value:
|
|
201
262
|
base_url = value["baseUrl"]
|
|
202
263
|
if not (isinstance(base_url, str)):
|
|
203
264
|
raise ValueError("GitHub configuration baseUrl has an invalid type")
|
|
204
265
|
config_arguments['base_url'] = base_url
|
|
205
|
-
if "apiVersion" in value
|
|
266
|
+
if "apiVersion" in value:
|
|
206
267
|
api_version = value["apiVersion"]
|
|
207
268
|
if not (isinstance(api_version, str)):
|
|
208
269
|
raise ValueError("GitHub configuration apiVersion has an invalid type")
|
|
209
270
|
config_arguments['api_version'] = api_version
|
|
210
|
-
if "timeout" in value
|
|
271
|
+
if "timeout" in value:
|
|
211
272
|
timeout = value["timeout"]
|
|
212
273
|
if not (type(timeout) is int):
|
|
213
274
|
raise ValueError("GitHub configuration timeout has an invalid type")
|
|
214
275
|
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
215
|
-
if "maxResponseBytes" in value
|
|
276
|
+
if "maxResponseBytes" in value:
|
|
216
277
|
max_response_bytes = value["maxResponseBytes"]
|
|
217
278
|
if not (type(max_response_bytes) is int):
|
|
218
279
|
raise ValueError("GitHub configuration maxResponseBytes has an invalid type")
|
|
219
280
|
config_arguments['max_response_bytes'] = max_response_bytes
|
|
220
|
-
if "defaultRepositoryLimit" in value
|
|
281
|
+
if "defaultRepositoryLimit" in value:
|
|
221
282
|
default_repository_limit = value["defaultRepositoryLimit"]
|
|
222
283
|
if not (type(default_repository_limit) is int):
|
|
223
284
|
raise ValueError("GitHub configuration defaultRepositoryLimit has an invalid type")
|
|
224
285
|
config_arguments['default_repository_limit'] = default_repository_limit
|
|
225
|
-
if "maxRepositories" in value
|
|
286
|
+
if "maxRepositories" in value:
|
|
226
287
|
max_repositories = value["maxRepositories"]
|
|
227
288
|
if not (type(max_repositories) is int):
|
|
228
289
|
raise ValueError("GitHub configuration maxRepositories has an invalid type")
|
|
229
290
|
config_arguments['max_repositories'] = max_repositories
|
|
230
|
-
if "maxPullRequestBodyCharacters" in value
|
|
291
|
+
if "maxPullRequestBodyCharacters" in value:
|
|
231
292
|
max_pull_request_body_characters = value["maxPullRequestBodyCharacters"]
|
|
232
293
|
if not (type(max_pull_request_body_characters) is int):
|
|
233
294
|
raise ValueError("GitHub configuration maxPullRequestBodyCharacters has an invalid type")
|
|
234
295
|
config_arguments['max_pull_request_body_characters'] = max_pull_request_body_characters
|
|
235
|
-
if "maxPatchCharacters" in value
|
|
296
|
+
if "maxPatchCharacters" in value:
|
|
236
297
|
max_patch_characters = value["maxPatchCharacters"]
|
|
237
298
|
if not (type(max_patch_characters) is int):
|
|
238
299
|
raise ValueError("GitHub configuration maxPatchCharacters has an invalid type")
|
|
239
300
|
config_arguments['max_patch_characters'] = max_patch_characters
|
|
240
|
-
if "maxCommitMessageCharacters" in value
|
|
301
|
+
if "maxCommitMessageCharacters" in value:
|
|
241
302
|
max_commit_message_characters = value["maxCommitMessageCharacters"]
|
|
242
303
|
if not (type(max_commit_message_characters) is int):
|
|
243
304
|
raise ValueError("GitHub configuration maxCommitMessageCharacters has an invalid type")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
# Validated manifest token grant declaration.
|
|
6
|
+
AUTHORIZATION = {'refreshable': True, 'defaultMethod': 'github-oauth', 'methods': [{'id': 'github-oauth', 'type': 'oauth2', 'fields': [{'name': 'oauth_client_id', 'type': 'string', 'required': True}, {'name': 'oauth_client_secret', 'type': 'secretString', 'required': True}, {'name': 'access_token', 'type': 'secretString', 'required': True}, {'name': 'refresh_token', 'type': 'secretString', 'required': False}], 'oauth2': {'tokenEndpoint': 'https://github.com/login/oauth/access_token', 'clientIDCredential': 'oauth_client_id', 'clientSecretCredential': 'oauth_client_secret', 'scopes': ['read:user', 'user:email', 'offline_access'], 'credentialMappings': [{'credential': 'access_token', 'source': 'access_token'}, {'credential': 'refresh_token', 'source': 'refresh_token'}], 'refresh': {'tokenExchangeTimeout': '15s', 'exactScopes': True, 'scopeSeparators': 'whitespaceAndComma', 'requiredScopes': ['read:user', 'user:email'], 'terminalErrorCodes': ['bad_refresh_token', 'incorrect_client_credentials', 'invalid_client', 'invalid_grant'], 'missingExpiry': 'reject'}}}, {'id': 'github-oauth-repository', 'type': 'oauth2', 'fields': [{'name': 'oauth_client_id', 'type': 'string', 'required': True}, {'name': 'oauth_client_secret', 'type': 'secretString', 'required': True}, {'name': 'access_token', 'type': 'secretString', 'required': True}, {'name': 'refresh_token', 'type': 'secretString', 'required': False}], 'oauth2': {'tokenEndpoint': 'https://github.com/login/oauth/access_token', 'clientIDCredential': 'oauth_client_id', 'clientSecretCredential': 'oauth_client_secret', 'scopes': ['repo', 'offline_access'], 'credentialMappings': [{'credential': 'access_token', 'source': 'access_token'}, {'credential': 'refresh_token', 'source': 'refresh_token'}], 'refresh': {'tokenExchangeTimeout': '15s', 'exactScopes': True, 'scopeSeparators': 'whitespaceAndComma', 'requiredScopes': ['repo'], 'terminalErrorCodes': ['bad_refresh_token', 'incorrect_client_credentials', 'invalid_client', 'invalid_grant'], 'missingExpiry': 'reject'}}}]}
|
|
7
|
+
|
|
8
|
+
# Stored credential names mapped to runtime dataclass fields.
|
|
9
|
+
CREDENTIAL_FIELDS = {'oauth_client_id': 'oauth_client_id', 'oauth_client_secret': 'oauth_client_secret', 'access_token': 'access_token', 'refresh_token': 'refresh_token'}
|
{dex_connector_github-0.1.0 → dex_connector_github-0.2.0}/src/dex_connectors/github/client.py
RENAMED
|
@@ -11,7 +11,20 @@ from typing import Any
|
|
|
11
11
|
from urllib.parse import quote, quote_plus, urlencode, urlsplit
|
|
12
12
|
|
|
13
13
|
import httpx
|
|
14
|
-
from dex_connectors.sdk import
|
|
14
|
+
from dex_connectors.sdk import (
|
|
15
|
+
Call,
|
|
16
|
+
CredentialProvider,
|
|
17
|
+
Failure,
|
|
18
|
+
FailureKind,
|
|
19
|
+
QueryAttempt,
|
|
20
|
+
ReauthorizationRequiredError,
|
|
21
|
+
Receipt,
|
|
22
|
+
)
|
|
23
|
+
from dex_connectors.sdk.projectconfig.broker import (
|
|
24
|
+
ConnectionNotSelectedError,
|
|
25
|
+
CredentialBrokerRejectedError,
|
|
26
|
+
)
|
|
27
|
+
from dex_connectors.sdk.projectconfig.storage import ObjectNotFoundError
|
|
15
28
|
from dex_connectors.sdk.providerhttp import (
|
|
16
29
|
BodyTooLargeError,
|
|
17
30
|
ProviderTransportError,
|
|
@@ -30,6 +43,22 @@ _REPOSITORY = re.compile(r"[A-Za-z0-9._-]{1,100}\Z")
|
|
|
30
43
|
_API_VERSION = re.compile(r"\d{4}-\d{2}-\d{2}\Z")
|
|
31
44
|
|
|
32
45
|
|
|
46
|
+
def _is_terminal_credential_error(error: BaseException) -> bool:
|
|
47
|
+
"""Report a credential failure no later attempt resolves without a person."""
|
|
48
|
+
# The generated connection module imports this module, so import it lazily.
|
|
49
|
+
from ._generated.connection import is_credential_material_error
|
|
50
|
+
|
|
51
|
+
return is_credential_material_error(error) or isinstance(
|
|
52
|
+
error,
|
|
53
|
+
(
|
|
54
|
+
ReauthorizationRequiredError,
|
|
55
|
+
ObjectNotFoundError,
|
|
56
|
+
ConnectionNotSelectedError,
|
|
57
|
+
CredentialBrokerRejectedError,
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
33
62
|
def _is_loopback(host: str | None) -> bool:
|
|
34
63
|
if host is None:
|
|
35
64
|
return False
|
|
@@ -82,6 +111,11 @@ def _scopes_match(response: _Response) -> bool:
|
|
|
82
111
|
} == {"read:user", "user:email"}
|
|
83
112
|
|
|
84
113
|
|
|
114
|
+
def _access_token(credential: Credentials) -> str:
|
|
115
|
+
"""Return the revealed access token, or empty when the credential has none."""
|
|
116
|
+
return credential.access_token.reveal() if credential.access_token is not None else ""
|
|
117
|
+
|
|
118
|
+
|
|
85
119
|
@dataclass(slots=True, repr=False)
|
|
86
120
|
class _CredentialState:
|
|
87
121
|
value: Credentials
|
|
@@ -162,17 +196,24 @@ class Client:
|
|
|
162
196
|
) -> tuple[_CredentialState | None, QueryAttempt[Any] | None]:
|
|
163
197
|
try:
|
|
164
198
|
credential = await self._credentials.resolve(call)
|
|
165
|
-
|
|
166
|
-
|
|
199
|
+
except Exception as error:
|
|
200
|
+
if not _is_terminal_credential_error(error):
|
|
201
|
+
# Nothing reached GitHub, so a transient credential failure retries.
|
|
202
|
+
return None, QueryAttempt.retry(
|
|
203
|
+
_failure(
|
|
204
|
+
operation, FailureKind.AVAILABILITY, "GitHub credentials are temporarily unavailable"
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
credential = None
|
|
208
|
+
if isinstance(credential, Credentials) and _access_token(credential):
|
|
167
209
|
return _CredentialState(credential), None
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
210
|
+
return None, self._branch(
|
|
211
|
+
operation,
|
|
212
|
+
"defect",
|
|
213
|
+
empty,
|
|
214
|
+
FailureKind.AUTHENTICATION,
|
|
215
|
+
"GitHub authorization is unavailable or revoked",
|
|
216
|
+
)
|
|
176
217
|
|
|
177
218
|
async def _get(
|
|
178
219
|
self, call: Call, credential: _CredentialState, path: str, query: dict[str, str] | None = None
|
|
@@ -184,7 +225,7 @@ class Client:
|
|
|
184
225
|
target,
|
|
185
226
|
headers={
|
|
186
227
|
"Accept": "application/vnd.github+json",
|
|
187
|
-
"Authorization": "Bearer " + credential.value
|
|
228
|
+
"Authorization": "Bearer " + _access_token(credential.value),
|
|
188
229
|
"User-Agent": "superdurable-dex-github-connector/0.1",
|
|
189
230
|
"X-GitHub-Api-Version": self.config.api_version,
|
|
190
231
|
},
|
|
@@ -206,7 +247,7 @@ class Client:
|
|
|
206
247
|
replacement = await self._credentials.resolve_after_rejection(call)
|
|
207
248
|
except Exception:
|
|
208
249
|
return result
|
|
209
|
-
if not isinstance(replacement, Credentials) or not replacement
|
|
250
|
+
if not isinstance(replacement, Credentials) or not _access_token(replacement):
|
|
210
251
|
return result
|
|
211
252
|
credential.value = replacement
|
|
212
253
|
raise AssertionError("request attempt exhausted")
|