read GOOGLE_APPLICATION_CREDENTIALS_JSON if it is set

This commit is contained in:
Martin Karlsch 2021-10-05 18:17:13 +02:00
parent c1220175da
commit 090e652a76
1 changed files with 3 additions and 0 deletions

3
gcs.go
View File

@ -37,6 +37,9 @@ type GcsFs struct {
// You can provide additional options to be passed to the client creation, as per // You can provide additional options to be passed to the client creation, as per
// cloud.google.com/go/storage documentation // cloud.google.com/go/storage documentation
func NewGcsFS(ctx context.Context, opts ...option.ClientOption) (Fs, error) { func NewGcsFS(ctx context.Context, opts ...option.ClientOption) (Fs, error) {
if json := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON"); json != "" {
opts = append(opts, option.WithCredentialsJSON([]byte(json)))
}
client, err := storage.NewClient(ctx, opts...) client, err := storage.NewClient(ctx, opts...)
if err != nil { if err != nil {
return nil, err return nil, err