Skip to content

Commit 4d4f0dd

Browse files
committed
Add permissions to PAT
1 parent e58e1a7 commit 4d4f0dd

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/openhound_github/models/personal_access_token.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime
33
from typing import ClassVar
44

5+
from dlt.common import json
56
from dlt.common.libs.pydantic import DltConfig
67
from openhound.core.asset import BaseAsset, EdgeDef, NodeDef
78
from openhound.core.models.entries_dataclass import Edge, EdgePath, EdgeProperties
@@ -28,12 +29,14 @@ class Owner(BaseModel):
2829
@dataclass
2930
class GHPersonalAccessTokenProperties(GHNodeProperties):
3031
"""PAT properties and accordion panel queries.
31-
32+
3233
Attributes:
3334
environment_name: The name of the environment (GitHub organization) where the token has access.
3435
owner_id: The GitHub ID of the token owner.
3536
owner_node_id: The GraphQL node ID of the token owner.
3637
token_expires_at: The ISO 8601 timestamp of when the token expires.
38+
organization_permissions: JSON string of the PAT's organization-scoped permissions.
39+
repository_permissions: JSON string of the PAT's repository-scoped permissions.
3740
token_last_used_at: The ISO 8601 timestamp of when the token was last used.
3841
access_granted_at: The ISO 8601 timestamp of when the token was granted to the organization. |
3942
token_name: The user-assigned display name of the token.
@@ -51,8 +54,9 @@ class GHPersonalAccessTokenProperties(GHNodeProperties):
5154
owner_node_id: str | None = None
5255
token_expires_at: datetime | None = None
5356
token_last_used_at: datetime | None = None
54-
# TODO: permissions:
5557
access_granted_at: datetime | None = None
58+
organization_permissions: str | None = None
59+
repository_permissions: str | None = None
5660
token_name: str | None = None
5761
owner_login: str | None = None
5862
repository_selection: str | None = None
@@ -140,6 +144,16 @@ def as_node(self) -> GHNode:
140144
environment_name=self.org_login,
141145
token_expires_at=self.token_expires_at,
142146
owner_id=self.owner.id if self.owner else None,
147+
organization_permissions=(
148+
json.dumps(self.permissions.organization)
149+
if self.permissions and self.permissions.organization
150+
else None
151+
),
152+
repository_permissions=(
153+
json.dumps(self.permissions.repository)
154+
if self.permissions and self.permissions.repository
155+
else None
156+
),
143157
token_last_used_at=self.token_last_used_at,
144158
query_organization_permissions=f"MATCH p=(:GH_PersonalAccessToken {{node_id:'{pid}'}})-[:GH_CanAccess]->(:GH_Organization) RETURN p",
145159
query_user=f"MATCH p=(:GH_User)-[:GH_HasPersonalAccessToken]->(:GH_PersonalAccessToken {{node_id:'{pid}'}}) RETURN p",

0 commit comments

Comments
 (0)