Ignore unknown plugin options in REST endpoints that support dynamic options

Some REST endpoints support dynamic options so that plugins can define
additional options for the REST endpoint. If callers start using the
plugin options, their requests will start failing as soon as the plugin
is disabled or uninstalled. This is unfortunate since plugin options are
mostly used to retrieve additional data which is optional. With this
change REST endpoints that support dynamic options now ignore unknown
plugin options, so that requests that use plugin options can still
succeed when a plugin is disabled or uninstalled.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ibf25127ce99bd858c7c02c38a07f58bd3e926908
This commit is contained in:
Edwin Kempin
2019-07-10 13:44:02 +02:00
parent 35b37e19eb
commit 6210be243d
3 changed files with 56 additions and 1 deletions

View File

@@ -25,6 +25,22 @@ import com.google.gerrit.common.Nullable;
* behavior if classes do not implement this interface).
*/
public interface UnknownOptionHandler {
/**
* Checks whether the given option name matches the naming pattern of options that are defined by
* plugins that were defined by registering a {@link
* com.google.gerrit.server.DynamicOptions.DynamicBean}.
*
* @param optionName name of the option
* @return {@code true} if it's a plugin option, otherwise {@code false}
*/
public static boolean isPluginOption(String optionName) {
// Options from plugins have the following name pattern: '--<plugin-name>--<option-name>'
if (optionName.startsWith("--")) {
optionName = optionName.substring(2);
}
return optionName.contains("--");
}
/**
* Whether an unknown option should be accepted.
*