From 7d145b2371033093ea13fd05520c90970a5ef363 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 4 Aug 2020 16:47:29 -0700 Subject: [PATCH] feat: add logging at FINE level for each step of ADC (#435) * feat: add logging at FINE level for each step of Application Default Credentials * chore: fix formatting * fix: standardize the debug message format --- .../google/auth/oauth2/ComputeEngineCredentials.java | 2 +- .../auth/oauth2/DefaultCredentialsProvider.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java index 364bb8265..e65e94ea6 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java @@ -253,7 +253,7 @@ static boolean runningOnComputeEngine( e); } } - LOGGER.log(Level.INFO, "Failed to detect whether we are running on Google Compute Engine."); + LOGGER.log(Level.FINE, "Failed to detect whether we are running on Google Compute Engine."); return false; } diff --git a/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java b/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java index afe317b25..78ad73066 100644 --- a/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java +++ b/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java @@ -145,6 +145,9 @@ private final GoogleCredentials getDefaultCredentialsUnsynchronized( GoogleCredentials credentials = null; String credentialsPath = getEnv(CREDENTIAL_ENV_VAR); if (credentialsPath != null && credentialsPath.length() > 0) { + LOGGER.log( + Level.FINE, + String.format("Attempting to load credentials from file: %s", credentialsPath)); InputStream credentialsStream = null; try { File credentialsFile = new File(credentialsPath); @@ -178,6 +181,11 @@ private final GoogleCredentials getDefaultCredentialsUnsynchronized( InputStream credentialsStream = null; try { if (isFile(wellKnownFileLocation)) { + LOGGER.log( + Level.FINE, + String.format( + "Attempting to load credentials from well known file: %s", + wellKnownFileLocation.getCanonicalPath())); credentialsStream = readStream(wellKnownFileLocation); credentials = GoogleCredentials.fromStream(credentialsStream, transportFactory); } @@ -198,17 +206,20 @@ private final GoogleCredentials getDefaultCredentialsUnsynchronized( // Then try GAE 7 standard environment if (credentials == null && isOnGAEStandard7() && !skipAppEngineCredentialsCheck()) { + LOGGER.log(Level.FINE, "Attempting to load credentials from GAE 7 Standard"); credentials = tryGetAppEngineCredential(); } // Then try Cloud Shell. This must be done BEFORE checking // Compute Engine, as Cloud Shell runs on GCE VMs. if (credentials == null) { + LOGGER.log(Level.FINE, "Attempting to load credentials from Cloud Shell"); credentials = tryGetCloudShellCredentials(); } // Then try Compute Engine and GAE 8 standard environment if (credentials == null) { + LOGGER.log(Level.FINE, "Attempting to load credentials from GCE"); credentials = tryGetComputeCredentials(transportFactory); }