From 090e652a76bba9e787474d585bb5897a7c18d044 Mon Sep 17 00:00:00 2001 From: Martin Karlsch Date: Tue, 5 Oct 2021 18:17:13 +0200 Subject: [PATCH] read GOOGLE_APPLICATION_CREDENTIALS_JSON if it is set --- gcs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcs.go b/gcs.go index fd1f717..1135822 100644 --- a/gcs.go +++ b/gcs.go @@ -37,6 +37,9 @@ type GcsFs struct { // You can provide additional options to be passed to the client creation, as per // cloud.google.com/go/storage documentation 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...) if err != nil { return nil, err