-
Notifications
You must be signed in to change notification settings - Fork 1
[INC-300] baton-github: include the error in the returned message #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca19315
b9eed40
cdc712e
4239b2b
0eaff5b
2c8e33f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,7 @@ func (gh *GitHub) Validate(ctx context.Context) (annotations.Annotations, error) | |
| membership, _, err := gh.client.Organizations.GetOrgMembership(ctx, "", o) | ||
| if err != nil { | ||
| if filterOrgs { | ||
| return nil, fmt.Errorf("access token must be an admin on the %s organization", o) | ||
| return nil, fmt.Errorf("access token must be an admin on the %s organization: %w", o, err) | ||
| } | ||
| continue | ||
| } | ||
|
|
@@ -450,6 +450,9 @@ func getOrgs(ctx context.Context, client *github.Client, orgs []string) ([]strin | |
| for { | ||
| orgs, resp, err := client.Organizations.List(ctx, "", &github.ListOptions{Page: page, PerPage: maxPageSize}) | ||
| if err != nil { | ||
| if isRatelimited(resp) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are adding retry
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also the error message is not correct can you return an error instead of nil?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, that makes sense. TIL |
||
| return nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil, fmt.Errorf("github-connector: failed to retrieve org: %w", err) | ||
| } | ||
| if resp.StatusCode == http.StatusUnauthorized { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,9 @@ func (o *orgResourceType) List( | |
|
|
||
| orgs, resp, err := o.client.Organizations.List(ctx, "", opts) | ||
| if err != nil { | ||
| if isRatelimited(resp) { | ||
| return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Add |
||
| } | ||
| return nil, "", nil, fmt.Errorf("github-connector: failed to fetch org: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -126,6 +129,10 @@ func (o *orgResourceType) List( | |
| l.Warn("insufficient access to list org membership, skipping org", zap.String("org", org.GetLogin())) | ||
| continue | ||
| } | ||
|
|
||
| if isRatelimited(resp) { | ||
| return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return nil, "", nil, err | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,12 @@ import ( | |
| "github.com/conductorone/baton-sdk/pkg/annotations" | ||
| "github.com/conductorone/baton-sdk/pkg/pagination" | ||
| "github.com/conductorone/baton-sdk/pkg/types/resource" | ||
| "github.com/conductorone/baton-sdk/pkg/uhttp" | ||
| "github.com/google/go-github/v69/github" | ||
| "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" | ||
| "github.com/shurcooL/githubv4" | ||
| "go.uber.org/zap" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
| ) | ||
|
|
||
|
|
@@ -131,6 +133,9 @@ func (o *userResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt | |
|
|
||
| users, resp, err := o.client.Organizations.ListMembers(ctx, orgName, &opts) | ||
| if err != nil { | ||
| if isRatelimited(resp) { | ||
| return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err) | ||
| } | ||
| return nil, "", nil, fmt.Errorf("github-connector: ListMembers failed: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -154,6 +159,9 @@ func (o *userResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt | |
| for _, user := range users { | ||
| u, res, err := o.client.Users.GetByID(ctx, user.GetID()) | ||
| if err != nil { | ||
| if isRatelimited(res) { | ||
| return nil, "", nil, uhttp.WrapErrors(codes.Unavailable, "too many requests", err) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: GitHub API Client Nil Response HandlingThe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isRatelimited has checked nil pointer. |
||
| // This undocumented API can return 404 for some users. If this fails it means we won't get some of their details like email | ||
| if res == nil || res.StatusCode != http.StatusNotFound { | ||
| return nil, "", nil, err | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add
isRatelimitedto Every API calls, includingListandGrants