mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(core): report the build version when FLOCI_VERSION is unset (#5768)
/health, /_floci/health and the TLS certificate metadata read FLOCI_VERSION and fell back to "dev". Only the Docker images set it, so a native binary run on the host reported "dev" and the floci-cli version check skipped it. One FlociVersion helper now resolves FLOCI_VERSION first, then the version the Maven build stamps into floci/version.properties (filtered, and included in the native image), and "dev" only when neither is known. It replaces five copies of the lookup. Refs #5767 Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
21184df828
commit
db8c441ed4
12 files changed
+126
-48
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The version this Floci build reports on {@code /health}, {@code /_floci/health} and in its
|
||||
* certificate metadata.
|
||||
*
|
||||
* <p>{@code FLOCI_VERSION} wins when set, so an image can still override it. Otherwise the
|
||||
* version stamped into {@code floci/version.properties} by the Maven build is used, which is what
|
||||
* a standalone native binary reports. {@code "dev"} remains only for a build that carries no
|
||||
* stamped version, such as an IDE run without resource processing.
|
||||
*
|
||||
* <p>Plain static code on purpose: {@link TlsConfigSource} runs while the configuration is still
|
||||
* being assembled, before CDI or {@code ConfigProvider} can be used.
|
||||
*/
|
||||
public final class FlociVersion {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(FlociVersion.class);
|
||||
|
||||
static final String RESOURCE = "floci/version.properties";
|
||||
static final String FALLBACK = "dev";
|
||||
|
||||
private static final String BUILD_VERSION = loadBuildVersion();
|
||||
|
||||
private FlociVersion() {
|
||||
}
|
||||
|
||||
public static String current() {
|
||||
return resolve(System.getenv("FLOCI_VERSION"), BUILD_VERSION);
|
||||
}
|
||||
|
||||
static String resolve(String override, String buildVersion) {
|
||||
if (override != null && !override.isBlank()) {
|
||||
return override;
|
||||
}
|
||||
if (buildVersion != null && !buildVersion.isBlank()) {
|
||||
return buildVersion;
|
||||
}
|
||||
return FALLBACK;
|
||||
}
|
||||
|
||||
private static String loadBuildVersion() {
|
||||
try (InputStream in = FlociVersion.class.getClassLoader().getResourceAsStream(RESOURCE)) {
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.load(in);
|
||||
String version = properties.getProperty("version");
|
||||
// An unfiltered copy (resources not processed by Maven) still holds the placeholder.
|
||||
if (version == null || version.startsWith("${")) {
|
||||
return null;
|
||||
}
|
||||
return version.trim();
|
||||
} catch (IOException e) {
|
||||
LOG.debugv("Could not read {0}: {1}", RESOURCE, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class TlsCertificateManager implements Resettable {
|
||||
CertificateGenerator.GeneratedCertificate issued = ca.issueServerCertificate("localhost", sans, keyAlgorithm, keyPair);
|
||||
|
||||
Path dir = tlsDir();
|
||||
CertificateMetadata metadata = CertificateMetadata.create(configuredHostnames, resolveFlociVersion());
|
||||
CertificateMetadata metadata = CertificateMetadata.create(configuredHostnames, FlociVersion.current());
|
||||
metadata.setLearnedHostnames(new ArrayList<>(learned));
|
||||
writeAtomically(dir.resolve(CERT_NAME), issued.certificatePem());
|
||||
writeAtomically(dir.resolve(METADATA_NAME), OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(metadata));
|
||||
@@ -302,9 +302,4 @@ public class TlsCertificateManager implements Resettable {
|
||||
Files.deleteIfExists(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
return env == null || env.isBlank() ? "dev" : env;
|
||||
}
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public class TlsConfigSource implements ConfigSource {
|
||||
private void persistMetadata(Path tlsDir, List<String> hostnames, List<String> learnedHostnames) {
|
||||
Path metadataFile = tlsDir.resolve(SERVER_METADATA_NAME);
|
||||
try {
|
||||
String version = resolveFlociVersion();
|
||||
String version = FlociVersion.current();
|
||||
CertificateMetadata metadata = CertificateMetadata.create(hostnames, version);
|
||||
metadata.setLearnedHostnames(learnedHostnames);
|
||||
|
||||
@@ -547,19 +547,6 @@ public class TlsConfigSource implements ConfigSource {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the Floci version from environment variable or defaults to "dev".
|
||||
*
|
||||
* @return Floci version string
|
||||
*/
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the hostname configuration has changed since the last certificate generation.
|
||||
* Loads the metadata file and compares the hostnames with the current configuration.
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.lifecycle;
|
||||
import io.github.hectorvent.floci.config.ContainerCaBundle;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociCertificateAuthority;
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardowns;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
@@ -63,7 +64,7 @@ public class EmulatorInfoController {
|
||||
this.certificateAuthority = certificateAuthority;
|
||||
this.config = config;
|
||||
this.dynamoDbBackendSelector = dynamoDbBackendSelector;
|
||||
this.version = resolveVersion();
|
||||
this.version = FlociVersion.current();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -207,12 +208,4 @@ public class EmulatorInfoController {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
static String resolveVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.lifecycle;
|
||||
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.ServiceRegistry;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
@@ -20,7 +21,7 @@ public class HealthController {
|
||||
@Inject
|
||||
public HealthController(ServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.version = resolveVersion();
|
||||
this.version = FlociVersion.current();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -31,12 +32,4 @@ public class HealthController {
|
||||
"original_edition", "floci-always-free",
|
||||
"version", version)).build();
|
||||
}
|
||||
|
||||
static String resolveVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.rds.proxy;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.CertificateMetadata;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
@@ -225,13 +226,8 @@ public class RdsProxyTlsCertificates {
|
||||
}
|
||||
|
||||
private void writeMetadata(Path metadataFile, List<String> sans) throws IOException {
|
||||
CertificateMetadata metadata = CertificateMetadata.create(sans, resolveFlociVersion());
|
||||
CertificateMetadata metadata = CertificateMetadata.create(sans, FlociVersion.current());
|
||||
String json = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(metadata);
|
||||
Files.writeString(metadataFile, json);
|
||||
}
|
||||
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
return (env != null && !env.isBlank()) ? env : "dev";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user