Skip to content
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

s3: do not perform entire GET to read meta-data #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.Headers;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectResult;
Expand Down Expand Up @@ -135,19 +137,15 @@ public AbstractDbArtifact getArtifactBySha1(final String tenant, final String sh
final String key = objectKey(tenant, sha1Hash);

LOG.info("Retrieving S3 object from bucket {} and key {}", s3Properties.getBucketName(), key);
try (final S3Object s3Object = amazonS3.getObject(s3Properties.getBucketName(), key)) {
if (s3Object == null) {
return null;
}

final ObjectMetadata s3ObjectMetadata = s3Object.getObjectMetadata();

return new S3Artifact(amazonS3, s3Properties, key, sha1Hash, new DbArtifactHash(sha1Hash, null, null),
s3ObjectMetadata.getContentLength(), s3ObjectMetadata.getContentType());
} catch (final IOException e) {
LOG.error("Could not verify S3Object", e);
var req = new GetObjectMetadataRequest(s3Properties.getBucketName(), key);
var objMeta = amazonS3.getObjectMetadata(req);
if (objMeta == null) {
return null;
}

return new S3Artifact(amazonS3, s3Properties, key, sha1Hash, new DbArtifactHash(sha1Hash, null, null),
objMeta.getContentLength(), objMeta.getContentType());
}

@Override
Expand Down