Skip to content

Commit 8fcef4e

Browse files
authored
Adds S3CrossRegion clients and codegen for retrieving bucket name (#4008)
* Adds S3CrossRegion clients and codegen for retrieving bucket name * Removes codegen of bucket parameter since getValueForField() is better * Add back overloads
1 parent 496c37b commit 8fcef4e

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.internal.crossregion;
17+
18+
import java.util.Optional;
19+
import java.util.function.Function;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
21+
import software.amazon.awssdk.services.s3.DelegatingS3AsyncClient;
22+
import software.amazon.awssdk.services.s3.S3AsyncClient;
23+
import software.amazon.awssdk.services.s3.model.S3Request;
24+
25+
@SdkInternalApi
26+
public final class S3CrossRegionAsyncClient extends DelegatingS3AsyncClient {
27+
28+
public S3CrossRegionAsyncClient(S3AsyncClient s3Client) {
29+
super(s3Client);
30+
}
31+
32+
@Override
33+
protected <T extends S3Request, ReturnT> ReturnT invokeOperation(T request, Function<T, ReturnT> operation) {
34+
Optional<String> bucket = request.getValueForField("bucket", String.class);
35+
36+
if (!bucket.isPresent()) {
37+
return operation.apply(request);
38+
}
39+
40+
//TODO: add modifyRequest logic
41+
return operation.apply(request);
42+
}
43+
44+
private void handleOperationFailure(Throwable t, String bucket) {
45+
//TODO: handle failure case
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.internal.crossregion;
17+
18+
import java.util.Optional;
19+
import java.util.function.Function;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
21+
import software.amazon.awssdk.services.s3.DelegatingS3Client;
22+
import software.amazon.awssdk.services.s3.S3Client;
23+
import software.amazon.awssdk.services.s3.model.S3Request;
24+
25+
@SdkInternalApi
26+
public final class S3CrossRegionSyncClient extends DelegatingS3Client {
27+
28+
public S3CrossRegionSyncClient(S3Client s3Client) {
29+
super(s3Client);
30+
}
31+
32+
@Override
33+
protected <T extends S3Request, ReturnT> ReturnT invokeOperation(T request, Function<T, ReturnT> operation) {
34+
Optional<String> bucket = request.getValueForField("bucket", String.class);
35+
36+
if (bucket.isPresent()) {
37+
try {
38+
operation.apply(request); //TODO: add modifyRequest logic
39+
} catch (Exception e) {
40+
handleOperationFailure(e, bucket.get());
41+
}
42+
}
43+
44+
return operation.apply(request);
45+
}
46+
47+
private void handleOperationFailure(Throwable t, String bucket) {
48+
//TODO: handle failure case
49+
}
50+
}

0 commit comments

Comments
 (0)