From 811fbcd4d7ff45a9e052a990bd55e715fa98c7bc Mon Sep 17 00:00:00 2001
From: tison <wander4096@gmail.com>
Date: Wed, 30 Mar 2022 13:49:38 +0800
Subject: [PATCH] Support get CREDENTIAL_ENV_NAME from properties

This closes #781.

Signed-off-by: tison <wander4096@gmail.com>
---
 .../src/main/java/com/google/cloud/ServiceOptions.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
index 8ffb77eaf5..231b9040c9 100644
--- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
+++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
@@ -327,7 +327,11 @@ protected ServiceOptions(
     quotaProjectId =
         builder.quotaProjectId != null
             ? builder.quotaProjectId
-            : getValueFromCredentialsFile(System.getenv(CREDENTIAL_ENV_NAME), "quota_project_id");
+            : getValueFromCredentialsFile(getCredentialsPath(), "quota_project_id");
+  }
+
+  private static String getCredentialsPath() {
+    return System.getProperty(CREDENTIAL_ENV_NAME, System.getenv(CREDENTIAL_ENV_NAME));
   }
 
   /**
@@ -511,7 +515,7 @@ static boolean headerContainsMetadataFlavor(HttpResponse response) {
   }
 
   protected static String getServiceAccountProjectId() {
-    return getValueFromCredentialsFile(System.getenv(CREDENTIAL_ENV_NAME), "project_id");
+    return getValueFromCredentialsFile(getCredentialsPath(), "project_id");
   }
 
   @InternalApi("Visible for testing")