CB-632 unit 3: prefer fleetd.yaml, fall back to bridged.yaml; log the chosen file
This commit is contained in:
@@ -51,6 +51,7 @@ import io.javalin.Javalin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -80,8 +81,24 @@ public final class Fleetd {
|
||||
private static final long HERDR_WAIT_SECONDS = 30;
|
||||
private static final long HERDR_WAIT_POLL_MILLIS = 500;
|
||||
|
||||
/**
|
||||
* CB-632: prefer {@code fleetd.yaml} in {@code dir}; fall back to {@code bridged.yaml} when
|
||||
* the new name is not there. The operator's live file is still named {@code bridged.yaml},
|
||||
* so the old name keeps working until that file moves.
|
||||
*/
|
||||
static Path chooseDefaultConfigFile(Path dir) {
|
||||
Path fleetd = dir.resolve("fleetd.yaml");
|
||||
if (Files.exists(fleetd)) {
|
||||
return fleetd;
|
||||
}
|
||||
return dir.resolve("bridged.yaml");
|
||||
}
|
||||
|
||||
static void main(String[] args) {
|
||||
Path configPath = Path.of(args.length > 0 ? args[0] : "bridged.yaml");
|
||||
Path configPath = args.length > 0 ? Path.of(args[0]) : chooseDefaultConfigFile(Path.of(""));
|
||||
// CB-632: the config file is being renamed bridged.yaml -> fleetd.yaml. Name the file we
|
||||
// actually loaded, whichever of the two names it carries.
|
||||
log.info("Using configuration file {}", configPath);
|
||||
FleetConfig cfg = FleetConfig.load(configPath);
|
||||
// CB-594: report which secret env vars the config actually needs, by name, before anything
|
||||
// else can fail on a silently-empty one. A daemon started without a login shell (launchd)
|
||||
@@ -642,7 +659,7 @@ public final class Fleetd {
|
||||
log.warn("memberCredentials: absent or empty — the daemon will start anyway, and every "
|
||||
+ "member pane inherits the operator's WHOLE secret store, unblocked (CB-592's "
|
||||
+ "protection is lost). Add a memberCredentials: block (policy/allow/known) to "
|
||||
+ "bridged.yaml — see bridged.example.yaml — and restart.");
|
||||
+ "bridged.yaml — see fleetd.example.yaml — and restart.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package dev.ltms.fleet;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* CB-632: the no-argument config lookup prefers {@code fleetd.yaml} but still falls back to
|
||||
* {@code bridged.yaml}, because the operator's live file carries the old name until this rename
|
||||
* finishes. An explicit argument never goes through this logic, so these three cases cover all
|
||||
* of it.
|
||||
*/
|
||||
class FleetdDefaultConfigFileTest {
|
||||
|
||||
@Test
|
||||
void onlyFleetdYamlPresentChoosesFleetdYaml(@TempDir Path dir) throws Exception {
|
||||
Files.writeString(dir.resolve("fleetd.yaml"), "");
|
||||
assertEquals("fleetd.yaml", Fleetd.chooseDefaultConfigFile(dir).getFileName().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyBridgedYamlPresentFallsBackToBridgedYaml(@TempDir Path dir) throws Exception {
|
||||
Files.writeString(dir.resolve("bridged.yaml"), "");
|
||||
assertEquals("bridged.yaml", Fleetd.chooseDefaultConfigFile(dir).getFileName().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bothPresentPrefersFleetdYaml(@TempDir Path dir) throws Exception {
|
||||
Files.writeString(dir.resolve("fleetd.yaml"), "");
|
||||
Files.writeString(dir.resolve("bridged.yaml"), "");
|
||||
assertEquals("fleetd.yaml", Fleetd.chooseDefaultConfigFile(dir).getFileName().toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user