Merge "blobserver/google/cloudstorage: allow service accounts w/o GCE"
diff --git a/pkg/blobserver/google/cloudstorage/cloudstorage_test.go b/pkg/blobserver/google/cloudstorage/cloudstorage_test.go
index a64158d..7b43dc5 100644
--- a/pkg/blobserver/google/cloudstorage/cloudstorage_test.go
+++ b/pkg/blobserver/google/cloudstorage/cloudstorage_test.go
@@ -91,12 +91,12 @@
 		t.Fatal("bucket not provided in config file or as a flag.")
 	}
 	if *clientID == "" {
-		if !metadata.OnGCE() {
-			if *clientSecret == "" {
-				t.Fatal("client ID and client secret required. Obtain from https://console.developers.google.com/ > Project > APIs & Auth > Credentials. Should be a 'native' or 'Installed application'")
-			}
-		} else {
+		if *clientSecret == "" {
+			// Assume auto if neither the the clientID and clientSecret are specified
+			// A service account key should be specified using the GOOGLE_APPLICATION_CREDENTIALS environment variable.
 			*clientID = "auto"
+		} else {
+			t.Fatal("client ID and client secret must be specified together. Obtain from https://console.developers.google.com/ > Project > APIs & Auth > Credentials. Should be a 'native' or 'Installed application'")
 		}
 	}
 	if *configFile == "" {
@@ -107,7 +107,7 @@
 			ClientSecret: *clientSecret,
 			RedirectURL:  oauthutil.TitleBarRedirectURL,
 		}
-		if !metadata.OnGCE() {
+		if !metadata.OnGCE() && *clientID != "auto" {
 			token, err := oauth2.ReuseTokenSource(nil,
 				&oauthutil.TokenSource{
 					Config:    config,
diff --git a/pkg/blobserver/google/cloudstorage/storage.go b/pkg/blobserver/google/cloudstorage/storage.go
index 9bdb70f..7efaf11 100644
--- a/pkg/blobserver/google/cloudstorage/storage.go
+++ b/pkg/blobserver/google/cloudstorage/storage.go
@@ -38,7 +38,6 @@
 	"perkeep.org/pkg/blobserver/memory"
 	"perkeep.org/pkg/constants"
 
-	"cloud.google.com/go/compute/metadata"
 	"cloud.google.com/go/storage"
 	"go4.org/cloud/google/gcsutil"
 	"go4.org/ctxutil"
@@ -121,9 +120,6 @@
 		err error
 	)
 	if clientID == "auto" {
-		if !metadata.OnGCE() {
-			return nil, errors.New(`Cannot use "auto" client_id when not running on GCE`)
-		}
 		ts, err = google.DefaultTokenSource(ctx, storage.ScopeReadWrite)
 		if err != nil {
 			return nil, err