Skip to content
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 @@ -27,6 +27,7 @@
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -443,9 +444,24 @@ public ProgressEvent<ModelT, CallbackT> done(Function<ResponseT, ProgressEvent<M
request.setRequestCredentialsProvider(v1CredentialsProvider);

try {
ResultT respose = requestFunction.apply(request);
logRequestMetadata(request, respose);
return respose;
ResultT response = requestFunction.apply(request);
logRequestMetadata(request, response);
return response;
} catch (final Throwable e) {
loggerProxy.log(String.format("Failed to execute remote function: {%s}", e.getMessage()));
throw e;
} finally {
request.setRequestCredentialsProvider(null);
}
}

public <RequestT extends AmazonWebServiceRequest> void injectCredentialsAndInvoke(final RequestT request,
final Consumer<RequestT> requestFunction) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also just make a void function for the v2 proxy as well? if we are tackling the v1 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think v2 functions are required to return a result and are never void. @ammokhov can you please confirm?


request.setRequestCredentialsProvider(v1CredentialsProvider);

try {
requestFunction.accept(request);
} catch (final Throwable e) {
loggerProxy.log(String.format("Failed to execute remote function: {%s}", e.getMessage()));
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public class AmazonWebServicesClientProxyTest {
//
private final AwsSessionCredentials MockCreds = AwsSessionCredentials.create("accessKeyId", "secretKey", "token");

//
// Empty method for testing injectCredentialsAndInvoke with void returns
//
public static void dummyMethod(DescribeStackEventsRequest request) {
}

@Test
public void testInjectCredentialsAndInvoke() {

Expand All @@ -102,6 +108,23 @@ public void testInjectCredentialsAndInvoke() {
assertThat(result).isEqualTo(expectedResult);
}

@Test
public void testInjectCredentialsAndInvokeWithVoidFunction() {

final LoggerProxy loggerProxy = mock(LoggerProxy.class);
final Credentials credentials = new Credentials("accessKeyId", "secretAccessKey", "sessionToken");

final AmazonWebServicesClientProxy proxy = new AmazonWebServicesClientProxy(loggerProxy, credentials, () -> 1000L);

final DescribeStackEventsRequest request = mock(DescribeStackEventsRequest.class);

proxy.injectCredentialsAndInvoke(request, AmazonWebServicesClientProxyTest::dummyMethod);

// ensure credentials are injected and then removed
verify(request).setRequestCredentialsProvider(any(AWSStaticCredentialsProvider.class));
verify(request).setRequestCredentialsProvider(eq(null));
}

@Test
public void testInjectCredentialsAndInvokeWithError() {

Expand Down