Skip to content

Commit 1a6b03f

Browse files
authored
Merge pull request #60 from ConductorOne/BB614
[BB-614] baton-github: ignore not found error
2 parents cf5c22e + 62ecf6f commit 1a6b03f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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/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/v63/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.GetTeamByID(ctx, orgID, team.GetID())
107+
fullTeam, resp, err := o.client.Teams.GetTeamByID(ctx, orgID, team.GetID())
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)