Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Only log credentials provider failures when all providers have failed (
Browse files Browse the repository at this point in the history
…#38)

* Only log credentials provider failures when all providers fail

* Update gradle version to 5.3.1
  • Loading branch information
sdford authored Jun 7, 2018
1 parent 225e358 commit 6f2d18c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
version=5.3.0
version=5.3.1
groupId=com.nike
artifactId=cerberus-client
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -74,6 +75,7 @@ public CerberusCredentials getCredentials() {
return lastUsedProvider.getCredentials();
}

List<String> logMessages = new ArrayList<>();
for (final CerberusCredentialsProvider credentialsProvider : credentialsProviderList) {
try {
final CerberusCredentials credentials = credentialsProvider.getCredentials();
Expand All @@ -82,26 +84,30 @@ public CerberusCredentials getCredentials() {
lastUsedProvider = credentialsProvider;
return credentials;
}
} catch (CerberusClientException sce) {
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed to resolve Cerberus credentials with credential provider: {}. Moving " +
"on to next provider", credentialsProvider.getClass().toString(), sce);
} else {
LOGGER.info("Failed to resolve Cerberus credentials with credential provider: {} for reason: {} moving " +
"on to next provider", credentialsProvider.getClass().toString(), sce.getMessage());
}
} catch (CerberusClientException cce) {
String message = String.format("Failed to resolve Cerberus credentials with credential provider: %s for" +
"reason: %s moving on to next provider",
credentialsProvider.getClass().toString(),
cce.getMessage());
logMessages.add(message);
} catch (Exception e) {
// The catch all is so that we don't break the chain of providers.
// If we do get an unexpected exception, we should at least log it for review.
LOGGER.warn("Unexpected error attempting to get credentials with provider: "
+ credentialsProvider.getClass().getName(), e);
String message = String.format("Unexpected error attempting to get credentials with provider: %s. Reason: %s",
credentialsProvider.getClass().getName(),
e.getMessage());
LOGGER.debug(message, e);

logMessages.add(message);
}
}

for (String message : logMessages) {
LOGGER.info(message);
}
throw new CerberusClientException("Unable to find credentials from any provider in the specified chain!");
}


/**
* Returns the reuse last provider flag.
*
Expand Down

0 comments on commit 6f2d18c

Please sign in to comment.