Skip to content

Commit a815ecc

Browse files
committed
Merge branch 'main' into update/sync-secrets-new
2 parents 6b069f2 + ba90aec commit a815ecc

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

pkg/connector/helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package connector
33
import (
44
"context"
55
"fmt"
6+
"net/http"
67
"strconv"
78
"strings"
89
"sync"
@@ -212,3 +213,10 @@ type hasSAMLQuery struct {
212213
}
213214
} `graphql:"organization(login: $orgLoginName)"`
214215
}
216+
217+
func isNotFoundError(resp *github.Response) bool {
218+
if resp == nil {
219+
return false
220+
}
221+
return resp.StatusCode == http.StatusNotFound
222+
}

pkg/connector/repository.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,18 @@ func (o *repositoryResourceType) Grants(
227227
return nil, "", nil, err
228228
}
229229

230-
rv = append(rv, grant.NewGrant(resource, permission, tr.Id, grant.WithAnnotation(&v2.V1Identifier{
231-
Id: fmt.Sprintf("repo-grant:%s:%d:%s", resource.Id.Resource, team.GetID(), permission),
232-
})))
230+
rv = append(rv, grant.NewGrant(resource, permission, tr.Id, grant.WithAnnotation(
231+
&v2.V1Identifier{
232+
Id: fmt.Sprintf("repo-grant:%s:%d:%s", resource.Id.Resource, team.GetID(), permission),
233+
},
234+
&v2.GrantExpandable{
235+
EntitlementIds: []string{
236+
entitlement.NewEntitlementID(tr, teamRoleMaintainer),
237+
entitlement.NewEntitlementID(tr, teamRoleMember),
238+
},
239+
Shallow: true,
240+
},
241+
)))
233242
}
234243
}
235244
default:
@@ -289,7 +298,7 @@ func (o *repositoryResourceType) Grant(ctx context.Context, principal *v2.Resour
289298
return nil, fmt.Errorf("github-connectorv2: failed to add user to a repository: %w", e)
290299
}
291300
case resourceTypeTeam.Id:
292-
team, _, err := o.client.Teams.GetTeamBySlug(ctx, fmt.Sprintf("%v", org.GetID()), fmt.Sprintf("%v", principalID))
301+
team, _, err := o.client.Teams.GetTeamBySlug(ctx, *org.Name, fmt.Sprintf("%v", principalID))
293302
if err != nil {
294303
return nil, fmt.Errorf("github-connectorv2: failed to get team: %w", err)
295304
}
@@ -347,7 +356,7 @@ func (o *repositoryResourceType) Revoke(ctx context.Context, grant *v2.Grant) (a
347356
return nil, fmt.Errorf("github-connectorv2: failed to remove user from repo: %w", e)
348357
}
349358
case resourceTypeTeam.Id:
350-
team, _, err := o.client.Teams.GetTeamBySlug(ctx, fmt.Sprintf("%v", org.GetID()), fmt.Sprintf("%v", principalID))
359+
team, _, err := o.client.Teams.GetTeamBySlug(ctx, *org.Name, fmt.Sprintf("%v", principalID))
351360
if err != nil {
352361
return nil, fmt.Errorf("github-connectorv2: failed to get team: %w", err)
353362
}

pkg/connector/team.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"github.com/conductorone/baton-sdk/pkg/types/entitlement"
1313
"github.com/conductorone/baton-sdk/pkg/types/grant"
1414
rType "github.com/conductorone/baton-sdk/pkg/types/resource"
15+
"github.com/conductorone/baton-sdk/pkg/uhttp"
1516
"github.com/google/go-github/v69/github"
1617
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1718
"go.uber.org/zap"
19+
"google.golang.org/grpc/codes"
1820
)
1921

2022
const (
@@ -102,8 +104,11 @@ func (o *teamResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
102104
}
103105

104106
for _, team := range teams {
105-
fullTeam, _, err := o.client.Teams.GetTeamBySlug(ctx, fmt.Sprintf("%v", orgID), fmt.Sprintf("%v", team.GetID()))
107+
fullTeam, _, err := o.client.Teams.GetTeamBySlug(ctx, orgName, team.GetSlug())
106108
if err != nil {
109+
if isNotFoundError(resp) {
110+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("team: %d not found", team.GetID()))
111+
}
107112
return nil, "", nil, err
108113
}
109114

@@ -178,6 +183,9 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
178183

179184
users, resp, err := o.client.Teams.ListTeamMembersByID(ctx, org.GetID(), githubID, &opts)
180185
if err != nil {
186+
if isNotFoundError(resp) {
187+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("org: %d not found", org.GetID()))
188+
}
181189
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to fetch team members: %w", err)
182190
}
183191

@@ -195,6 +203,9 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
195203
for _, user := range users {
196204
membership, _, err := o.client.Teams.GetTeamMembershipByID(ctx, org.GetID(), githubID, user.GetLogin())
197205
if err != nil {
206+
if isNotFoundError(resp) {
207+
return nil, "", nil, uhttp.WrapErrors(codes.NotFound, fmt.Sprintf("user: %s not found", user.GetLogin()))
208+
}
198209
return nil, "", nil, fmt.Errorf("github-connectorv2: failed to get team membership for user: %w", err)
199210
}
200211

0 commit comments

Comments
 (0)