Skip to content

[Hackathon] Adds wrappers providing shortcuts to S3 getUrl and S3Presigner #3073

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

Merged
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
8 changes: 4 additions & 4 deletions docs/LaunchChangelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ The S3 client in 2.0 is drastically different from the client in 1.11, because i
| `disableRequesterPays` | `putBucketRequestPayment` |
| `doesBucketExist` | `doesBucketExist` or `headBucket` |
| `doesBucketExistV2` | `doesBucketExist` or `headBucket` |
| `doesObjectExist` | `headObject` |
| `doesObjectExist` | `doesObjectExist` or `headObject` |
| `enableRequesterPays` | `putBucketRequestPayment` |
| `generatePresignedUrl` | ~~Not Supported~~ [S3Presigner](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-s3-presign.html) |
| `generatePresignedUrl` | `presigner` or direct [S3Presigner](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-s3-presign.html) |
| `getBucketAccelerateConfiguration` | `getBucketAccelerateConfiguration` |
| `getBucketAcl` | `getBucketAcl` |
| `getBucketAnalyticsConfiguration` | `getBucketAnalyticsConfiguration` |
Expand All @@ -400,9 +400,9 @@ The S3 client in 2.0 is drastically different from the client in 1.11, because i
| `getObjectAsString` | `getObjectAsBytes().asUtf8String` |
| `getObjectMetadata` | `headObject` |
| `getObjectTagging` | `getObjectTagging` |
| `getResourceUrl` | [S3Utilities#getUrl](https://github.com/aws/aws-sdk-java-v2/blob/7428f629753c603f96dd700ca686a7b169fc4cd4/services/s3/src/main/java/software/amazon/awssdk/services/s3/S3Utilities.java#L140) |
| `getResourceUrl` | `getUrl` ([S3Utilities#getUrl](https://github.com/aws/aws-sdk-java-v2/blob/7428f629753c603f96dd700ca686a7b169fc4cd4/services/s3/src/main/java/software/amazon/awssdk/services/s3/S3Utilities.java#L140)) |
| `getS3AccountOwner` | `listBuckets` |
| `getUrl` | [S3Utilities#getUrl](https://github.com/aws/aws-sdk-java-v2/blob/7428f629753c603f96dd700ca686a7b169fc4cd4/services/s3/src/main/java/software/amazon/awssdk/services/s3/S3Utilities.java#L140) |
| `getUrl` | `getUrl` ([S3Utilities#getUrl](https://github.com/aws/aws-sdk-java-v2/blob/7428f629753c603f96dd700ca686a7b169fc4cd4/services/s3/src/main/java/software/amazon/awssdk/services/s3/S3Utilities.java#L140)) |
| `headBucket` | `headBucket` |
| `initiateMultipartUpload` | `createMultipartUpload` |
| `isRequesterPaysEnabled` | `getBucketRequestPayment` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@

package software.amazon.awssdk.services.s3.extensions;

import java.net.URL;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.SdkExtensionMethod;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Utilities;
import software.amazon.awssdk.services.s3.internal.extensions.DefaultS3ClientSdkExtension;
import software.amazon.awssdk.services.s3.internal.extensions.DeleteBucketAndAllContents;
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
import software.amazon.awssdk.services.s3.model.GetUrlRequest;
import software.amazon.awssdk.services.s3.model.ListObjectVersionsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;

/**
* Extension methods for the {@link S3Client} interface.
Expand Down Expand Up @@ -86,4 +91,35 @@ default void deleteBucketAndAllContents(String bucket) {
new DeleteBucketAndAllContents((S3Client) this).deleteBucketAndAllContents(bucket);
}

/**
* Shortcut to the {@link S3Utilities#getUrl(GetUrlRequest)} method.
*
* @param getUrlRequest The get URL request
* @return the URL for the object
*/
@SdkExtensionMethod
default URL getUrl(GetUrlRequest getUrlRequest) {
return ((S3Client) this).utilities().getUrl(getUrlRequest);
}

/**
* Shortcut to the {@link S3Utilities#getUrl(Consumer)} method.
*
* @param getUrlRequest The get URL request
* @return the URL for the object
*/
@SdkExtensionMethod
default URL getUrl(Consumer<GetUrlRequest.Builder> getUrlRequest) {
return ((S3Client) this).utilities().getUrl(getUrlRequest);
}

/**
* Convenience method to retrieve the {@link S3Presigner} in order to generate presigned methods.
*
* @return The presigner
*/
@SdkExtensionMethod
default S3Presigner presigner() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also expose individual methods here, like presignGetObject, presignPutObject, etc. But it would be a lot of duplication of interfaces. At the same time, it's more in-line with the methods being discovered as a first-class citizen on the native API. WDYT?

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 debated back and forth on this question and decided to not do it for the hackathon, since it is a lot of boilerplate. For "real" it's up for discussion but should be easy enough to add.

return S3Presigner.create();
}
}