From 9ae807467504438ffa9ee2ec7f06db275df3fd8a Mon Sep 17 00:00:00 2001 From: Daniel Brauer Date: Fri, 8 Nov 2024 08:20:32 -0500 Subject: [PATCH] initial poking around incomplete Signed-off-by: Daniel Brauer --- cartography/models/github/users.py | 122 +++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 cartography/models/github/users.py diff --git a/cartography/models/github/users.py b/cartography/models/github/users.py new file mode 100644 index 000000000..5732f69ac --- /dev/null +++ b/cartography/models/github/users.py @@ -0,0 +1,122 @@ +from dataclasses import dataclass +from typing import Optional + +from cartography.models.core.common import PropertyRef +from cartography.models.core.nodes import CartographyNodeProperties +from cartography.models.core.nodes import CartographyNodeSchema +from cartography.models.core.relationships import CartographyRelProperties +from cartography.models.core.relationships import CartographyRelSchema +from cartography.models.core.relationships import LinkDirection +from cartography.models.core.relationships import make_target_node_matcher +from cartography.models.core.relationships import OtherRelationships +from cartography.models.core.relationships import TargetNodeMatcher + + +@dataclass(frozen=True) +class GitHubUserNodeProperties(CartographyNodeProperties): + id: PropertyRef = PropertyRef('url') + lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) + fullname: PropertyRef = PropertyRef('name') + username: PropertyRef = PropertyRef('login', extra_index=True) + # optional because some enterprise owners do not have this property specified + has_2fa_enabled: Optional[PropertyRef] = PropertyRef('hasTwoFactorEnabled') + role: PropertyRef = PropertyRef('role') + is_site_admin: PropertyRef = PropertyRef('isSiteAdmin') + is_enterprise_owner: PropertyRef = PropertyRef('isEnterpriseOwner') + email: PropertyRef = PropertyRef('email') + company: PropertyRef = PropertyRef('company') + + + + + +# @dataclass(frozen=True) +# class GitHubTeamToRepoRelProperties(CartographyRelProperties): +# lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) +# +# +# @dataclass(frozen=True) +# class GitHubTeamAdminRepoRel(CartographyRelSchema): +# target_node_label: str = 'GitHubRepository' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('ADMIN')}, +# ) +# direction: LinkDirection = LinkDirection.OUTWARD +# rel_label: str = "ADMIN" +# properties: GitHubTeamToRepoRelProperties = GitHubTeamToRepoRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamMaintainRepoRel(CartographyRelSchema): +# target_node_label: str = 'GitHubRepository' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('MAINTAIN')}, +# ) +# direction: LinkDirection = LinkDirection.OUTWARD +# rel_label: str = "MAINTAIN" +# properties: GitHubTeamToRepoRelProperties = GitHubTeamToRepoRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamReadRepoRel(CartographyRelSchema): +# target_node_label: str = 'GitHubRepository' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('READ')}, +# ) +# direction: LinkDirection = LinkDirection.OUTWARD +# rel_label: str = "READ" +# properties: GitHubTeamToRepoRelProperties = GitHubTeamToRepoRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamTriageRepoRel(CartographyRelSchema): +# target_node_label: str = 'GitHubRepository' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('TRIAGE')}, +# ) +# direction: LinkDirection = LinkDirection.OUTWARD +# rel_label: str = "TRIAGE" +# properties: GitHubTeamToRepoRelProperties = GitHubTeamToRepoRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamWriteRepoRel(CartographyRelSchema): +# target_node_label: str = 'GitHubRepository' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('WRITE')}, +# ) +# direction: LinkDirection = LinkDirection.OUTWARD +# rel_label: str = "WRITE" +# properties: GitHubTeamToRepoRelProperties = GitHubTeamToRepoRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamToOrganizationRelProperties(CartographyRelProperties): +# lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) +# +# +# @dataclass(frozen=True) +# class GitHubTeamToOrganizationRel(CartographyRelSchema): +# target_node_label: str = 'GitHubOrganization' +# target_node_matcher: TargetNodeMatcher = make_target_node_matcher( +# {'id': PropertyRef('org_url', set_in_kwargs=True)}, +# ) +# direction: LinkDirection = LinkDirection.INWARD +# rel_label: str = "RESOURCE" +# properties: GitHubTeamToOrganizationRelProperties = GitHubTeamToOrganizationRelProperties() +# +# +# @dataclass(frozen=True) +# class GitHubTeamSchema(CartographyNodeSchema): +# label: str = 'GitHubTeam' +# properties: GitHubTeamNodeProperties = GitHubTeamNodeProperties() +# other_relationships: OtherRelationships = OtherRelationships( +# [ +# GitHubTeamAdminRepoRel(), +# GitHubTeamMaintainRepoRel(), +# GitHubTeamReadRepoRel(), +# GitHubTeamTriageRepoRel(), +# GitHubTeamWriteRepoRel(), +# ], +# ) +# sub_resource_relationship: GitHubTeamToOrganizationRel = GitHubTeamToOrganizationRel()