dex-connector-github 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_github-0.1.0.dist-info/METADATA +39 -0
- dex_connector_github-0.1.0.dist-info/RECORD +21 -0
- dex_connector_github-0.1.0.dist-info/WHEEL +4 -0
- dex_connector_github-0.1.0.dist-info/licenses/LICENSE +21 -0
- dex_connectors/github/__init__.py +47 -0
- dex_connectors/github/_generated/__init__.py +2 -0
- dex_connectors/github/_generated/config.py +34 -0
- dex_connectors/github/_generated/connection.py +245 -0
- dex_connectors/github/_generated/definitions.py +143 -0
- dex_connectors/github/_generated/mock.py +665 -0
- dex_connectors/github/_generated/models.py +464 -0
- dex_connectors/github/_generated/refresh.py +9 -0
- dex_connectors/github/_generated/steps.py +385 -0
- dex_connectors/github/_generated/timestamps.py +60 -0
- dex_connectors/github/client.py +367 -0
- dex_connectors/github/connection.py +5 -0
- dex_connectors/github/dex-connector.json +304 -0
- dex_connectors/github/githubmock/__init__.py +6 -0
- dex_connectors/github/models.py +5 -0
- dex_connectors/github/operations.py +861 -0
- dex_connectors/github/steps.py +5 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-github
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dex-native GitHub connector
|
|
5
|
+
Project-URL: Source, https://github.com/superdurable/dex-connectors-library/tree/main/connectors/github/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
|
+
# GitHub Python connector
|
|
15
|
+
|
|
16
|
+
`dex-connector-github` implements the six GitHub Query operations declared in
|
|
17
|
+
[`connector.yaml`](../connector.yaml): `getAuthenticatedProfile`,
|
|
18
|
+
`listPublicRepositories`, `listMergedPullRequests`, `listPullRequestFiles`,
|
|
19
|
+
`listReleases`, and `listCommits`. Its Python release is `v0.1.0`; the Go release
|
|
20
|
+
version remains independent.
|
|
21
|
+
|
|
22
|
+
The generated project connection resolves credentials at call time and uses the
|
|
23
|
+
manifest-driven OAuth refresh driver. It requests `read:user`, `user:email`, and
|
|
24
|
+
`offline_access` during authorization. The provider responses must advertise
|
|
25
|
+
exactly `read:user` and `user:email` in `X-OAuth-Scopes`; broader scopes select
|
|
26
|
+
`insufficientScope`. The package never stores tokens in Flow input, Attributes,
|
|
27
|
+
Results, receipts, or logs.
|
|
28
|
+
|
|
29
|
+
The [profile example](examples/profile/README.md) is the runnable consuming
|
|
30
|
+
application. Its Worker entrypoint is `examples/profile/main.py`; the Flow
|
|
31
|
+
source is `examples/profile/flow.py`. The real Dex integration test runs that
|
|
32
|
+
Flow with an inert local provider stand-in. Provider replay tests use the
|
|
33
|
+
Go-recorded scenarios in [`conformance/connectors/github`](../../../conformance/connectors/github/).
|
|
34
|
+
|
|
35
|
+
From this directory, run `uv sync` and `uv run pytest -q tests`. With a local
|
|
36
|
+
Dex stack running, set `DEX_FLOW_SERVICE_ADDRESS` to its gRPC address and run
|
|
37
|
+
`uv run pytest -q examples/profile/integration_test.py`. The local integration
|
|
38
|
+
test does not authorize against GitHub.com. Use Dex Web Connections and the
|
|
39
|
+
GitHub OAuth App guide in the manifest for live provider authorization.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
dex_connectors/github/__init__.py,sha256=jbEWY8aEpLrplBbvz8ogGyC8vaMfIhiG7dPcCti6UG8,1418
|
|
2
|
+
dex_connectors/github/client.py,sha256=5HDhqAEt_JB9RM-HFZj05A4MKn7183kbDFIyI0_7OoY,13966
|
|
3
|
+
dex_connectors/github/connection.py,sha256=pz2jVt_G4LmjNWiUgJkYSLEaOO06ir2kNCzQpf9fUhI,188
|
|
4
|
+
dex_connectors/github/dex-connector.json,sha256=yu95C_50wEC4I_4DVuaBKptoQVaTXjO23MuZyVOXV38,7348
|
|
5
|
+
dex_connectors/github/models.py,sha256=k38uoQXysGKcGhIQt9riVgYLNIgaXWLy8cpF-otMPH8,162
|
|
6
|
+
dex_connectors/github/operations.py,sha256=WrnYfkbz-6lEXzEKoYWA6i3s7aIM49r71QK4BSsvMe0,34703
|
|
7
|
+
dex_connectors/github/steps.py,sha256=hxVMshkz6BFX0El03o7RtWopPnj2jXI2iFY8XnyTrJ4,161
|
|
8
|
+
dex_connectors/github/_generated/__init__.py,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
9
|
+
dex_connectors/github/_generated/config.py,sha256=JWeVTVTXvJYeppsnxrh6YYt44MmZX-tDaRFscyf0RbE,882
|
|
10
|
+
dex_connectors/github/_generated/connection.py,sha256=IcJk_uSGQ-0nP9hTPyKbXtZzla5cB2B_g8t4zYocsHY,14383
|
|
11
|
+
dex_connectors/github/_generated/definitions.py,sha256=i4tKgoPTACw9VYV8VFFYYY37lmNo20JCOoWhBijLVUg,7386
|
|
12
|
+
dex_connectors/github/_generated/mock.py,sha256=K06DJkvWRDLsaWPvhHKv09Te33N6iNubFs1KonzjRd8,47751
|
|
13
|
+
dex_connectors/github/_generated/models.py,sha256=QXnSf0Tav8k0R_FRw8NpkPgvXGlCANjQLUm6_qe1Hw0,25980
|
|
14
|
+
dex_connectors/github/_generated/refresh.py,sha256=JUzkRtqofkjdDvLn2NJHt-QunMJY3fnW0W5HU69nXG0,1363
|
|
15
|
+
dex_connectors/github/_generated/steps.py,sha256=PzfDgV7cjlwR9Leha5NPLxZq6tJ_CQ2qV_vORnAh4S8,19044
|
|
16
|
+
dex_connectors/github/_generated/timestamps.py,sha256=Z8VwrE60w-33InIMgEMLiMPTFyRjj6oBq8tUro8Ssi8,3164
|
|
17
|
+
dex_connectors/github/githubmock/__init__.py,sha256=sEODfqQ6BJ0_cxRmH7FUHlzuhGC26jntpGD0cmUtm_U,167
|
|
18
|
+
dex_connector_github-0.1.0.dist-info/METADATA,sha256=sZiry7tdnIKEMH-lp1iHSTyXwqfZdenkFNY85jSciOY,2003
|
|
19
|
+
dex_connector_github-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
20
|
+
dex_connector_github-0.1.0.dist-info/licenses/LICENSE,sha256=WNj87Zd5micrAShl1LujOPM6PDzDqjlNLrryDZ4hE0M,1070
|
|
21
|
+
dex_connector_github-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,47 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa: F403, F405
|
|
4
|
+
"""Dex-native GitHub connector."""
|
|
5
|
+
|
|
6
|
+
from .client import Client as Client
|
|
7
|
+
from .client import Config as Config
|
|
8
|
+
from .client import Credentials as Credentials
|
|
9
|
+
from .connection import Connection as Connection
|
|
10
|
+
from .connection import new_connection as new_connection
|
|
11
|
+
from .connection import new_connection_with_operations as new_connection_with_operations
|
|
12
|
+
from .connection import new_project_connection as new_project_connection
|
|
13
|
+
from .models import * # noqa: F403
|
|
14
|
+
from .steps import * # noqa: F403
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Client",
|
|
18
|
+
"Config",
|
|
19
|
+
"Credentials",
|
|
20
|
+
"Connection",
|
|
21
|
+
"new_connection",
|
|
22
|
+
"new_connection_with_operations",
|
|
23
|
+
"new_project_connection",
|
|
24
|
+
"GetAuthenticatedProfileInput",
|
|
25
|
+
"AuthenticatedProfile",
|
|
26
|
+
"ListPublicRepositoriesInput",
|
|
27
|
+
"Repository",
|
|
28
|
+
"PublicRepositories",
|
|
29
|
+
"ListMergedPullRequestsInput",
|
|
30
|
+
"MergedPullRequest",
|
|
31
|
+
"MergedPullRequestPage",
|
|
32
|
+
"ListPullRequestFilesInput",
|
|
33
|
+
"PullRequestFile",
|
|
34
|
+
"PullRequestFilePage",
|
|
35
|
+
"ListReleasesInput",
|
|
36
|
+
"Release",
|
|
37
|
+
"ReleasePage",
|
|
38
|
+
"ListCommitsInput",
|
|
39
|
+
"CommitSummary",
|
|
40
|
+
"CommitPage",
|
|
41
|
+
"new_get_authenticated_profile_step",
|
|
42
|
+
"new_list_public_repositories_step",
|
|
43
|
+
"new_list_merged_pull_requests_step",
|
|
44
|
+
"new_list_pull_request_files_step",
|
|
45
|
+
"new_list_releases_step",
|
|
46
|
+
"new_list_commits_step",
|
|
47
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
base_url: str = "https://api.github.com"
|
|
14
|
+
api_version: str = "2026-03-10"
|
|
15
|
+
timeout_seconds: float = 15
|
|
16
|
+
max_response_bytes: int = 2097152
|
|
17
|
+
default_repository_limit: int = 100
|
|
18
|
+
max_repositories: int = 500
|
|
19
|
+
max_pull_request_body_characters: int = 4000
|
|
20
|
+
max_patch_characters: int = 4000
|
|
21
|
+
max_commit_message_characters: int = 4000
|
|
22
|
+
|
|
23
|
+
setattr(Config, '__module__', 'dex_connectors.github.client')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class Credentials:
|
|
28
|
+
|
|
29
|
+
oauth_client_id: str
|
|
30
|
+
oauth_client_secret: SecretString
|
|
31
|
+
access_token: SecretString
|
|
32
|
+
refresh_token: SecretString
|
|
33
|
+
|
|
34
|
+
setattr(Credentials, '__module__', 'dex_connectors.github.client')
|
|
@@ -0,0 +1,245 @@
|
|
|
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, GET_AUTHENTICATED_PROFILE_DEFINITION, LIST_COMMITS_DEFINITION, LIST_MERGED_PULL_REQUESTS_DEFINITION, LIST_PUBLIC_REPOSITORIES_DEFINITION, LIST_PULL_REQUEST_FILES_DEFINITION, LIST_RELEASES_DEFINITION
|
|
15
|
+
from .refresh import AUTHORIZATION, CREDENTIAL_FIELDS
|
|
16
|
+
from ..models import AuthenticatedProfile, CommitPage, GetAuthenticatedProfileInput, ListCommitsInput, ListMergedPullRequestsInput, ListPublicRepositoriesInput, ListPullRequestFilesInput, ListReleasesInput, MergedPullRequestPage, PublicRepositories, PullRequestFilePage, ReleasePage
|
|
17
|
+
|
|
18
|
+
class Connection:
|
|
19
|
+
|
|
20
|
+
__slots__ = ('_get_authenticated_profile', '_list_public_repositories', '_list_merged_pull_requests', '_list_pull_request_files', '_list_releases', '_list_commits', '_client', 'reference')
|
|
21
|
+
|
|
22
|
+
def __init__(self,
|
|
23
|
+
reference: ConnectionRef,
|
|
24
|
+
get_authenticated_profile: Query[GetAuthenticatedProfileInput, AuthenticatedProfile],
|
|
25
|
+
list_public_repositories: Query[ListPublicRepositoriesInput, PublicRepositories],
|
|
26
|
+
list_merged_pull_requests: Query[ListMergedPullRequestsInput, MergedPullRequestPage],
|
|
27
|
+
list_pull_request_files: Query[ListPullRequestFilesInput, PullRequestFilePage],
|
|
28
|
+
list_releases: Query[ListReleasesInput, ReleasePage],
|
|
29
|
+
list_commits: Query[ListCommitsInput, CommitPage],
|
|
30
|
+
client: Client | None = None,
|
|
31
|
+
) -> None:
|
|
32
|
+
reference.validate()
|
|
33
|
+
if reference.provider != CONNECTOR_ID or get_authenticated_profile is None or list_public_repositories is None or list_merged_pull_requests is None or list_pull_request_files is None or list_releases is None or list_commits is None:
|
|
34
|
+
raise ValueError("GitHub connection provider and operations are required")
|
|
35
|
+
if get_authenticated_profile.definition().operation != GET_AUTHENTICATED_PROFILE_DEFINITION.operation:
|
|
36
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
37
|
+
if list_public_repositories.definition().operation != LIST_PUBLIC_REPOSITORIES_DEFINITION.operation:
|
|
38
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
39
|
+
if list_merged_pull_requests.definition().operation != LIST_MERGED_PULL_REQUESTS_DEFINITION.operation:
|
|
40
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
41
|
+
if list_pull_request_files.definition().operation != LIST_PULL_REQUEST_FILES_DEFINITION.operation:
|
|
42
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
43
|
+
if list_releases.definition().operation != LIST_RELEASES_DEFINITION.operation:
|
|
44
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
45
|
+
if list_commits.definition().operation != LIST_COMMITS_DEFINITION.operation:
|
|
46
|
+
raise ValueError("GitHub connection operation identity differs")
|
|
47
|
+
self.reference = reference
|
|
48
|
+
self._get_authenticated_profile = get_authenticated_profile
|
|
49
|
+
self._list_public_repositories = list_public_repositories
|
|
50
|
+
self._list_merged_pull_requests = list_merged_pull_requests
|
|
51
|
+
self._list_pull_request_files = list_pull_request_files
|
|
52
|
+
self._list_releases = list_releases
|
|
53
|
+
self._list_commits = list_commits
|
|
54
|
+
self._client = client
|
|
55
|
+
|
|
56
|
+
def get_authenticated_profile(self) -> Query[GetAuthenticatedProfileInput, AuthenticatedProfile]:
|
|
57
|
+
return self._get_authenticated_profile
|
|
58
|
+
|
|
59
|
+
def list_public_repositories(self) -> Query[ListPublicRepositoriesInput, PublicRepositories]:
|
|
60
|
+
return self._list_public_repositories
|
|
61
|
+
|
|
62
|
+
def list_merged_pull_requests(self) -> Query[ListMergedPullRequestsInput, MergedPullRequestPage]:
|
|
63
|
+
return self._list_merged_pull_requests
|
|
64
|
+
|
|
65
|
+
def list_pull_request_files(self) -> Query[ListPullRequestFilesInput, PullRequestFilePage]:
|
|
66
|
+
return self._list_pull_request_files
|
|
67
|
+
|
|
68
|
+
def list_releases(self) -> Query[ListReleasesInput, ReleasePage]:
|
|
69
|
+
return self._list_releases
|
|
70
|
+
|
|
71
|
+
def list_commits(self) -> Query[ListCommitsInput, CommitPage]:
|
|
72
|
+
return self._list_commits
|
|
73
|
+
|
|
74
|
+
async def aclose(self) -> None:
|
|
75
|
+
if self._client is not None:
|
|
76
|
+
await self._client.aclose()
|
|
77
|
+
|
|
78
|
+
def __repr__(self) -> str:
|
|
79
|
+
return "github.Connection([REDACTED])"
|
|
80
|
+
|
|
81
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
82
|
+
raise TypeError("GitHub connections cannot be serialized")
|
|
83
|
+
|
|
84
|
+
setattr(Connection, '__module__', 'dex_connectors.github.connection')
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
88
|
+
if client is None:
|
|
89
|
+
raise ValueError("GitHub client is required")
|
|
90
|
+
return Connection(reference, client.get_authenticated_profile(), client.list_public_repositories(), client.list_merged_pull_requests(), client.list_pull_request_files(), client.list_releases(), client.list_commits(), client)
|
|
91
|
+
|
|
92
|
+
setattr(new_connection, '__module__', 'dex_connectors.github.connection')
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def new_connection_with_operations(
|
|
96
|
+
get_authenticated_profile: Query[GetAuthenticatedProfileInput, AuthenticatedProfile],
|
|
97
|
+
list_public_repositories: Query[ListPublicRepositoriesInput, PublicRepositories],
|
|
98
|
+
list_merged_pull_requests: Query[ListMergedPullRequestsInput, MergedPullRequestPage],
|
|
99
|
+
list_pull_request_files: Query[ListPullRequestFilesInput, PullRequestFilePage],
|
|
100
|
+
list_releases: Query[ListReleasesInput, ReleasePage],
|
|
101
|
+
list_commits: Query[ListCommitsInput, CommitPage],
|
|
102
|
+
reference: ConnectionRef,
|
|
103
|
+
) -> Connection:
|
|
104
|
+
return Connection(reference, get_authenticated_profile, list_public_repositories, list_merged_pull_requests, list_pull_request_files, list_releases, list_commits)
|
|
105
|
+
|
|
106
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.github.connection')
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def decode_credentials(material: dict[str, Any], *, shared: bool = False) -> Credentials:
|
|
110
|
+
if not isinstance(material, dict):
|
|
111
|
+
raise ValueError("GitHub stored credential does not match the connector credential fields")
|
|
112
|
+
if set(material) - set(('oauth_client_id', 'oauth_client_secret', 'access_token', 'refresh_token')):
|
|
113
|
+
raise ValueError("GitHub stored credential does not match the connector credential fields")
|
|
114
|
+
is_shared = shared
|
|
115
|
+
oauth_client_id = material.get("oauth_client_id")
|
|
116
|
+
if oauth_client_id is not None and not (isinstance(oauth_client_id, str)):
|
|
117
|
+
raise ValueError("GitHub credential oauth_client_id has an invalid type")
|
|
118
|
+
oauth_client_secret = material.get("oauth_client_secret")
|
|
119
|
+
if oauth_client_secret is not None and not (isinstance(oauth_client_secret, str)):
|
|
120
|
+
raise ValueError("GitHub credential oauth_client_secret has an invalid type")
|
|
121
|
+
access_token = material.get("access_token")
|
|
122
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
123
|
+
raise ValueError("GitHub credential access_token has an invalid type")
|
|
124
|
+
refresh_token = material.get("refresh_token")
|
|
125
|
+
if refresh_token is not None and not (isinstance(refresh_token, str)):
|
|
126
|
+
raise ValueError("GitHub credential refresh_token has an invalid type")
|
|
127
|
+
if not oauth_client_id:
|
|
128
|
+
raise ValueError("GitHub credential oauth_client_id is required")
|
|
129
|
+
if not oauth_client_secret and not is_shared:
|
|
130
|
+
raise ValueError("GitHub credential oauth_client_secret is required")
|
|
131
|
+
if not access_token:
|
|
132
|
+
raise ValueError("GitHub credential access_token is required")
|
|
133
|
+
return Credentials(oauth_client_id, SecretString(oauth_client_secret or ''), SecretString(access_token), SecretString(refresh_token or ''))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def decode_shared_credentials(material: dict[str, Any]) -> Credentials:
|
|
137
|
+
return decode_credentials(material, shared=True)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def encode_credentials(credentials: Credentials) -> dict[str, Any]:
|
|
141
|
+
material: dict[str, Any] = {}
|
|
142
|
+
if credentials.oauth_client_id:
|
|
143
|
+
material["oauth_client_id"] = credentials.oauth_client_id
|
|
144
|
+
if credentials.oauth_client_secret.reveal():
|
|
145
|
+
material["oauth_client_secret"] = credentials.oauth_client_secret.reveal()
|
|
146
|
+
if credentials.access_token.reveal():
|
|
147
|
+
material["access_token"] = credentials.access_token.reveal()
|
|
148
|
+
if credentials.refresh_token.reveal():
|
|
149
|
+
material["refresh_token"] = credentials.refresh_token.reveal()
|
|
150
|
+
decode_credentials(material)
|
|
151
|
+
return material
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class _ProjectCredentialSource:
|
|
155
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey, http_client: httpx.AsyncClient, settings: dict[str, Any]) -> None:
|
|
156
|
+
self.provider = RefreshingCredentialProvider(
|
|
157
|
+
project.connections, key, decode_credentials, encode_credentials, decode_shared_credentials
|
|
158
|
+
)
|
|
159
|
+
self.driver = ManifestCredentialRefreshDriver[Credentials]("GitHub", AUTHORIZATION, CREDENTIAL_FIELDS, http_client, settings=settings)
|
|
160
|
+
|
|
161
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
162
|
+
return await self.provider.resolve_with_refresh(call, self.driver)
|
|
163
|
+
|
|
164
|
+
async def resolve_with_refresh(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
165
|
+
return await self.provider.resolve_with_refresh(call, driver or self.driver)
|
|
166
|
+
|
|
167
|
+
async def resolve_after_rejection(self, call: Call, driver: CredentialRefreshDriver[Credentials] | None = None) -> Credentials:
|
|
168
|
+
return await self.provider.resolve_after_rejection(call, driver or self.driver)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def new_project_connection(
|
|
172
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
173
|
+
) -> Connection:
|
|
174
|
+
if project is None:
|
|
175
|
+
raise ValueError("GitHub connection requires loaded project configuration")
|
|
176
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
177
|
+
reference.validate()
|
|
178
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
179
|
+
matching = [
|
|
180
|
+
entry
|
|
181
|
+
for entry in project.configuration.connections
|
|
182
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
183
|
+
]
|
|
184
|
+
if len(matching) != 1:
|
|
185
|
+
raise ValueError("GitHub project connection is missing or duplicated")
|
|
186
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
187
|
+
raise ValueError("GitHub project connection provider differs")
|
|
188
|
+
config = _decode_config(matching[0].configuration)
|
|
189
|
+
http_client = http_client or httpx.AsyncClient()
|
|
190
|
+
client = Client(config, _ProjectCredentialSource(project, key, http_client, matching[0].configuration), http_client)
|
|
191
|
+
return new_connection(client, reference)
|
|
192
|
+
|
|
193
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.github.connection')
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
197
|
+
if set(value) - {"baseUrl", "apiVersion", "timeout", "maxResponseBytes", "defaultRepositoryLimit", "maxRepositories", "maxPullRequestBodyCharacters", "maxPatchCharacters", "maxCommitMessageCharacters"}:
|
|
198
|
+
raise ValueError("GitHub configuration has unknown fields")
|
|
199
|
+
config_arguments: dict[str, Any] = {}
|
|
200
|
+
if "baseUrl" in value and value["baseUrl"] != '':
|
|
201
|
+
base_url = value["baseUrl"]
|
|
202
|
+
if not (isinstance(base_url, str)):
|
|
203
|
+
raise ValueError("GitHub configuration baseUrl has an invalid type")
|
|
204
|
+
config_arguments['base_url'] = base_url
|
|
205
|
+
if "apiVersion" in value and value["apiVersion"] != '':
|
|
206
|
+
api_version = value["apiVersion"]
|
|
207
|
+
if not (isinstance(api_version, str)):
|
|
208
|
+
raise ValueError("GitHub configuration apiVersion has an invalid type")
|
|
209
|
+
config_arguments['api_version'] = api_version
|
|
210
|
+
if "timeout" in value and value["timeout"] != '':
|
|
211
|
+
timeout = value["timeout"]
|
|
212
|
+
if not (type(timeout) is int):
|
|
213
|
+
raise ValueError("GitHub configuration timeout has an invalid type")
|
|
214
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
215
|
+
if "maxResponseBytes" in value and value["maxResponseBytes"] != '':
|
|
216
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
217
|
+
if not (type(max_response_bytes) is int):
|
|
218
|
+
raise ValueError("GitHub configuration maxResponseBytes has an invalid type")
|
|
219
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
220
|
+
if "defaultRepositoryLimit" in value and value["defaultRepositoryLimit"] != '':
|
|
221
|
+
default_repository_limit = value["defaultRepositoryLimit"]
|
|
222
|
+
if not (type(default_repository_limit) is int):
|
|
223
|
+
raise ValueError("GitHub configuration defaultRepositoryLimit has an invalid type")
|
|
224
|
+
config_arguments['default_repository_limit'] = default_repository_limit
|
|
225
|
+
if "maxRepositories" in value and value["maxRepositories"] != '':
|
|
226
|
+
max_repositories = value["maxRepositories"]
|
|
227
|
+
if not (type(max_repositories) is int):
|
|
228
|
+
raise ValueError("GitHub configuration maxRepositories has an invalid type")
|
|
229
|
+
config_arguments['max_repositories'] = max_repositories
|
|
230
|
+
if "maxPullRequestBodyCharacters" in value and value["maxPullRequestBodyCharacters"] != '':
|
|
231
|
+
max_pull_request_body_characters = value["maxPullRequestBodyCharacters"]
|
|
232
|
+
if not (type(max_pull_request_body_characters) is int):
|
|
233
|
+
raise ValueError("GitHub configuration maxPullRequestBodyCharacters has an invalid type")
|
|
234
|
+
config_arguments['max_pull_request_body_characters'] = max_pull_request_body_characters
|
|
235
|
+
if "maxPatchCharacters" in value and value["maxPatchCharacters"] != '':
|
|
236
|
+
max_patch_characters = value["maxPatchCharacters"]
|
|
237
|
+
if not (type(max_patch_characters) is int):
|
|
238
|
+
raise ValueError("GitHub configuration maxPatchCharacters has an invalid type")
|
|
239
|
+
config_arguments['max_patch_characters'] = max_patch_characters
|
|
240
|
+
if "maxCommitMessageCharacters" in value and value["maxCommitMessageCharacters"] != '':
|
|
241
|
+
max_commit_message_characters = value["maxCommitMessageCharacters"]
|
|
242
|
+
if not (type(max_commit_message_characters) is int):
|
|
243
|
+
raise ValueError("GitHub configuration maxCommitMessageCharacters has an invalid type")
|
|
244
|
+
config_arguments['max_commit_message_characters'] = max_commit_message_characters
|
|
245
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,143 @@
|
|
|
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 = "github"
|
|
18
|
+
PROVIDER = "github"
|
|
19
|
+
GET_AUTHENTICATED_PROFILE_OPERATION_ID = "getAuthenticatedProfile"
|
|
20
|
+
LIST_PUBLIC_REPOSITORIES_OPERATION_ID = "listPublicRepositories"
|
|
21
|
+
LIST_MERGED_PULL_REQUESTS_OPERATION_ID = "listMergedPullRequests"
|
|
22
|
+
LIST_PULL_REQUEST_FILES_OPERATION_ID = "listPullRequestFiles"
|
|
23
|
+
LIST_RELEASES_OPERATION_ID = "listReleases"
|
|
24
|
+
LIST_COMMITS_OPERATION_ID = "listCommits"
|
|
25
|
+
AUTHORIZATION_REVOKED = "authorizationRevoked"
|
|
26
|
+
DEFECT = "defect"
|
|
27
|
+
INSUFFICIENT_SCOPE = "insufficientScope"
|
|
28
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
29
|
+
LISTED = "listed"
|
|
30
|
+
NOT_FOUND = "notFound"
|
|
31
|
+
PROFILE_LOADED = "profileLoaded"
|
|
32
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
33
|
+
REPOSITORIES_LOADED = "repositoriesLoaded"
|
|
34
|
+
VERIFIED_EMAIL_REQUIRED = "verifiedEmailRequired"
|
|
35
|
+
|
|
36
|
+
GET_AUTHENTICATED_PROFILE_DEFINITION = QueryDefinition(
|
|
37
|
+
OperationRef(CONNECTOR_ID, GET_AUTHENTICATED_PROFILE_OPERATION_ID),
|
|
38
|
+
(
|
|
39
|
+
BranchDefinition(PROFILE_LOADED, "The authenticated profile and primary verified email were loaded.", False),
|
|
40
|
+
BranchDefinition(VERIFIED_EMAIL_REQUIRED, "A primary verified email was not available.", True),
|
|
41
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
42
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
43
|
+
BranchDefinition(NOT_FOUND, "The authenticated account was not found.", True),
|
|
44
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the profile query.", True),
|
|
45
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized profile response.", True),
|
|
46
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
47
|
+
),
|
|
48
|
+
StepDefaults(
|
|
49
|
+
timedelta(seconds=30),
|
|
50
|
+
2,
|
|
51
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
LIST_PUBLIC_REPOSITORIES_DEFINITION = QueryDefinition(
|
|
56
|
+
OperationRef(CONNECTOR_ID, LIST_PUBLIC_REPOSITORIES_OPERATION_ID),
|
|
57
|
+
(
|
|
58
|
+
BranchDefinition(REPOSITORIES_LOADED, "Public repositories were loaded and bounded.", False),
|
|
59
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
60
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
61
|
+
BranchDefinition(NOT_FOUND, "The requested GitHub account was not found.", True),
|
|
62
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the repository query.", True),
|
|
63
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized repository response.", True),
|
|
64
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
65
|
+
),
|
|
66
|
+
StepDefaults(
|
|
67
|
+
timedelta(seconds=30),
|
|
68
|
+
2,
|
|
69
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
70
|
+
),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
LIST_MERGED_PULL_REQUESTS_DEFINITION = QueryDefinition(
|
|
74
|
+
OperationRef(CONNECTOR_ID, LIST_MERGED_PULL_REQUESTS_OPERATION_ID),
|
|
75
|
+
(
|
|
76
|
+
BranchDefinition(LISTED, "One bounded page of merged pull requests was loaded.", False),
|
|
77
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
78
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
79
|
+
BranchDefinition(NOT_FOUND, "The requested GitHub resource was not found.", True),
|
|
80
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the search, including a repository it cannot search.", True),
|
|
81
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized search response.", True),
|
|
82
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
83
|
+
),
|
|
84
|
+
StepDefaults(
|
|
85
|
+
timedelta(seconds=30),
|
|
86
|
+
2,
|
|
87
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=30), 0, timedelta(seconds=3900)),
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
LIST_PULL_REQUEST_FILES_DEFINITION = QueryDefinition(
|
|
92
|
+
OperationRef(CONNECTOR_ID, LIST_PULL_REQUEST_FILES_OPERATION_ID),
|
|
93
|
+
(
|
|
94
|
+
BranchDefinition(LISTED, "One bounded page of changed files was loaded.", False),
|
|
95
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
96
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
97
|
+
BranchDefinition(NOT_FOUND, "The repository or pull request was not found.", True),
|
|
98
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the changed-file query.", True),
|
|
99
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized changed-file response.", True),
|
|
100
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
101
|
+
),
|
|
102
|
+
StepDefaults(
|
|
103
|
+
timedelta(seconds=30),
|
|
104
|
+
2,
|
|
105
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=30), 0, timedelta(seconds=3900)),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
LIST_RELEASES_DEFINITION = QueryDefinition(
|
|
110
|
+
OperationRef(CONNECTOR_ID, LIST_RELEASES_OPERATION_ID),
|
|
111
|
+
(
|
|
112
|
+
BranchDefinition(LISTED, "One bounded page of releases was loaded, possibly empty.", False),
|
|
113
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
114
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
115
|
+
BranchDefinition(NOT_FOUND, "The repository was not found or is inaccessible.", True),
|
|
116
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the releases query.", True),
|
|
117
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized releases response.", True),
|
|
118
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
119
|
+
),
|
|
120
|
+
StepDefaults(
|
|
121
|
+
timedelta(seconds=30),
|
|
122
|
+
2,
|
|
123
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=30), 0, timedelta(seconds=3900)),
|
|
124
|
+
),
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
LIST_COMMITS_DEFINITION = QueryDefinition(
|
|
128
|
+
OperationRef(CONNECTOR_ID, LIST_COMMITS_OPERATION_ID),
|
|
129
|
+
(
|
|
130
|
+
BranchDefinition(LISTED, "One bounded page of commits was loaded; an empty repository has no commits.", False),
|
|
131
|
+
BranchDefinition(INSUFFICIENT_SCOPE, "The OAuth grant does not match the required scopes.", True),
|
|
132
|
+
BranchDefinition(AUTHORIZATION_REVOKED, "The OAuth grant is invalid or revoked.", True),
|
|
133
|
+
BranchDefinition(NOT_FOUND, "The repository or starting ref was not found.", True),
|
|
134
|
+
BranchDefinition(PROVIDER_REJECTED, "GitHub conclusively rejected the commit query.", True),
|
|
135
|
+
BranchDefinition(INVALID_RESPONSE, "GitHub returned an invalid or oversized commit response.", True),
|
|
136
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
137
|
+
),
|
|
138
|
+
StepDefaults(
|
|
139
|
+
timedelta(seconds=30),
|
|
140
|
+
2,
|
|
141
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=30), 0, timedelta(seconds=3900)),
|
|
142
|
+
),
|
|
143
|
+
)
|