From aa45b7666e7f1a426763dbc177a4a60b1c8ba5b2 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 23 Nov 2022 23:56:36 +0800 Subject: [PATCH] feat: Support get CREDENTIAL_ENV_NAME from properties (#782) This closes #781. Signed-off-by: tison Signed-off-by: tison --- .../src/main/java/com/google/cloud/ServiceOptions.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 8ffb77eaf552..231b9040c949 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/java-core/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")