diff options
author | Aniket Kumar <aniket.kumar@linaro.org> | 2023-09-29 16:20:35 +0530 |
---|---|---|
committer | Aniket Kumar <aniket.kumar@linaro.org> | 2023-10-02 16:37:49 +0000 |
commit | 32e16158fdea658b485d31db665fad162242e1a8 (patch) | |
tree | 6b0b8abf93686d3edde6619f5c24c484bee27ef5 | |
parent | a7401b0131a8899295f91ad96b3de47e12cb4ad6 (diff) |
Fix the warning to not appear while loading a plugin
Prior to this change, warning [1] was observed in the error logs for a
plugin which has exclusively bindings for SshExecuteCommandInterceptor/
SshCreateCommandInterceptor in the ssh module as outlined in the
documentation provided in references [2] and [3]. Fix this by skipping
the warning if those bindings are found.
[1] WARN com.google.gerrit.sshd.SshPluginStarterCallback : Plugin
<plugin_name> did not define its top-level command nor any
DynamicOptions com.google.inject.ConfigurationException: Guice
configuration errors:
[Guice/MissingImplementation]: No implementation for Command annotated
with @CommandName("<plugin_name>") was bound.
[2] https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ssh-command-creation-interception
[3] https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ssh-command-execution-interception
Bug: Issue 302408544
Change-Id: I80a2de37f2d38766b66315359779f7678f7062db
Release-Notes: Eliminated startup warning for plugins whose SshModule only provides Ssh*CommandInterceptors
-rw-r--r-- | java/com/google/gerrit/sshd/SshPluginStarterCallback.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java index 6e8590c888..55ecdfeecf 100644 --- a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java +++ b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java @@ -24,6 +24,10 @@ import com.google.inject.Inject; import com.google.inject.Key; import com.google.inject.Provider; import com.google.inject.Singleton; +import com.google.inject.TypeLiteral; +import com.google.inject.internal.MoreTypes; +import java.util.ArrayList; +import java.util.List; import org.apache.sshd.server.command.Command; @Singleton @@ -63,9 +67,9 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe try { return plugin.getSshInjector().getProvider(key); } catch (RuntimeException err) { - if (!providesDynamicOptions(plugin)) { + if (!providesDynamicOptions(plugin) && !providesCommandInterceptor(plugin)) { logger.atWarning().withCause(err).log( - "Plugin %s did not define its top-level command nor any DynamicOptions", + "Plugin %s did not define its top-level command, any DynamicOptions, nor any Ssh*CommandInterceptors", plugin.getName()); } } @@ -76,4 +80,16 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe private boolean providesDynamicOptions(Plugin plugin) { return dynamicBeans.plugins().contains(plugin.getName()); } + + private boolean providesCommandInterceptor(Plugin plugin) { + List<TypeLiteral<?>> typeLiterals = new ArrayList<>(2); + typeLiterals.add( + MoreTypes.canonicalizeForKey( + (TypeLiteral<?>) TypeLiteral.get(SshExecuteCommandInterceptor.class))); + typeLiterals.add( + MoreTypes.canonicalizeForKey( + (TypeLiteral<?>) TypeLiteral.get(SshCreateCommandInterceptor.class))); + return plugin.getSshInjector().getAllBindings().keySet().stream() + .anyMatch(key -> typeLiterals.contains(key.getTypeLiteral())); + } } |