spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Simplify signing urls for putting and getting S3 objects

Open maciejwalkowiak opened this issue 3 years ago • 3 comments

Add 2 methods (likely to S3Operations), one for getting signed url for fetching S3 object, second for getting signed url for putting an S3 object.

Work can start once https://github.com/awspring/spring-cloud-aws/pull/314 is merged.

maciejwalkowiak avatar Apr 14 '22 05:04 maciejwalkowiak

Hi @maciejwalkowiak , I would love to work on this

amit-github-personal avatar Apr 29 '22 18:04 amit-github-personal

The pull request 314 has now been merged so can i start working on this?

amit-github-personal avatar Apr 29 '22 18:04 amit-github-personal

@amit-github-personal apologies I missed this notification. Go ahead if you still feel like doing so!

maciejwalkowiak avatar Sep 04 '22 10:09 maciejwalkowiak

Is there any progress?

whisper-bye avatar Dec 27 '22 09:12 whisper-bye

@whisper-bye no, but if you would like to pick it up go ahead!

maciejwalkowiak avatar Dec 30 '22 06:12 maciejwalkowiak

@whisper-bye Do you want to work on this still? If not I can work on this.

SaiUpadhyayula avatar Jan 02 '23 17:01 SaiUpadhyayula

@SaiUpadhyayula please go ahead. I just made a quick fix.

placed my code here to assist anyone who may need it before a new release is available

    @Override
    public String download(String key) {
        var getObjectRequest = GetObjectRequest.builder()
                .bucket(OssBucketNameEnum.PRIVATE.getValue())
                .key(key)
                .build();

        var getObjectPresignRequest = GetObjectPresignRequest.builder()
                .getObjectRequest(getObjectRequest)
                .signatureDuration(Duration.ofHours(1))
                .build();

        try (var s3Presigner = S3Presigner.builder()
                .region(Region.of(Objects.requireNonNull(s3Properties.getRegion())))
                .credentialsProvider(getCredentialsProvider())
                .endpointOverride(s3Properties.getEndpoint())
                .build()) {
            var url = s3Presigner.presignGetObject(getObjectPresignRequest).url();
            return url.getPath() + "?" + url.getQuery();
        }
    }

    private ProfileCredentialsProvider getCredentialsProvider() {
        InputStream content;
        try {
            content = CharSource.wrap("[default]\n" + "aws_access_key_id=" + accessKey + "\n" + "aws_secret_access_key="
                            + secretKey + "\n")
                    .asByteSource(StandardCharsets.UTF_8)
                    .openStream();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        return ProfileCredentialsProvider.builder()
                .profileFile(ProfileFile.builder()
                        .content(content)
                        .type(ProfileFile.Type.CREDENTIALS)
                        .build())
                .build();
    }

whisper-bye avatar Jan 04 '23 09:01 whisper-bye

@maciejwalkowiak Please let me know what you think regarding the comments at the bottom of my draft when you get a chance.

Belair34 avatar Jan 11 '23 21:01 Belair34

@Belair34 I was also working on the ticket, you could have checked with me :)

https://github.com/awspring/spring-cloud-aws/compare/main...SaiUpadhyayula:spring-cloud-aws:gh-318

I was planning to finalize the changes during the weekend, but if you find time before and if you like, you can use the changes I did in my branch for your PR.

SaiUpadhyayula avatar Jan 12 '23 11:01 SaiUpadhyayula

@SaiUpadhyayula Sorry about that! In the past I've found that if there's not at least a draft or something within a week for this kind of issue then it ends up being up for grabs again, and I had time to do it right away so I just went for it. Next time I'll ask! Thanks for sharing your changes.

Belair34 avatar Jan 12 '23 19:01 Belair34