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
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<awaitability.version>4.3.0</awaitability.version>

<!-- Plugin version -->
<palantir.java.format.version>2.74.0</palantir.java.format.version>
<build.helper-maven-plugin.version>3.6.1</build.helper-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.15</jacoco-maven-plugin.version>
<spotless-maven-plugin.version>3.10.0</spotless-maven-plugin.version>
Expand Down Expand Up @@ -601,15 +600,14 @@
<version>${spotless-maven-plugin.version}</version>
<configuration>
<java>
<toggleOffOn />
<endWithNewline />
<shortenFullyQualifiedTypes />
<importOrder />
<indent>
<spaces>true</spaces>
</indent>
<palantirJavaFormat>
<!-- Until http://github.com/diffplug/spotless/issues/2468 -->
<version>${palantir.java.format.version}</version>
</palantirJavaFormat>
<palantirJavaFormat />
<removeUnusedImports />
<trimTrailingWhitespace />
</java>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/land/oras/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.io.ByteArrayInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -1176,7 +1177,7 @@ private String uploadChunks(ContainerRef ref, InputStream stream, long totalSize
Const.APPLICATION_OCTET_STREAM_HEADER_VALUE,
Const.CONTENT_RANGE_HEADER,
contentRange),
() -> new java.io.ByteArrayInputStream(chunk),
() -> new ByteArrayInputStream(chunk),
Scopes.of(ref),
authProvider);
logResponse(patchResponse);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/land/oras/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
@NullMarked
@OrasModel
@JsonInclude(JsonInclude.Include.NON_NULL)
public record Tags(String name, List<String> tags, @Nullable String last, @Nullable Integer n) {
public record Tags(
String name,
List<String> tags,
@Nullable String last,
@Nullable Integer n) {

/**
* Constructor without last
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/land/oras/auth/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@

package land.oras.auth;

// spotless:off
// Until https://github.com/diffplug/spotless/issues/3033
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpTimeoutException;
Expand Down Expand Up @@ -66,6 +74,7 @@
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// spotless:on

/**
* HTTP client for ORAS
Expand All @@ -87,12 +96,15 @@ public final class HttpClient {
/**
* The HTTP client builder
*/
// spotless:off
// Until https://github.com/diffplug/spotless/issues/3033
private final java.net.http.HttpClient.Builder builder;

/**
* The HTTP client
*/
private java.net.http.HttpClient client;
// spotless:on

/**
* Skip TLS verification
Expand Down Expand Up @@ -834,7 +846,7 @@ private static boolean isRetryableStatus(int statusCode) {
}

private static boolean isRetryableException(Exception e) {
return e instanceof HttpTimeoutException || e instanceof java.io.IOException;
return e instanceof HttpTimeoutException || e instanceof IOException;
}

private long computeRetryDelay(@Nullable HttpResponse<?> response, int attempt) {
Expand Down Expand Up @@ -989,7 +1001,10 @@ private void logRequest(HttpRequest request, byte[] body) {
* @param service The service (not on response but on HTTP headers)
*/
public record ResponseWrapper<T>(
T response, int statusCode, Map<String, String> headers, @Nullable String service) {}
T response,
int statusCode,
Map<String, String> headers,
@Nullable String service) {}

/**
* Insecure trust manager when skipping TLS verification
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/land/oras/auth/RegistriesConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ record ConfigFile(
@JsonProperty("short-name-mode") @Nullable ShortNameMode shortNameMode,
@JsonProperty("registry") @Nullable List<RegistryConfig> registries,
@JsonProperty("aliases") @Nullable Map<String, String> aliases,
@JsonProperty("unqualified-search-registries") @Nullable List<String> unqualifiedRegistries) {}

@JsonProperty("unqualified-search-registries") @Nullable
List<String> unqualifiedRegistries) {}

/**
* Get the list of unqualified registries.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/land/oras/policy/SigstoreVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -287,7 +288,7 @@ static byte[] preAuthEncoding(String payloadType, byte[] payload) {
* @return a non-null (possibly empty) list of successfully loaded public keys.
*/
static List<PublicKey> loadKeys(PolicyRequirement.SigstoreSigned requirement) {
java.util.List<PublicKey> keys = new java.util.ArrayList<>();
List<PublicKey> keys = new ArrayList<>();

// Single-key fields
PublicKey single = loadKey(requirement);
Expand Down Expand Up @@ -391,7 +392,8 @@ record DsseSignature(@JsonProperty("sig") @Nullable String sig) {}
* @param subject The subject
*/
@OrasModel
record InTotoStatement(@JsonProperty("subject") @Nullable List<Subject> subject) {}
record InTotoStatement(
@JsonProperty("subject") @Nullable List<Subject> subject) {}

/**
* An in-toto subject: a map of digest algorithm to hex value
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/land/oras/ContainerRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class ContainerRefTest {
@Execution(ExecutionMode.SAME_THREAD)
void shouldReadRegistriesConfig(@TempDir Path homeDir) throws Exception {
// language=toml
String config =
"""
String config = """
[[registry]]
location = "public.ecr.aws"
blocked = true
Expand Down Expand Up @@ -82,8 +81,7 @@ void shouldReadRegistriesConfig(@TempDir Path homeDir) throws Exception {
void shouldDetermineFromAlias(@TempDir Path homeDir) throws Exception {

// language=toml
String config =
"""
String config = """
[aliases]
"my-library/my-namespace"="localhost:5000/test"
"my-library"="localhost:5000/test2"
Expand All @@ -105,8 +103,7 @@ void shouldDetermineFromAlias(@TempDir Path homeDir) throws Exception {
void shouldRewriteAllSubdomainToLocalProxy(@TempDir Path homeDir) throws Exception {

// language=toml
String config =
"""
String config = """
[[registry]]
prefix = "*.example.com"
location = "localhost:5000/example-com"
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/land/oras/DockerIoITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ void shouldContainsCommonLinuxPlatform() {
void shouldCopyTagToInternalRegistryViaAlias(@TempDir Path homeDir) throws Exception {

// language=toml
String config =
"""
String config = """
[aliases]
"dockerhub-alpine" = "docker.io/library/alpine"
""";
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/land/oras/GitHubContainerRegistryITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,14 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception {
Path publicKeyPath = Path.of("src/test/resources/keys/sigstore/alpine-signed.pub");

// language=toml
String config =
"""
String config = """
[[registry]]
location = "ghcr.io"
insecure = false
""";

// language=json
Files.writeString(
path,
"""
Files.writeString(path, """
{
"default": [{"type": "reject"}],
"transports": {
Expand All @@ -104,8 +101,7 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception {
}
}
}
"""
.formatted(publicKeyPath.toAbsolutePath().toString()));
""".formatted(publicKeyPath.toAbsolutePath().toString()));
ContainersPolicy policy = ContainersPolicy.newPolicy(path);
TestUtils.createRegistriesConfFile(homeDir, config);
TestUtils.withHome(homeDir, () -> {
Expand All @@ -120,8 +116,7 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception {
@Execution(ExecutionMode.SAME_THREAD)
void shouldPullIndexWithAlias(@TempDir Path homeDir) throws Exception {
// language=toml
String config =
"""
String config = """
[aliases]
"oras"="ghcr.io/oras-project/oras"
""";
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/land/oras/HarborS3ITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ void shouldPushJenkinsLibArtifact() {
void shouldPushJenkinsScriptArtifact() {

// language=groovy
String jenkinsfile =
"""
String jenkinsfile = """
node {
stage('Build') {
echo 'Building...'
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/land/oras/LayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ void shouldHaveEmptyLayer() {

@Test
void shouldReadNullAnnotations() {
String json =
"""
String json = """
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
Expand All @@ -94,8 +93,7 @@ void shouldReadNullAnnotations() {

@Test
void shouldReadBlobData() {
String json =
"""
String json = """
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
Expand Down Expand Up @@ -155,14 +153,12 @@ private String emptyLayer() {
* @return The manifest
*/
private String sampleLayer() {
return Layer.fromJson(
"""
return Layer.fromJson("""
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"size": 32654
}
""")
.toJson();
""").toJson();
}
}
7 changes: 2 additions & 5 deletions src/test/java/land/oras/OCILayoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ void shouldPushSignedLayoutAndPullItAndValidateSignature(@TempDir Path homeDir)
Path policyPath = homeDir.resolve("policy.json");

// language=json
Files.writeString(
policyPath,
"""
Files.writeString(policyPath, """
{
"default": [{"type": "reject"}],
"transports": {
Expand All @@ -177,8 +175,7 @@ void shouldPushSignedLayoutAndPullItAndValidateSignature(@TempDir Path homeDir)
}
}
}
"""
.formatted(registry.getRegistry(), publicKeyPath.toAbsolutePath()));
""".formatted(registry.getRegistry(), publicKeyPath.toAbsolutePath()));
ContainersPolicy policy = ContainersPolicy.newPolicy(policyPath);

// Pull the manifest with the policy: the attached signature is fetched and verified.
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/land/oras/PlatformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void shouldTestUnknownPlatform() {
@Test
void shouldReadFromJson() {
// language=json
String json =
"""
String json = """
{
"architecture": "amd64",
"os": "linux"
Expand All @@ -125,8 +124,7 @@ void shouldReadFromJson() {
assertNull(platform.variant());
assertEquals(Platform.linuxAmd64(), platform);

json =
"""
json = """
{
"architecture": "unknown",
"os": "unknown"
Expand All @@ -139,8 +137,7 @@ void shouldReadFromJson() {
@Test
void shouldReadFromJsonWithOptionalValues() {
// language=json
String json =
"""
String json = """
{
"architecture": "amd64",
"variant": "v8",
Expand All @@ -164,8 +161,7 @@ void shouldReadFromJsonWithOptionalValues() {
.withVariant("v8"),
platform);

json =
"""
json = """
{
"architecture": "unknown",
"os": "unknown"
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/land/oras/PublicECRITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ void shouldDetermineEffectiveRegistryWithUnqualifiedSettings() throws Exception
void shouldRewriteDockerIOToPublicECR() throws Exception {

// language=toml
String config =
"""
String config = """
[[registry]]
prefix = "docker.io/library"
location = "public.ecr.aws/docker/library"
Expand Down
Loading
Loading