diff --git a/backend/cmd/generate/main.go b/backend/cmd/generate/main.go index 3c5541fc..e37e33cc 100644 --- a/backend/cmd/generate/main.go +++ b/backend/cmd/generate/main.go @@ -100,7 +100,8 @@ func main() { } } - backendFactory, err := factory.New(mainLogger) + ghToken := os.Getenv("GITHUB_TOKEN") + backendFactory, err := factory.New(mainLogger, ghToken) if err != nil { mainLogger.Error(ctx, err.Error()) os.Exit(1) diff --git a/backend/internal/e2e_test.go b/backend/internal/e2e_test.go index e56fbf5a..8bbd5a29 100644 --- a/backend/internal/e2e_test.go +++ b/backend/internal/e2e_test.go @@ -54,7 +54,7 @@ func TestE2E(t *testing.T) { Region: aws.Region(), } - backendFactory := tofutestutils.Must2(factory.New(log)) + backendFactory := tofutestutils.Must2(factory.New(log, "")) binaryName := "tofu" if runtime.GOOS == "windows" { binaryName += ".exe" @@ -96,7 +96,7 @@ func TestE2EDoubleRun(t *testing.T) { Region: aws.Region(), } - backendFactory := tofutestutils.Must2(factory.New(log)) + backendFactory := tofutestutils.Must2(factory.New(log, "")) binaryName := "tofu" if runtime.GOOS == "windows" { binaryName += ".exe" diff --git a/backend/internal/factory/factory.go b/backend/internal/factory/factory.go index 9769817e..a9dfdf4d 100644 --- a/backend/internal/factory/factory.go +++ b/backend/internal/factory/factory.go @@ -46,9 +46,10 @@ type S3Parameters struct { Region string } -func New(log logger.Logger) (BackendFactory, error) { +func New(log logger.Logger, githubToken string) (BackendFactory, error) { return &backendFactory{ - logger: log, + logger: log, + githubToken: githubToken, }, nil } @@ -67,7 +68,8 @@ type BackendFactory interface { } type backendFactory struct { - logger logger.Logger + logger logger.Logger + githubToken string } func (b backendFactory) Create( @@ -81,7 +83,7 @@ func (b backendFactory) Create( tofuBinaryPath string, approvedLicenses []string, ) (internal.Backend, error) { - return getBackend(ctx, b.logger, registryDir, workDir, destinationDir, blocklist, s3Params, parallelism, tofuBinaryPath, approvedLicenses) + return getBackend(ctx, b.logger, registryDir, workDir, destinationDir, blocklist, s3Params, parallelism, tofuBinaryPath, approvedLicenses, b.githubToken) } func getBackend( @@ -95,6 +97,7 @@ func getBackend( parallelism int, tofuBinaryPath string, approvedLicenses []string, + githubToken string, ) (internal.Backend, error) { if err := os.MkdirAll(workDir, 0700); err != nil { return nil, fmt.Errorf("failed to create workdir %s (%w)", workDir, err) @@ -117,6 +120,7 @@ func getBackend( github.WithSkipCleanupWorkingCopyOnClose(true), github.WithCheckoutRootDirectory(workDir), github.WithLogger(log), + github.WithToken(githubToken), ) if err != nil { return nil, err