Runway 1.2.0

This commit is contained in:
Runway committed 2026-10-30 11:24:46 -06:00
1 parent 5fa0c1ef9f
commit 9144c206be
90 files changed
+2737 -554

No files matched your search

@@ -1,9 +1,12 @@
package mx.quest.database.postgresql;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import javax.sql.DataSource;
import mx.quest.database.spi.ConnectionSettings;
import mx.quest.database.spi.DatabaseProvider;
import mx.quest.database.spi.ProviderSettings;
import org.postgresql.ds.PGSimpleDataSource;
import org.postgresql.util.DriverInfo;
@@ -28,6 +31,25 @@ public final class PostgresProvider implements DatabaseProvider {
static final String JVM_TRUST = "org.postgresql.ssl.DefaultJavaSSLFactory";
static final String CA_FILE = "org.postgresql.ssl.LibPQFactory";
private final Supplier<ProviderSettings> running;
private final Supplier<ProviderSettings> saved;
/**
* Without settings, as before database 2.0.0: for building data sources only (tests).
*/
public PostgresProvider() {
this(() -> null, () -> null);
}
/**
* @param running the server settings the application started with, from this plugin's own settings page
* @param saved the server settings saved on that page now, which the next restart applies
*/
public PostgresProvider(Supplier<ProviderSettings> running, Supplier<ProviderSettings> saved) {
this.running = Objects.requireNonNull(running, "running");
this.saved = Objects.requireNonNull(saved, "saved");
}
@Override
public String id() {
return "postgresql";
@@ -76,4 +98,20 @@ public final class PostgresProvider implements DatabaseProvider {
private static int seconds(long value) {
return (int) Math.max(1, Math.min(Integer.MAX_VALUE, value));
}
@Override
public Optional<ProviderSettings> runningSettings() {
return Optional.ofNullable(withoutCollation(running.get()));
}
@Override
public Optional<ProviderSettings> savedSettings() {
return Optional.ofNullable(withoutCollation(saved.get()));
}
/** A collation is a MariaDB setting: never handed over from here, even when written into the file by hand. */
private static ProviderSettings withoutCollation(ProviderSettings s) {
return s == null ? null : new ProviderSettings(s.host(), s.port(), s.database(), s.username(), s.password(),
s.tls(), s.caCertificate(), null);
}
}
@@ -1,14 +1,33 @@
package mx.quest.database.postgresql;
import mx.quest.database.spi.ProviderSettings;
import mx.quest.database.spi.ProviderSettingsProps;
import mx.quest.runway.spi.service.PluginSettings;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** Registers the PostgreSQL provider; the database plugin collects it by type. */
/**
* Registers the PostgreSQL provider; the database plugin collects it by type. The server's settings are this plugin's
* own app-level settings ({@code runway.plugin.database-postgresql.*}, since database 2.0.0): the running ones as
* bound at startup, the password through {@link PluginSettings#appSecret}, and the saved ones through
* {@link PluginSettings#savedApp} for the connection test. With both providers installed the context holds two
* {@link ProviderSettingsProps} beans, hence the qualifier.
*/
@Configuration(proxyBeanMethods = false)
public class PostgresProviderConfig {
@Bean
public PostgresProvider databasePostgresqlProvider() {
return new PostgresProvider();
@ConfigurationProperties("runway.plugin.database-postgresql")
public ProviderSettingsProps databasePostgresqlSettings() {
return new ProviderSettingsProps();
}
@Bean
public PostgresProvider databasePostgresqlProvider(
@Qualifier("databasePostgresqlSettings") ProviderSettingsProps server, PluginSettings settings) {
return new PostgresProvider(() -> server.toSettings(settings.appSecret(ProviderSettings.PASSWORD)),
() -> ProviderSettings.read(settings::savedApp));
}
}
@@ -12,14 +12,21 @@ import java.sql.Statement;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import mx.quest.database.spi.ConnectionSettings;
import mx.quest.database.spi.ConnectionSettings.Tls;
import mx.quest.database.spi.ConnectionSettings;
import mx.quest.database.spi.ProviderSettings;
import mx.quest.runway.spi.service.PluginSettings;
import mx.quest.runway.spi.testkit.FakePluginSettings;
import org.junit.jupiter.api.Test;
import org.postgresql.ds.PGSimpleDataSource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
class PostgresProviderTest {
@@ -67,15 +74,66 @@ class PostgresProviderTest {
assertThat(new PostgresProvider().driverVersion()).isEqualTo("pgjdbc 42.7.10");
}
/** Turns on @ConfigurationProperties binding, as the kernel's context does. */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
static class Binding {
}
@Test
void theConfigurationRegistersOneProviderNamedForThePlugin() {
try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
PostgresProviderConfig.class)) {
try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
ctx.registerBean(PluginSettings.class, FakePluginSettings::new);
ctx.register(Binding.class, PostgresProviderConfig.class);
ctx.refresh();
assertThat(ctx.getBeanNamesForType(mx.quest.database.spi.DatabaseProvider.class))
.containsExactly("databasePostgresqlProvider");
for (String name : ctx.getBeanDefinitionNames()) {
if ("postgresProviderConfig".equals(ctx.getBeanDefinition(name).getFactoryBeanName())) {
assertThat(name).as("bean names carry the plugin id").startsWith("databasePostgresql");
}
}
}
}
@Test
void theServerSettingsAreThisPluginsOwnRunningAndSaved() {
try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
String prefix = "runway.plugin.database-postgresql.";
ctx.getEnvironment().getPropertySources().addFirst(new MapPropertySource("test", Map.of(
prefix + "host", "db.running", prefix + "port", "6000", prefix + "database", "runway",
prefix + "username", "rw", prefix + "password", "ENC(only-the-stored-form)",
prefix + "tls", "require", prefix + "collation", "utf8mb4_uca1400_ai_ci",
"runway.plugin.database.host", "not-this-plugins")));
ctx.registerBean(PluginSettings.class, () -> new FakePluginSettings().appSecret("password", "running-pw")
.savedApp("host", "db.saved").savedApp("database", "runway").savedApp("username", "rw2")
.savedApp("password", "saved-pw"));
ctx.register(Binding.class, PostgresProviderConfig.class);
ctx.refresh();
PostgresProvider provider = ctx.getBean(PostgresProvider.class);
ProviderSettings running = provider.runningSettings().orElseThrow();
assertThat(running.host()).isEqualTo("db.running");
assertThat(running.port()).isEqualTo("6000");
assertThat(running.username()).isEqualTo("rw");
assertThat(running.tls()).isEqualTo("require");
assertThat(running.password()).as("in clear, from appSecret").isEqualTo("running-pw");
assertThat(running.collation()).as("a MariaDB setting, never handed over").isNull();
ProviderSettings saved = provider.savedSettings().orElseThrow();
assertThat(saved.host()).isEqualTo("db.saved");
assertThat(saved.username()).isEqualTo("rw2");
assertThat(saved.password()).isEqualTo("saved-pw");
assertThat(saved.port()).as("unsaved: blank, the product's default").isNull();
}
}
@Test
void withoutSettingsTheProviderSaysNothingAsBeforeTwo() {
assertThat(new PostgresProvider().runningSettings()).isEmpty();
assertThat(new PostgresProvider().savedSettings()).isEmpty();
}
@Test
void theCompiledClassesLinkNoHostInternals() throws Exception {
Path classes = Path.of("target", "classes");