Skip to content

Commit 7d572f4

Browse files
committed
fix: change organization role assignment
1 parent d8bd443 commit 7d572f4

File tree

3 files changed

+38
-56
lines changed

3 files changed

+38
-56
lines changed

cloudql/github/table_github_organization_role_assignment.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,16 @@ func gitHubOrganizationRoleAssignment() []*plugin.Column {
2020
Type: proto.ColumnType_INT,
2121
Description: "The name of the repository",
2222
Transform: transform.FromField("Description.OrganizationId")},
23-
24-
{
25-
Name: "list_of_teams",
26-
Type: proto.ColumnType_JSON,
27-
Description: "The permission the collaborator has on the repository.",
28-
Transform: transform.FromField("Description.ListOfTeams")},
29-
30-
{
31-
Name: "list_of_users",
32-
Type: proto.ColumnType_JSON,
33-
Description: "The login details of the collaborator.",
34-
Transform: transform.FromField("Description.ListOfUsers")},
3523
{
36-
Name: "created_at",
37-
Type: proto.ColumnType_TIMESTAMP,
38-
Description: "The id of the collaborator.",
39-
Transform: transform.FromField("Description.CreatedAt")},
24+
Name: "principal_type",
25+
Type: proto.ColumnType_STRING,
26+
Description: "The name of the repository",
27+
Transform: transform.FromField("Description.PrincipalType")},
4028
{
41-
Name: "updated_at",
42-
Type: proto.ColumnType_TIMESTAMP,
43-
Description: "The id of the collaborator.",
44-
Transform: transform.FromField("Description.UpdatedAt")},
29+
Name: "principal_id",
30+
Type: proto.ColumnType_INT,
31+
Description: "The name of the repository",
32+
Transform: transform.FromField("Description.PrincipalId")},
4533
}
4634

4735
return tableCols

discovery/describers/organization_role_assignment.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,50 @@ func ListOrganizationRoleAssignments(ctx context.Context, githubClient model.Git
3434
return nil, err
3535
}
3636

37-
// 3) For each role, gather assigned teams and users
38-
var assignments []GitHubRoleAssignment
37+
// 3) For each role, gather assigned teams and users, then produce output
38+
var allAssignments []GitHubOrganizationRoleAssignment
3939

4040
for _, role := range orgRoles {
4141
teams, err := fetchTeamsAssignedToRole(sdk, organizationName, role.ID)
4242
if err != nil {
4343
fmt.Println(err)
4444
continue
4545
}
46-
teamIDs := make([]int, 0, len(teams))
46+
// Create one JSON object per assigned team
4747
for _, t := range teams {
48-
teamIDs = append(teamIDs, t.ID)
48+
allAssignments = append(allAssignments, GitHubOrganizationRoleAssignment{
49+
RoleID: role.ID,
50+
OrganizationID: orgID,
51+
PrincipalType: "team",
52+
PrincipalID: t.ID,
53+
})
4954
}
5055

5156
users, err := fetchUsersAssignedToRole(sdk, organizationName, role.ID)
5257
if err != nil {
5358
return nil, err
5459
}
55-
userIDs := make([]int, 0, len(users))
60+
// Create one JSON object per assigned user
5661
for _, u := range users {
57-
userIDs = append(userIDs, u.ID)
62+
allAssignments = append(allAssignments, GitHubOrganizationRoleAssignment{
63+
RoleID: role.ID,
64+
OrganizationID: orgID,
65+
PrincipalType: "user",
66+
PrincipalID: u.ID,
67+
})
5868
}
59-
60-
assignments = append(assignments, GitHubRoleAssignment{
61-
RoleID: role.ID,
62-
OrganizationID: orgID,
63-
CreatedAt: role.CreatedAt,
64-
UpdatedAt: role.UpdatedAt,
65-
ListOfTeams: teamIDs,
66-
ListOfUsers: userIDs,
67-
})
6869
}
6970

70-
for _, a := range assignments {
71+
for _, a := range allAssignments {
7172
id := fmt.Sprintf("%d/%d", a.OrganizationID, a.RoleID)
7273
value := models.Resource{
7374
ID: id,
7475
Description: model.OrganizationRoleAssignmentDescription{
7576
RoleId: a.RoleID,
7677
OrganizationId: a.OrganizationID,
7778
Organization: organizationName,
78-
ListOfTeams: a.ListOfTeams,
79-
ListOfUsers: a.ListOfUsers,
80-
CreatedAt: a.CreatedAt,
81-
UpdatedAt: a.UpdatedAt,
79+
PrincipalType: a.PrincipalType,
80+
PrincipalId: a.PrincipalID,
8281
},
8382
}
8483

@@ -109,18 +108,6 @@ type orgRoleListResponseForAssignment struct {
109108
Roles []OrgRoleForAssignment `json:"roles"`
110109
}
111110

112-
// GitHubRoleAssignment captures which teams and which users are assigned to a single org role
113-
type GitHubRoleAssignment struct {
114-
RoleID int `json:"role_id"`
115-
OrganizationID int `json:"organization_id"`
116-
CreatedAt time.Time `json:"created_at,omitempty"`
117-
UpdatedAt time.Time `json:"updated_at,omitempty"`
118-
119-
ListOfTeams []int `json:"list_of_teams"`
120-
ListOfUsers []int `json:"list_of_users"`
121-
}
122-
123-
// Minimal structs for teams and users assigned to roles
124111
type GitHubTeam struct {
125112
ID int `json:"id"`
126113
}
@@ -129,6 +116,15 @@ type GitHubUser struct {
129116
ID int `json:"id"`
130117
}
131118

119+
// GitHubOrganizationRoleAssignment is the final output format:
120+
// one object per "principal" (team or user) assigned to a role.
121+
type GitHubOrganizationRoleAssignment struct {
122+
RoleID int `json:"role_id"`
123+
OrganizationID int `json:"organization_id"`
124+
PrincipalType string `json:"principal_type"` // "team" or "user"
125+
PrincipalID int `json:"principal_id"`
126+
}
127+
132128
// -----------------------------------------------------
133129
// Implementation: Org ID, Roles, Assignments
134130
// -----------------------------------------------------

discovery/provider/model.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,10 +1871,8 @@ type OrganizationRoleAssignmentDescription struct {
18711871
RoleId int
18721872
OrganizationId int
18731873
Organization string
1874-
ListOfTeams []int
1875-
ListOfUsers []int
1876-
CreatedAt time.Time
1877-
UpdatedAt time.Time
1874+
PrincipalType string
1875+
PrincipalId int
18781876
}
18791877

18801878
type OrganizationRoleDefinitionDescription struct {

0 commit comments

Comments
 (0)