Skip to content

Commit

Permalink
Additional logging for logging the classes and classloaders of the IA…
Browse files Browse the repository at this point in the history
…MClientCallbackHandler and the AWSCredentialsCallback classes. (#38)

* Enable support for STS regional endpoints when configured to assume a role

In AWS VPCs without internet access which have the STS VPC endpoint created the region needs to be explicitly along with the environment variable AWS_STS_REGIONAL_ENDPOINTS=regional otherwise the AWS Java SDK will use the global STS endpoint.

* Additional logging for logging the classes and classloaders of the IAMClientCallbackHandler and the AWSCredentialsCallback classes.

Co-authored-by: Dan Vulpe <dvulpe@gmail.com>
  • Loading branch information
sayantacC and dvulpe committed Aug 23, 2021
1 parent b318611 commit 96a395b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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"));
}

}

0 comments on commit 96a395b

Please sign in to comment.