Skip to content

Commit

Permalink
Make Keycloak fail with an error when the persisted build options dif…
Browse files Browse the repository at this point in the history
…fers from those provided

Signed-off-by: Peter Zaoral <[email protected]>
  • Loading branch information
Pepo48 committed Sep 24, 2024
1 parent 8b87655 commit f7026ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public static void validateConfig(List<String> cliArgs, AbstractCommand abstract
if (options.includeRuntime) {
disabledMappers.addAll(PropertyMappers.getDisabledRuntimeMappers().values());
}

checkSpiOptions(options, ignoredBuildTime, ignoredRunTime);

for (OptionCategory category : abstractCommand.getOptionCategories()) {
Expand Down Expand Up @@ -429,7 +429,7 @@ public static void validateConfig(List<String> cliArgs, AbstractCommand abstract
Logger logger = Logger.getLogger(Picocli.class); // logger can't be instantiated in a class field

if (!ignoredBuildTime.isEmpty()) {
logger.warn(format("The following build time options have values that differ from what is persisted - the new values will NOT be used until another build is run: %s\n",
throw new RuntimeException(format("The build time options have values that differ from what is persisted - perform build run with the following options: %s\n",
String.join(", ", ignoredBuildTime)));
} else if (!ignoredRunTime.isEmpty()) {
logger.warn(format("The following run time options were found, but will be ignored during build time: %s\n",
Expand Down Expand Up @@ -459,15 +459,15 @@ private static void checkSpiOptions(IncludeOptions options, final List<String> i
continue;
}
boolean buildTimeOption = key.endsWith("-provider") || key.endsWith("-provider-default") || key.endsWith("-enabled");

ConfigValue configValue = Configuration.getConfigValue(key);
String configValueStr = configValue.getValue();

// don't consider missing or anything below standard env properties
if (configValueStr == null || configValue.getConfigSourceOrdinal() < 300) {
continue;
}

if (!options.includeBuildTime) {
if (buildTimeOption) {
String currentValue = getRawPersistedProperty(key).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ void warnSpiRuntimeAtBuildtime(LaunchResult result) {

@Test
@RawDistOnly(reason = "Containers are immutable")
void warnSpiBuildtimeAtRuntime(KeycloakDistribution dist) {
void errorSpiBuildtimeAtRuntime(KeycloakDistribution dist) {
CLIResult result = dist.run("build");
result.assertBuild();

result = dist.run("start", "--optimized", "--http-enabled=true", "--hostname-strict=false", "--spi-events-listener-jboss-logging-enabled=false");
result.assertMessage("The following build time options have values that differ from what is persisted - the new values will NOT be used until another build is run: kc.spi-events-listener-jboss-logging-enabled");
result.assertError("The build time options have values that differ from what is persisted - perform build run with the following options: kc.spi-events-listener-jboss-logging-enabled");
}

@Test
Expand Down Expand Up @@ -216,7 +216,7 @@ void testWarningWhenOverridingNonCliBuildOptionsDuringStart(KeycloakDistribution
cliResult.assertBuild();
dist.setEnvVar("KC_DB", "postgres");
cliResult = dist.run("start", "--optimized", "--hostname=localhost", "--http-enabled=true");
cliResult.assertMessage("The following build time options have values that differ from what is persisted - the new values will NOT be used until another build is run: kc.db");
cliResult.assertError("The build time options have values that differ from what is persisted - perform build run with the following options: kc.db");
}

@Test
Expand Down

0 comments on commit f7026ca

Please sign in to comment.