Files
trufflehog/pkg/sources/github/connector_unauthenticated.go
Cody Rose ae793d7030 Enable GitHub Realtime authentication (#3929)
GitHub Realtime needs to be able to authenticate. This PR adds relevant fields to the relevant protobuf message, and exports/tweaks some stuff from the github source package to permit its (eventual) use by the GitHub Realtime implementation:

The Connector interface and its constructors are now exported
Connector.Clone now accepts additional clone arguments
The github-specific connection construction has been moved into github.go
The injected rate limit handler no longer accepts error reporters that it never uses
I also added an API endpoint field to the GitHub Realtime proto message, because we need that too and I was here.
2025-02-26 10:20:05 -05:00

39 lines
1.1 KiB
Go

package github
import (
"fmt"
gogit "github.com/go-git/go-git/v5"
"github.com/google/go-github/v67/github"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/git"
)
type unauthenticatedConnector struct {
apiClient *github.Client
}
var _ Connector = (*unauthenticatedConnector)(nil)
func NewUnauthenticatedConnector(apiEndpoint string) (Connector, error) {
const httpTimeoutSeconds = 60
httpClient := common.RetryableHTTPClientTimeout(int64(httpTimeoutSeconds))
apiClient, err := createGitHubClient(httpClient, apiEndpoint)
if err != nil {
return nil, fmt.Errorf("could not create API client: %w", err)
}
return &unauthenticatedConnector{
apiClient: apiClient,
}, nil
}
func (c *unauthenticatedConnector) APIClient() *github.Client {
return c.apiClient
}
func (c *unauthenticatedConnector) Clone(ctx context.Context, repoURL string, args ...string) (string, *gogit.Repository, error) {
return git.CloneRepoUsingUnauthenticated(ctx, repoURL, args...)
}