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
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup java
uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
check-latest: true
distribution: 'zulu'

Expand Down
13 changes: 11 additions & 2 deletions cloudnet-rest-module/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ plugins {
alias(libs.plugins.juppiter)
}

repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
api(projects.webApi)
moduleLibrary(libs.guava)
Expand Down Expand Up @@ -49,8 +53,8 @@ dependencies {
compileOnly(libs.logbackCore)
compileOnly(libs.logbackClassic)

compileOnly("eu.cloudnetservice.cloudnet:node:4.0.0-RC10")
compileOnly("eu.cloudnetservice.cloudnet:bridge:4.0.0-RC10")
compileOnly("eu.cloudnetservice.cloudnet:node:4.0.0-RC11-SNAPSHOT")
compileOnly("eu.cloudnetservice.cloudnet:bridge:4.0.0-RC11-SNAPSHOT")
}

tasks.withType<Jar> {
Expand All @@ -65,6 +69,11 @@ tasks.withType<ShadowJar> {
}
}

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_22.toString()
targetCompatibility = JavaVersion.VERSION_22.toString()
}

moduleJson {
main = "eu.cloudnetservice.ext.modules.rest.CloudNetRestModule"
name = "CloudNet-Rest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package eu.cloudnetservice.ext.modules.rest;

import dev.derklaro.aerogel.SpecifiedInjector;
import dev.derklaro.aerogel.binding.BindingBuilder;
import eu.cloudnetservice.common.language.I18n;
import eu.cloudnetservice.driver.document.DocumentFactory;
import eu.cloudnetservice.driver.event.EventManager;
import eu.cloudnetservice.driver.inject.InjectionLayer;
import eu.cloudnetservice.driver.module.ModuleLifeCycle;
import eu.cloudnetservice.driver.module.ModuleProvider;
import eu.cloudnetservice.driver.module.ModuleTask;
import eu.cloudnetservice.driver.module.driver.DriverModule;
import eu.cloudnetservice.ext.modules.rest.config.RestConfiguration;
Expand All @@ -46,7 +48,9 @@
import eu.cloudnetservice.ext.rest.api.auth.RestUserManagementLoader;
import eu.cloudnetservice.ext.rest.api.factory.HttpComponentFactoryLoader;
import eu.cloudnetservice.ext.rest.validation.ValidationHandlerMethodContextDecorator;
import eu.cloudnetservice.node.TickLoop;
import eu.cloudnetservice.node.command.CommandProvider;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import lombok.NonNull;
import org.slf4j.Logger;
Expand All @@ -63,7 +67,7 @@ public void loadLanguageFile() {
}

@ModuleTask(order = 127, lifecycle = ModuleLifeCycle.STARTED)
public void initHttpServer(@NonNull InjectionLayer<?> injectionLayer) {
public void initHttpServer(@Named("module") @NonNull InjectionLayer<?> injectionLayer) {
var restConfig = this.readConfig(RestConfiguration.class, () -> RestConfiguration.DEFAULT, DocumentFactory.json());

// construct the http server component
Expand Down Expand Up @@ -124,16 +128,30 @@ public void registerRestCommand(@NonNull CommandProvider commandProvider) {
commandProvider.register(RestCommand.class);
}

@ModuleTask(lifecycle = ModuleLifeCycle.STARTED)
public void scheduleBridgeInitialization(
@NonNull TickLoop tickLoop,
@NonNull ModuleProvider moduleProvider,
@NonNull HttpServer server,
@NonNull @Named("module") InjectionLayer<SpecifiedInjector> moduleLayer
) {
// we want to register the bridge handlers after all modules are started
tickLoop.runTask(() -> CloudNetBridgeInitializer.installBridgeHandler(moduleProvider, server, moduleLayer));
}

@ModuleTask(lifecycle = ModuleLifeCycle.STARTED)
public void registerListener(@NonNull EventManager eventManager) {
eventManager.registerListener(RestUserUpdateListener.class);
eventManager.registerListener(CloudNetBridgeInitializer.class);
}

@ModuleTask(lifecycle = ModuleLifeCycle.STOPPED)
public void unregisterModule(@NonNull HttpServer httpServer) {
public void unregisterModule(
@NonNull HttpServer httpServer,
@Named("module") InjectionLayer<SpecifiedInjector> layer
) {
try {
httpServer.close();
layer.injector().removeConstructedBindings();
} catch (Exception exception) {
LOGGER.error("Unable to close http server while disabling cloudnet rest module.", exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import lombok.NonNull;
Expand Down Expand Up @@ -65,19 +64,12 @@ public final class JsonConfigurationDto implements Dto<JsonConfiguration> {
@NotNull
private final Map<String, String> ipAliases;

@Valid
@NotNull
private final Collection<HostAndPortDto> httpListeners;

@Valid
@NotNull
private final SSLConfigurationDto clientSslConfig;
@Valid
@NotNull
private final SSLConfigurationDto serverSslConfig;
@Valid
@NotNull
private final SSLConfigurationDto webSslConfig;

@NotNull
private final Document properties;
Expand All @@ -97,10 +89,8 @@ public JsonConfigurationDto(
String jvmCommand,
String hostAddress,
Map<String, String> ipAliases,
Collection<HostAndPortDto> httpListeners,
SSLConfigurationDto clientSslConfig,
SSLConfigurationDto serverSslConfig,
SSLConfigurationDto webSslConfig,
Document properties
) {
this.language = language;
Expand All @@ -117,10 +107,8 @@ public JsonConfigurationDto(
this.jvmCommand = jvmCommand;
this.hostAddress = hostAddress;
this.ipAliases = ipAliases;
this.httpListeners = httpListeners;
this.clientSslConfig = clientSslConfig;
this.serverSslConfig = serverSslConfig;
this.webSslConfig = webSslConfig;
this.properties = properties;
}

Expand All @@ -141,10 +129,8 @@ public JsonConfigurationDto(
config.javaCommand(this.jvmCommand);
config.hostAddress(this.hostAddress);
config.ipAliases(this.ipAliases);
config.httpListeners(Dto.toList(this.httpListeners));
config.clientSSLConfig(this.clientSslConfig.toEntity());
config.serverSSLConfig(this.serverSslConfig.toEntity());
config.webSSLConfig(this.webSslConfig.toEntity());
config.properties(this.properties);
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ public final class SSLConfigurationDto implements Dto<SSLConfiguration> {
private final Path certificatePath;
@NotNull
private final Path privateKeyPath;
private final String privateKeyPassword;

public SSLConfigurationDto(
boolean enabled,
boolean clientAuth,
Path trustCertificatePath,
Path certificatePath,
Path privateKeyPath
Path privateKeyPath,
String privateKeyPassword
) {
this.enabled = enabled;
this.clientAuth = clientAuth;
this.trustCertificatePath = trustCertificatePath;
this.certificatePath = certificatePath;
this.privateKeyPath = privateKeyPath;
this.privateKeyPassword = privateKeyPassword;
}

@Override
Expand All @@ -53,6 +56,7 @@ public SSLConfigurationDto(
this.clientAuth,
this.trustCertificatePath,
this.certificatePath,
this.privateKeyPath);
this.privateKeyPath,
this.privateKeyPassword);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,34 @@

package eu.cloudnetservice.ext.modules.rest.listener;

import eu.cloudnetservice.driver.event.EventListener;
import dev.derklaro.aerogel.SpecifiedInjector;
import eu.cloudnetservice.driver.inject.InjectionLayer;
import eu.cloudnetservice.driver.module.ModuleLifeCycle;
import eu.cloudnetservice.driver.module.ModuleProvider;
import eu.cloudnetservice.ext.modules.rest.v3.bridge.V3HttpHandlerPlayer;
import eu.cloudnetservice.ext.rest.api.HttpServer;
import eu.cloudnetservice.node.event.CloudNetNodePostInitializationEvent;
import jakarta.inject.Singleton;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
public class CloudNetBridgeInitializer {

private static final String BRIDGE_MODULE_NAME = "CloudNet-Bridge";

private static final Logger LOGGER = LoggerFactory.getLogger(CloudNetBridgeInitializer.class);

@EventListener
public void handleNodePostInit(
@NonNull CloudNetNodePostInitializationEvent event,
public static void installBridgeHandler(
@NonNull ModuleProvider moduleProvider,
@NonNull HttpServer server
@NonNull HttpServer server,
@NonNull InjectionLayer<SpecifiedInjector> moduleLayer
) {
var bridgeModule = moduleProvider.module(BRIDGE_MODULE_NAME);
if (bridgeModule == null || bridgeModule.moduleLifeCycle() != ModuleLifeCycle.STARTED) {
LOGGER.debug("Could not detect started {} module. Aborting http player initialization.", BRIDGE_MODULE_NAME);
return;
}

var layer = InjectionLayer.findLayerOf(this.getClass());
server.annotationParser().parseAndRegister(layer.instance(V3HttpHandlerPlayer.class));
server.annotationParser().parseAndRegister(moduleLayer.instance(V3HttpHandlerPlayer.class));
LOGGER.debug("Successfully registered V3HttpHandlerPlayer as {} is present", BRIDGE_MODULE_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public V3HttpHandlerModule(@NonNull ModulesHolder modulesHolder, @NonNull Module
// download the module
var target = this.moduleProvider.moduleDirectoryPath().resolve(entry.name() + ".jar");
Unirest.get(entry.url())
.connectTimeout(5000)
.requestTimeout(5000)
.thenConsume(rawResponse -> FileUtil.copy(rawResponse.getContent(), target));

// validate the downloaded file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.OutputStreamAppender;
import eu.cloudnetservice.common.concurrent.TaskUtil;
import eu.cloudnetservice.common.util.StringUtil;
import eu.cloudnetservice.driver.CloudNetVersion;
import eu.cloudnetservice.driver.module.ModuleProvider;
Expand Down Expand Up @@ -228,7 +229,7 @@ public void handle(@NonNull WebSocketChannel channel, @NonNull WebSocketFrameTyp
if (this.user.hasScope("cloudnet_rest:node_send_commands")) {
var commandLine = new String(bytes, StandardCharsets.UTF_8);
var commandSource = new DriverCommandSource();
V3HttpHandlerNode.this.commandProvider.execute(commandSource, commandLine).getOrNull();
TaskUtil.getOrDefault(V3HttpHandlerNode.this.commandProvider.execute(commandSource, commandLine), null);

for (var message : commandSource.messages()) {
this.channel.sendWebSocketFrame(WebSocketFrameType.TEXT, message);
Expand Down