Skip to content

Commit 30dfaab

Browse files
committed
Review feedback
1 parent c27aca1 commit 30dfaab

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,7 @@ void executeSingleUpload(
469469
S3BlobStore.configureRequestForMetrics(putRequest, blobStore, Operation.PUT_OBJECT, purpose);
470470

471471
try (AmazonS3Reference clientReference = s3BlobStore.clientReference()) {
472-
SocketAccess.doPrivilegedVoid(() -> {
473-
// WIP
474-
clientReference.client().putObject(putRequest);
475-
});
472+
SocketAccess.doPrivilegedVoid(() -> clientReference.client().putObject(putRequest));
476473
} catch (final AmazonClientException e) {
477474
throw new IOException("Unable to upload object [" + blobName + "] using a single upload", e);
478475
}

test/fixtures/aws-fixture-utils/src/main/java/fixture/aws/AwsCredentialsUtils.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ public enum AwsCredentialsUtils {
2626
/**
2727
* @return an authorization predicate that ensures the authorization header matches the given access key, region and service name.
2828
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a>
29+
* @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter
2930
*/
30-
public static BiPredicate<String, String> fixedAccessKey(String accessKey, String region, String service) {
31-
return mutableAccessKey(() -> accessKey, region, service);
31+
public static BiPredicate<String, String> fixedAccessKey(String accessKey, String region, String serviceName) {
32+
return mutableAccessKey(() -> accessKey, region, serviceName);
3233
}
3334

3435
/**
3536
* @return an authorization predicate that ensures the authorization header matches the access key supplied by the given supplier,
3637
* and also matches the given region and service name.
3738
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a>
39+
* @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter
3840
*/
39-
public static BiPredicate<String, String> mutableAccessKey(Supplier<String> accessKeySupplier, String region, String service) {
41+
public static BiPredicate<String, String> mutableAccessKey(Supplier<String> accessKeySupplier, String region, String serviceName) {
4042
return (authorizationHeader, sessionTokenHeader) -> {
4143
if (authorizationHeader == null) {
4244
return false;
@@ -50,21 +52,27 @@ public static BiPredicate<String, String> mutableAccessKey(Supplier<String> acce
5052

5153
if (region.equals("*")) {
5254
// skip region validation; TODO eliminate this when region is fixed in all tests
53-
return authorizationHeader.contains("/" + service + "/aws4_request, ");
55+
return authorizationHeader.contains("/" + serviceName + "/aws4_request, ");
5456
}
5557

56-
final var remainder = authorizationHeader.substring(expectedPrefix.length() + 8 /* YYYYMMDD not validated */);
57-
return remainder.startsWith("/" + region + "/" + service + "/aws4_request, ");
58+
final var remainder = authorizationHeader.substring(expectedPrefix.length() + "YYYYMMDD".length() /* date not validated */);
59+
return remainder.startsWith("/" + region + "/" + serviceName + "/aws4_request, ");
5860
};
5961
}
6062

6163
/**
6264
* @return an authorization predicate that ensures the access key, session token, region and service name all match the given values.
6365
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a>
66+
* @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter
6467
*/
65-
public static BiPredicate<String, String> fixedAccessKeyAndToken(String accessKey, String sessionToken, String region, String service) {
68+
public static BiPredicate<String, String> fixedAccessKeyAndToken(
69+
String accessKey,
70+
String sessionToken,
71+
String region,
72+
String serviceName
73+
) {
6674
Objects.requireNonNull(sessionToken);
67-
final var accessKeyPredicate = fixedAccessKey(accessKey, region, service);
75+
final var accessKeyPredicate = fixedAccessKey(accessKey, region, serviceName);
6876
return (authorizationHeader, sessionTokenHeader) -> accessKeyPredicate.test(authorizationHeader, sessionTokenHeader)
6977
&& sessionToken.equals(sessionTokenHeader);
7078
}

0 commit comments

Comments
 (0)