Skip to content
Permalink
Browse files
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
  • Loading branch information
chingor13 committed Aug 4, 2020
1 parent 7fae646 commit 7d145b2371033093ea13fd05520c90970a5ef363
@@ -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;
}

@@ -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);
}

0 comments on commit 7d145b2

Please sign in to comment.