Simplify signing urls for putting and getting S3 objects
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.
Hi @maciejwalkowiak , I would love to work on this
The pull request 314 has now been merged so can i start working on this?
@amit-github-personal apologies I missed this notification. Go ahead if you still feel like doing so!
Is there any progress?
@whisper-bye no, but if you would like to pick it up go ahead!
@whisper-bye Do you want to work on this still? If not I can work on this.
@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();
}
@maciejwalkowiak Please let me know what you think regarding the comments at the bottom of my draft when you get a chance.
@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 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.