Skip to content

Commit

Permalink
feat: add logging at FINE level for each step of ADC (#435)
Browse files Browse the repository at this point in the history
* 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 7d145b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 7d145b2

Please sign in to comment.