Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/deckarep/golang-set/v2 v2.9.0
github.com/ennyjfrick/ruleguard-logfatal v0.0.2
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/go-github/v69 v69.2.0
github.com/google/go-github/v93 v93.0.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/migueleliasweb/go-github-mock v1.1.0
github.com/quasilyte/go-ruleguard/dsl v0.3.23
Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/go-github/v64 v64.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e h1:4bw4WeyTYPp0smaXiJZCNnLrvVBqirQVreixayXezGc=
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v64 v64.0.0 h1:4G61sozmY3eiPAjjoOHponXDBONm+utovTKbyUb2Qdg=
github.com/google/go-github/v64 v64.0.0/go.mod h1:xB3vqMQNdHzilXBiO2I+M7iEFtHf+DP/omBOv6tQzVo=
github.com/google/go-github/v69 v69.2.0 h1:wR+Wi/fN2zdUx9YxSmYE0ktiX9IAR/BeePzeaUUbEHE=
github.com/google/go-github/v69 v69.2.0/go.mod h1:xne4jymxLR6Uj9b7J7PyTpkMYstEMMwGZa0Aehh1azM=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/go-github/v93 v93.0.0 h1:qElXPLv+XbSz1qrLdWyb0t3gSYGsWBTzr9T4/PZTCfk=
github.com/google/go-github/v93 v93.0.0/go.mod h1:l8I3rt4/mdjANKpg4Y84LEy9HJQCetUkZ8WTl2bPU8M=
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/api_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
)

func apiTokenResource(ctx context.Context, token *github.PersonalAccessToken) (*v2.Resource, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
)

// appResource builds a GitHub App resource from one organization installation.
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/app_privatekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestLoadPrivateKeyFromString(t *testing.T) {
realNewlines := string(pemBytes)

shapes := map[string]string{
"real newlines": realNewlines,
"real CRLF": strings.ReplaceAll(realNewlines, "\n", "\r\n"),
"real newlines": realNewlines,
"real CRLF": strings.ReplaceAll(realNewlines, "\n", "\r\n"),
"backslash-n escaped, as the docs instruct": strings.ReplaceAll(realNewlines, "\n", `\n`),
"backslash-n escaped, trailing space": strings.ReplaceAll(realNewlines, "\n", `\n`) + " ",
"backslash-r-backslash-n escaped (CRLF file)": strings.ReplaceAll(realNewlines, "\n", `\r\n`),
Expand Down
16 changes: 8 additions & 8 deletions pkg/connector/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/stretchr/testify/require"
)

func TestAppResource(t *testing.T) {
ctx := context.Background()

installation := &github.Installation{
ID: github.Ptr(int64(42)),
AppID: github.Ptr(int64(7)),
AppSlug: github.Ptr("octo-app"),
TargetType: github.Ptr("Organization"),
RepositorySelection: github.Ptr("all"),
HTMLURL: github.Ptr("https://github.com/organizations/acme/settings/installations/42"),
Account: &github.User{Login: github.Ptr("acme")},
ID: new(int64(42)),
AppID: new(int64(7)),
AppSlug: new("octo-app"),
TargetType: new("Organization"),
RepositorySelection: new("all"),
HTMLURL: new("https://github.com/organizations/acme/settings/installations/42"),
Account: &github.User{Login: new("acme")},
}
parent := &v2.ResourceId{ResourceType: resourceTypeOrg.Id, Resource: "1"}

Expand Down
11 changes: 5 additions & 6 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
"github.com/conductorone/baton-sdk/pkg/uhttp"
jwtv5 "github.com/golang-jwt/jwt/v5"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/shurcooL/githubv4"
"go.uber.org/zap"
Expand Down Expand Up @@ -312,14 +312,13 @@ func newGitHubClient(ctx context.Context, instanceURL string, ts oauth2.TokenSou
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)

tc := oauth2.NewClient(ctx, ts)
gc := github.NewClient(tc)

opts := []github.ClientOptionsFunc{github.WithHTTPClient(tc)}
instanceURL = strings.TrimSuffix(instanceURL, "/")
if instanceURL != "" && instanceURL != githubDotCom {
return gc.WithEnterpriseURLs(instanceURL, instanceURL)
opts = append(opts, github.WithEnterpriseURLs(instanceURL, instanceURL))
}

return gc, nil
return github.NewClient(opts...)
}

func NewLambdaConnector(ctx context.Context, ghc *cfg.Github, cliOpts *cli.ConnectorOpts) (connectorbuilder.ConnectorBuilderV2, []connectorbuilder.Opt, error) {
Expand Down Expand Up @@ -758,7 +757,7 @@ func getJWTToken(appID string, privateKey string) (string, error) {
}

func findInstallation(ctx context.Context, c *github.Client, orgName string) (*github.Installation, error) {
installation, resp, err := c.Apps.FindOrganizationInstallation(ctx, orgName)
installation, resp, err := c.Apps.GetOrganizationInstallation(ctx, orgName)
if err != nil {
return nil, wrapGitHubError(err, resp, fmt.Sprintf("github-connector: failed to find installation for org %s", orgName))
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/connector/enterprise_installations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"testing"

"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
"google.golang.org/grpc/codes"
Expand All @@ -34,11 +34,12 @@ func newGitHubAPITestClientAt(t *testing.T, handler http.Handler, basePath strin
srv := httptest.NewServer(handler)
t.Cleanup(srv.Close)

baseURL, err := url.Parse(srv.URL + basePath)
baseURL, err := url.Parse(srv.URL)
require.NoError(t, err)
baseURL = baseURL.JoinPath(basePath)

client := github.NewClient(srv.Client())
client.BaseURL = baseURL
client, err := github.NewClient(github.WithHTTPClient(srv.Client()), github.WithURLs(new(baseURL.String()), nil))
require.NoError(t, err)

return client
}
Expand Down Expand Up @@ -340,7 +341,7 @@ func TestNewEnterpriseRoleClientsRejectsANonCloudInstance(t *testing.T) {
_, err := newEnterpriseRoleClients(
context.Background(), context.Background(),
"https://github.acme.com",
github.NewClient(nil), nil,
newTestGitHubClient(t, nil), nil,
[]string{testEnterprise, "another-enterprise"}, nil, "example-org",
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/enterprise_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/conductorone/baton-sdk/pkg/types/entitlement"
"github.com/conductorone/baton-sdk/pkg/types/grant"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/shurcooL/githubv4"
"go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/enterprise_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
entitlementSdk "github.com/conductorone/baton-sdk/pkg/types/entitlement"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/conductorone/baton-sdk/pkg/uhttp"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -426,7 +426,7 @@ func newTestEnterpriseRoleBuilder(
require.NoError(t, err)

builder := EnterpriseRoleProvisioningBuilder(
github.NewClient(mgh.Server()),
newTestGitHubClient(t, mgh.Server()),
nil,
[]string{testEnterprise},
func(context.Context, []string) (map[string]*customclient.EnterpriseAdminClient, error) {
Expand Down
20 changes: 20 additions & 0 deletions pkg/connector/go_github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package connector

import (
"net/http"
"testing"

"github.com/google/go-github/v93/github"
"github.com/stretchr/testify/require"
)

func newTestGitHubClient(t *testing.T, httpClient *http.Client) *github.Client {
t.Helper()
var opts []github.ClientOptionsFunc
if httpClient != nil {
opts = append(opts, github.WithHTTPClient(httpClient))
}
client, err := github.NewClient(opts...)
require.NoError(t, err)
return client
}
2 changes: 1 addition & 1 deletion pkg/connector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/conductorone/baton-sdk/pkg/session"
"github.com/conductorone/baton-sdk/pkg/types/sessions"
"github.com/conductorone/baton-sdk/pkg/uhttp"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/shurcooL/githubv4"
"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
"github.com/conductorone/baton-sdk/pkg/pagination"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -262,7 +262,7 @@ func (i *invitationResourceType) CreateAccount(
return nil, nil, nil, fmt.Errorf("github-connectorv2: failed to get CreateUserParams: %w", err)
}

invitation, resp, err := i.client.Organizations.CreateOrgInvitation(ctx, params.org, &github.CreateOrgInvitationOptions{
invitation, resp, err := i.client.Organizations.CreateOrgInvitation(ctx, params.org, github.CreateOrgInvitationRequest{
Email: params.email,
})
if err != nil {
Expand Down
68 changes: 34 additions & 34 deletions pkg/connector/invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/pagination"
resourceSdk "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/google/go-github/v69/github"
"github.com/google/go-github/v93/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -57,8 +57,8 @@ func orgByIDHandler() mock.MockBackendOption {
mocks.GetOrganizationById,
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write(mock.MustMarshal(github.Organization{
ID: github.Ptr(invitationTestOrgID),
Login: github.Ptr(invitationTestOrgLogin),
ID: new(invitationTestOrgID),
Login: new(invitationTestOrgLogin),
}))
}),
)
Expand Down Expand Up @@ -86,26 +86,26 @@ func TestInvitationListPagination(t *testing.T) {

pendingPage1 := []*github.Invitation{
{
ID: github.Ptr(int64(1001)),
Login: github.Ptr("alice"),
Email: github.Ptr("alice@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(1001)),
Login: new("alice"),
Email: new("alice@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated1},
},
{
ID: github.Ptr(int64(1002)),
Login: github.Ptr("bob"),
Email: github.Ptr("bob@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(1002)),
Login: new("bob"),
Email: new("bob@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated2},
},
}
pendingPage2 := []*github.Invitation{
{
ID: github.Ptr(int64(1003)),
Login: github.Ptr("carol"),
Email: github.Ptr("carol@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(1003)),
Login: new("carol"),
Email: new("carol@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated3},
},
}
Expand All @@ -116,44 +116,44 @@ func TestInvitationListPagination(t *testing.T) {
// for failures that aren't expirations.
failedPage1 := []*github.Invitation{
{
ID: github.Ptr(int64(2001)),
Email: github.Ptr("dave-expired@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(2001)),
Email: new("dave-expired@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated1},
FailedAt: &github.Timestamp{Time: expiredFailedAt1},
FailedReason: github.Ptr("Invitation expired. User did not accept this invite for 7 days"),
FailedReason: new("Invitation expired. User did not accept this invite for 7 days"),
},
{
ID: github.Ptr(int64(2002)),
Email: github.Ptr("eve-inactive@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(2002)),
Email: new("eve-inactive@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated1},
FailedAt: &github.Timestamp{Time: expiredFailedAt1},
FailedReason: github.Ptr("user_was_inactive"),
FailedReason: new("user_was_inactive"),
},
}
failedPage2 := []*github.Invitation{
{
ID: github.Ptr(int64(2003)),
Email: github.Ptr("frank-expired@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated2},
FailedAt: &github.Timestamp{Time: expiredFailedAt2},
ID: new(int64(2003)),
Email: new("frank-expired@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated2},
FailedAt: &github.Timestamp{Time: expiredFailedAt2},
// Uppercase variant locks in case-insensitive matching.
FailedReason: github.Ptr("INVITATION EXPIRED"),
FailedReason: new("INVITATION EXPIRED"),
},
{
ID: github.Ptr(int64(2004)),
Email: github.Ptr("grace-unexpected@example.com"),
Inviter: &github.User{Login: github.Ptr("admin")},
ID: new(int64(2004)),
Email: new("grace-unexpected@example.com"),
Inviter: &github.User{Login: new("admin")},
CreatedAt: &github.Timestamp{Time: pendingCreated2},
FailedAt: &github.Timestamp{Time: expiredFailedAt2},
FailedReason: github.Ptr("unexpected_failure"),
FailedReason: new("unexpected_failure"),
},
}

newBuilder := func(httpClient *http.Client) *invitationResourceType {
gh := github.NewClient(httpClient)
gh := newTestGitHubClient(t, httpClient)
return InvitationBuilder(InvitationBuilderParams{
client: gh,
orgCache: newOrgNameCache(gh),
Expand Down
Loading
Loading