Skip to content

Commit

Permalink
Bug and test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Václav Muzikář <[email protected]>
  • Loading branch information
vmuzikar committed Nov 25, 2024
1 parent 142f185 commit 46f5001
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String toString() {

public static final Option<Level> LOG_LEVEL_CATEGORY = new OptionBuilder<>("log-level-<category>", Level.class)
.category(OptionCategory.LOGGING)
.description("The log level of a category.")
.description("The log level of a category. Takes precedence over the 'log-level' option.")
.strictExpectedValues(false)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.keycloak.common.profile.ProfileException;
import org.keycloak.config.DeprecatedMetadata;
Expand Down Expand Up @@ -101,6 +102,7 @@ private static class IncludeOptions {
}

private ExecutionExceptionHandler errorHandler = new ExecutionExceptionHandler();
private Set<PropertyMapper<?>> allowedMappers;
private List<String> uncrecognizedArgs = new ArrayList<>();

public void parseAndRun(List<String> cliArgs) {
Expand Down Expand Up @@ -333,7 +335,8 @@ public void validateConfig(List<String> cliArgs, AbstractCommand abstractCommand
if (arg.contains("=")) {
arg = arg.substring(0, arg.indexOf("="));
}
return PropertyMappers.getMapper(arg) != null;
PropertyMapper<?> mapper = PropertyMappers.getMapper(arg);
return mapper != null && mapper.hasWildcard() && allowedMappers.contains(mapper);
});
if (!uncrecognizedArgs.isEmpty()) {
throw new KcUnmatchedArgumentException(abstractCommand.getCommandLine().orElseThrow(), uncrecognizedArgs);
Expand Down Expand Up @@ -654,7 +657,7 @@ private static void addHelp(CommandSpec currentSpec) {
}
}

private static IncludeOptions getIncludeOptions(List<String> cliArgs, AbstractCommand abstractCommand, String commandName) {
private IncludeOptions getIncludeOptions(List<String> cliArgs, AbstractCommand abstractCommand, String commandName) {
IncludeOptions result = new IncludeOptions();
if (abstractCommand == null) {
return result;
Expand All @@ -672,7 +675,7 @@ private static IncludeOptions getIncludeOptions(List<String> cliArgs, AbstractCo
return result;
}

private static void addCommandOptions(List<String> cliArgs, CommandLine command) {
private void addCommandOptions(List<String> cliArgs, CommandLine command) {
if (command != null && command.getCommand() instanceof AbstractCommand) {
IncludeOptions options = getIncludeOptions(cliArgs, command.getCommand(), command.getCommandName());

Expand All @@ -684,7 +687,7 @@ private static void addCommandOptions(List<String> cliArgs, CommandLine command)
}
}

private static void addOptionsToCli(CommandLine commandLine, IncludeOptions includeOptions) {
private void addOptionsToCli(CommandLine commandLine, IncludeOptions includeOptions) {
final Map<OptionCategory, List<PropertyMapper<?>>> mappers = new EnumMap<>(OptionCategory.class);

// Since we can't run sanitizeDisabledMappers sooner, PropertyMappers.getRuntime|BuildTimeMappers() at this point
Expand All @@ -698,6 +701,8 @@ private static void addOptionsToCli(CommandLine commandLine, IncludeOptions incl
}

addMappedOptionsToArgGroups(commandLine, mappers);

allowedMappers = mappers.values().stream().flatMap(List::stream).collect(Collectors.toUnmodifiableSet());
}

private static <T extends Map<OptionCategory, List<PropertyMapper<?>>>> void combinePropertyMappers(T origMappers, T additionalMappers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public abstract class AbstractStartCommand extends AbstractCommand implements Ru
@Override
public void run() {
doBeforeRun();
HttpPropertyMappers.validateConfig();
HostnameV2PropertyMappers.validateConfig();
validateConfig();

if (isDevProfile()) {
Expand All @@ -56,6 +54,13 @@ protected void doBeforeRun() {

}

@Override
protected void validateConfig() {
super.validateConfig(); // need to run generic validation first as it also verifies unknown options
HttpPropertyMappers.validateConfig();
HostnameV2PropertyMappers.validateConfig();
}

@Override
public List<OptionCategory> getOptionCategories() {
EnumSet<OptionCategory> excludedCategories = excludedCategories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ protected void doBeforeRun() {

@Override
public void validateConfig() {
ExportPropertyMappers.validateConfig();
super.validateConfig();
ExportPropertyMappers.validateConfig();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.

Truststore:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.
--log-syslog-app-name <name>
Set the app name used when formatting the message in RFC5424 format. Default:
keycloak. Available only when Syslog is activated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.

Truststore:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.
--log-syslog-app-name <name>
Set the app name used when formatting the message in RFC5424 format. Default:
keycloak. Available only when Syslog is activated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.

Truststore:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.
--log-syslog-app-name <name>
Set the app name used when formatting the message in RFC5424 format. Default:
keycloak. Available only when Syslog is activated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.

Truststore:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.
--log-syslog-app-name <name>
Set the app name used when formatting the message in RFC5424 format. Default:
keycloak. Available only when Syslog is activated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.

Truststore:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ Logging:
The log level of the root category or a comma-separated list of individual
categories and their levels. For the root category, you don't need to
specify a category. Default: info.
--log-level-<category> <level>
The log level of a category. Takes precedence over the 'log-level' option.
Possible values are: off, fatal, error, warn, info, debug, trace, all, or a
custom one.
--log-syslog-app-name <name>
Set the app name used when formatting the message in RFC5424 format. Default:
keycloak. Available only when Syslog is activated.
Expand Down

0 comments on commit 46f5001

Please sign in to comment.