Skip to content
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
10 changes: 1 addition & 9 deletions src/main/java/land/oras/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public Manifest pushArtifact(
public Layer pushBlob(ContainerRef containerRef, Path blob, Map<String, String> annotations) {
String digest = containerRef.getAlgorithm().digest(blob);
LOG.debug("Digest: {}", digest);
// This migh not works with registries performing HEAD request
if (hasBlob(containerRef.withDigest(digest))) {
LOG.info("Blob already exists: {}", digest);
return Layer.fromFile(blob, containerRef.getAlgorithm()).withAnnotations(annotations);
Expand Down Expand Up @@ -491,9 +492,6 @@ private HttpClient.ResponseWrapper<String> headBlob(ContainerRef containerRef) {
*/
@Override
public byte[] getBlob(ContainerRef containerRef) {
if (!hasBlob(containerRef)) {
throw new OrasException(new HttpClient.ResponseWrapper<>("", 404, Map.of()));
}
URI uri = URI.create(
"%s://%s".formatted(getScheme(), containerRef.forRegistry(this).getBlobsPath(this)));
HttpClient.ResponseWrapper<String> response = client.get(
Expand All @@ -510,9 +508,6 @@ public byte[] getBlob(ContainerRef containerRef) {

@Override
public void fetchBlob(ContainerRef containerRef, Path path) {
if (!hasBlob(containerRef)) {
throw new OrasException(new HttpClient.ResponseWrapper<>("", 404, Map.of()));
}
URI uri = URI.create(
"%s://%s".formatted(getScheme(), containerRef.forRegistry(this).getBlobsPath(this)));
HttpClient.ResponseWrapper<Path> response = client.download(
Expand All @@ -528,9 +523,6 @@ public void fetchBlob(ContainerRef containerRef, Path path) {

@Override
public InputStream fetchBlob(ContainerRef containerRef) {
if (!hasBlob(containerRef)) {
throw new OrasException(new HttpClient.ResponseWrapper<>("", 404, Map.of()));
}
URI uri = URI.create(
"%s://%s".formatted(getScheme(), containerRef.forRegistry(this).getBlobsPath(this)));
HttpClient.ResponseWrapper<InputStream> response = client.download(
Expand Down
21 changes: 20 additions & 1 deletion src/test/java/land/oras/PublicECRITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
@Execution(ExecutionMode.SAME_THREAD) // Avoid 429 Too Many Requests for unauthenticated requests to public ECR
class PublicECRITCase {

@Test
Expand All @@ -44,4 +45,22 @@ void shouldPullAnonymousIndex() {
Index index2 = registry.getIndex(containerRef2);
assertNotNull(index2);
}

@Test
@Disabled("https://github.com/oras-project/oras-java/issues/522")
void shouldPullManifest() {
Registry registry = Registry.builder().build();
ContainerRef containerRef = ContainerRef.parse(
"public.ecr.aws/docker/library/alpine@sha256:59855d3dceb3ae53991193bd03301e082b2a7faa56a514b03527ae0ec2ce3a95");
Manifest manifest = registry.getManifest(containerRef);
assertNotNull(manifest);
}

@Test
void shouldPullLayer() {
Registry registry = Registry.builder().build();
ContainerRef containerRef = ContainerRef.parse(
"public.ecr.aws/docker/library/alpine@sha256:589002ba0eaed121a1dbf42f6648f29e5be55d5c8a6ee0f8eaa0285cc21ac153");
registry.getBlob(containerRef);
}
}