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
22 changes: 9 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@

<!-- Module Dependency Versions -->
<assertj.version>3.27.7</assertj.version>
<base.version>0.23.1</base.version>
<base.version>0.24.0</base.version>
<byte-buddy.version>1.18.4</byte-buddy.version>
<codemodel.version>0.21.1</codemodel.version>
<jackson-core.version>2.21.2</jackson-core.version>
<codemodel.version>0.21.2</codemodel.version>
<junit.version>6.0.3</junit.version>
<jakarta-inject.version>2.0.1</jakarta-inject.version>
<mockito.version>5.23.0</mockito.version>
Expand Down Expand Up @@ -236,22 +235,19 @@
<version>${codemodel.version}</version>
</dependency>

<!-- Upstream: base.build (extra) -->
<dependency>
<groupId>build.base</groupId>
<artifactId>base-json</artifactId>
<version>${base.version}</version>
</dependency>

<!-- Third-party -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-core.version}</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
Expand Down
9 changes: 2 additions & 7 deletions spawn-docker-jdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>build.base</groupId>
<artifactId>base-json</artifactId>
</dependency>

<!-- Test Dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import build.base.flow.Publicist;
import build.base.flow.Publisher;
import build.base.flow.SubscriberRegistry;
import build.base.json.JsonObject;
import build.base.option.Email;
import build.base.option.Password;
import build.base.option.Username;
Expand All @@ -51,7 +52,6 @@
import build.spawn.docker.option.DockerAPIVersion;
import build.spawn.docker.option.DockerRegistry;
import build.spawn.docker.option.IdentityToken;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand Down Expand Up @@ -142,9 +142,6 @@ protected AbstractSession(final InjectionFramework injectionFramework,
this.eventSubscriber = new CompletingSubscriber<>();
this.publicist.subscribe(this.eventSubscriber);

// establish an ObjectMapper for working with JSON
final ObjectMapper objectMapper = new ObjectMapper();

// establish the dependency injection context
this.context = injectionFramework
.newContext();
Expand All @@ -155,7 +152,6 @@ protected AbstractSession(final InjectionFramework injectionFramework,
this.context.bind(Session.class).to(this);
this.context.bind(AbstractSession.class).to(this);
this.context.bind((Class) getClass()).to(this);
this.context.bind(ObjectMapper.class).to(objectMapper);
this.context.bind(Configuration.class).to(this.configuration);
this.context.bind(Publicist.class).to(this.publicist);
this.context.bind(Publisher.class).to(this.publicist);
Expand All @@ -178,23 +174,23 @@ protected AbstractSession(final InjectionFramework injectionFramework,
.to(identityToken);

// establish the Authentication JSON
final var json = objectMapper.createObjectNode();
final var jsonBuilder = JsonObject.builder();

if (identityToken.isEmpty()) {
this.configuration.getOptionalValue(Username.class)
.ifPresent(username -> json.put("username", username));
.ifPresent(username -> jsonBuilder.put("username", username));
this.configuration.getOptionalValue(Password.class)
.ifPresent(password -> json.put("password", password));
.ifPresent(password -> jsonBuilder.put("password", password));
this.configuration.getOptionalValue(Email.class)
.ifPresent(email -> json.put("email", email));
.ifPresent(email -> jsonBuilder.put("email", email));
this.configuration.getOptionalValue(DockerRegistry.class)
.ifPresent(url -> json.put("serveraddress", url.getHost()));
.ifPresent(url -> jsonBuilder.put("serveraddress", url.getHost()));
}
else {
json.put("identitytoken", identityToken.get());
jsonBuilder.put("identitytoken", identityToken.get());
}

xRegistryAuth = Optional.of(json.toString());
xRegistryAuth = Optional.of(jsonBuilder.build().toJsonString());
}
else {
// determine the Configuration-provided IdentityToken
Expand All @@ -211,9 +207,11 @@ protected AbstractSession(final InjectionFramework injectionFramework,
xRegistryAuth = Optional.empty();
}
else {
final var json = objectMapper.createObjectNode();
json.put("identitytoken", identityToken.get());
xRegistryAuth = Optional.of(json.toString());
xRegistryAuth = Optional.of(
JsonObject.builder()
.put("identitytoken", identityToken.get())
.build()
.toJsonString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,14 +22,15 @@

import build.base.configuration.Configuration;
import build.base.foundation.Strings;
import build.base.json.Json;
import build.base.json.JsonObject;
import build.base.option.Email;
import build.base.option.Password;
import build.base.option.Username;
import build.spawn.docker.Session;
import build.spawn.docker.jdk.HttpTransport;
import build.spawn.docker.option.DockerRegistry;
import build.spawn.docker.option.IdentityToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.inject.Inject;

import java.io.IOException;
Expand All @@ -45,12 +46,6 @@
public class Authenticate
extends AbstractBlockingCommand<IdentityToken> {

/**
* The {@link ObjectMapper} for parsing json.
*/
@Inject
private ObjectMapper objectMapper;

/**
* The {@link Username} for authentication.
*/
Expand Down Expand Up @@ -79,27 +74,27 @@ public class Authenticate
protected HttpTransport.Request createRequest() {

// establish an ObjectNode containing the auth json
final var node = this.objectMapper.createObjectNode();
final var builder = JsonObject.builder()
.put("username", this.username.get())
.put("password", this.password.get())
.put("serveraddress", this.dockerRegistry.get().toString());

node.put("username", this.username.get());
node.put("password", this.password.get());
this.configuration.getOptionalValue(Email.class)
.ifPresent(email -> node.put("email", email));
node.put("serveraddress", this.dockerRegistry.get().toString());
.ifPresent(email -> builder.put("email", email));

return HttpTransport.Request
.post("/auth", node.toString().getBytes(StandardCharsets.UTF_8))
.post("/auth", builder.build().toJsonString().getBytes(StandardCharsets.UTF_8))
.withContentType("application/json");
}

@Override
protected IdentityToken createResult(final HttpTransport.Response response)
throws IOException {

final var body = response.bodyString();
final var json = this.objectMapper.readTree(body);

final var identityToken = json.get("IdentityToken").asText();
final var json = Json.parse(response.bodyString()).asObject();
final var identityToken = json.has("IdentityToken")
? json.getString("IdentityToken")
: "";

return Strings.isEmpty(identityToken)
? IdentityToken.of(this.password.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,12 +22,10 @@

import build.base.configuration.Configuration;
import build.base.flow.CompletingSubscriber;
import build.base.json.JsonValue;
import build.spawn.docker.Image;
import build.spawn.docker.jdk.HttpTransport;
import build.spawn.docker.option.ImageName;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.inject.Inject;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -56,12 +54,6 @@ public class BuildImage
*/
private final Configuration configuration;

/**
* The {@link ObjectMapper} for parsing json.
*/
@Inject
private ObjectMapper objectMapper;

/**
* Constructs a {@link BuildImage} {@link Command}.
*
Expand Down Expand Up @@ -97,17 +89,17 @@ protected Optional<String> createResult(final HttpTransport.Response response)

// establish the CompletingObserver observe when image ID has been generated
// (we want to capture {"aux":{"ID":"sha256:f65c628a75fe8b3e982165d1a4ceaf521fadab8da2136702c59e184d7be3e243"})
final var completingSubscriber = new CompletingSubscriber<JsonNode>();
final var completingSubscriber = new CompletingSubscriber<JsonValue>();
final var onImageBuilt = completingSubscriber.when(
json -> json.get("aux") != null,
json -> json.get("aux").get("ID").asText());
json -> json.asObject().has("aux"),
json -> json.get("aux").getString("ID"));

final CompletableFuture<?> onSuccess = completingSubscriber.when(
json -> json.get("stream") != null,
json -> json.get("stream").asText().contains("Successful"));
json -> json.asObject().has("stream"),
json -> json.getString("stream").contains("Successful"));

// process the entire InputStream from the Response to essentially wait for the image to be created
final JsonNodeInputStreamProcessor processor = new JsonNodeInputStreamProcessor(this.objectMapper);
final var processor = new JsonNodeInputStreamProcessor();
processor.process(response.bodyStream(), completingSubscriber);

// we've completed building when the ImageId is available and "Successful" has been observed
Expand Down
Loading
Loading