Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional logging for logging the classes and classloaders of the IAMClientCallbackHandler and the AWSCredentialsCallback classes. #38

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ public void close() {
@Override
public void handle(@NonNull Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (log.isDebugEnabled()) {
log.debug("Type information for callback: " + debugClassString(callback.getClass()) + " from "
+ debugClassString(this.getClass()));
}
if (callback instanceof AWSCredentialsCallback) {
handleCallback((AWSCredentialsCallback) callback);
} else {
String message = "Unsupported callback type:" + callback.getClass().getName();
String message = "Unsupported callback type: " + debugClassString(callback.getClass()) + " from "
+ debugClassString(this.getClass());
//We are breaking good practice and logging as well as throwing since this is where client side
//integrations might have trouble. Depending on the client framework either logging or throwing might
//surface the error more easily to the user.
Expand All @@ -82,6 +87,10 @@ public void handle(@NonNull Callback[] callbacks) throws IOException, Unsupporte
}
}

protected static String debugClassString(Class<?> clazz) {
return "class: " + clazz.getName() + " classloader: " + clazz.getClassLoader().toString();
}

protected void handleCallback(AWSCredentialsCallback callback) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Selecting provider {} to load credentials", provider.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ public void testDifferentCallback() {
assertTrue(callbackException.getMessage().startsWith("Unsupported"));
}

@Test
public void testDebugClassString() {
String debug1 = IAMClientCallbackHandler.debugClassString(this.getClass());
assertTrue(debug1.contains("software.amazon.msk.auth.iam.IAMClientCallbackHandlerTest"));
IAMClientCallbackHandler clientCallbackHandler = new IAMClientCallbackHandler();
String debug2 = IAMClientCallbackHandler.debugClassString(clientCallbackHandler.getClass());
assertTrue(debug2.contains("software.amazon.msk.auth.iam.IAMClientCallbackHandler"));
}

}