Skip to content

Commit

Permalink
fix: allow default credentials to work for GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
xytis committed Oct 13, 2024
1 parent 9779a84 commit 8ca12d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/tusd/cli/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func CreateComposer() {
// GCS_SERVICE_ACCOUNT_FILE environment variable.
gcsSAF := os.Getenv("GCS_SERVICE_ACCOUNT_FILE")
if gcsSAF == "" {
stderr.Fatalf("No service account file provided for Google Cloud Storage using the GCS_SERVICE_ACCOUNT_FILE environment variable.\n")
stdout.Printf("Attempting to use default GCS credentials because no GCS_SERVICE_ACCOUNT_FILE env var was provided\n")
}

service, err := gcsstore.NewGCSService(gcsSAF)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/tus/tusd/v2
// Specify the Go version needed for the Heroku deployment
// See https://github.com/heroku/heroku-buildpack-go#go-module-specifics
// +heroku goVersion go1.22
go 1.21.0
toolchain go1.22.7
go 1.22.1

toolchain go1.23.1

require (
cloud.google.com/go/storage v1.43.0
Expand Down
7 changes: 6 additions & 1 deletion pkg/gcsstore/gcsservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ type GCSService struct {
// NewGCSService returns a GCSService object given a GCloud service account file path.
func NewGCSService(filename string) (*GCSService, error) {
ctx := context.Background()
client, err := storage.NewClient(ctx, option.WithCredentialsFile(filename))
var opts []option.ClientOption
if filename != "" {
opts = append(opts, option.WithCredentialsFile(filename))
}
client, err := storage.NewClient(ctx, opts...)

if err != nil {
return nil, err
}
Expand Down

0 comments on commit 8ca12d9

Please sign in to comment.