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

Replace deprecated Aws4Signer with AwsV4HttpSigner #9681

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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 @@ -28,12 +28,13 @@
import org.projectnessie.client.http.HttpAuthentication;
import org.projectnessie.client.http.HttpClient;
import org.projectnessie.client.http.RequestContext;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.auth.signer.params.Aws4SignerParams;
import software.amazon.awssdk.http.SdkHttpFullRequest;
import software.amazon.awssdk.http.SdkHttpMethod;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
import software.amazon.awssdk.regions.Region;

/**
Expand Down Expand Up @@ -108,17 +109,22 @@ public void applyToHttpClient(HttpClient.Builder client) {

@Override
public void applyToHttpRequest(RequestContext context) {
SdkHttpFullRequest modifiedRequest =
Aws4Signer.create()
SdkHttpFullRequest request =
prepareRequest(context.getUri(), context.getMethod(), context.getBody());
AwsCredentials identity = awsCredentialsProvider.resolveCredentials();
String signingName = "execute-api";
SdkHttpRequest modReq =
AwsV4HttpSigner.create()
.sign(
prepareRequest(context.getUri(), context.getMethod(), context.getBody()),
Aws4SignerParams.builder()
.signingName("execute-api")
.awsCredentials(awsCredentialsProvider.resolveCredentials())
.signingRegion(region)
.build());
for (Map.Entry<String, List<String>> entry :
modifiedRequest.toBuilder().headers().entrySet()) {
b -> {
b.request(request)
.identity(identity)
.putProperty(AwsV4HttpSigner.REGION_NAME, region.id())
.putProperty(AwsV4HttpSigner.SERVICE_SIGNING_NAME, signingName);
request.contentStreamProvider().ifPresent(b::payload);
})
.request();
for (Map.Entry<String, List<String>> entry : modReq.headers().entrySet()) {
if (context.containsHeader(entry.getKey())) {
continue;
}
Expand Down