Skip to content

Commit

Permalink
GH token handling
Browse files Browse the repository at this point in the history
Signed-off-by: AbstractionFactory <[email protected]>
  • Loading branch information
abstractionfactory committed Sep 10, 2024
1 parent 06c935e commit 6ffe85c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion backend/cmd/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions backend/internal/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions backend/internal/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -67,7 +68,8 @@ type BackendFactory interface {
}

type backendFactory struct {
logger logger.Logger
logger logger.Logger
githubToken string
}

func (b backendFactory) Create(
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -117,6 +120,7 @@ func getBackend(
github.WithSkipCleanupWorkingCopyOnClose(true),
github.WithCheckoutRootDirectory(workDir),
github.WithLogger(log),
github.WithToken(githubToken),
)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6ffe85c

Please sign in to comment.