Install "git-lfs-authenticate" SSH command when lfs.plugin is configured

SSH command registration was extended so that command gets registered
only in case when plugin is configured in gerrit.config.

Change-Id: Iffaf00775bdf1242e1fbe1dea15e5ce0bf912079
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
This commit is contained in:
Jacek Centkowski
2017-01-16 11:11:30 +01:00
committed by Jacek Centkowski
parent f104ccd30c
commit 31235233d0
4 changed files with 24 additions and 6 deletions

View File

@@ -87,6 +87,7 @@ import com.google.gerrit.sshd.SshKeyCacheImpl;
import com.google.gerrit.sshd.SshModule;
import com.google.gerrit.sshd.commands.DefaultCommandModule;
import com.google.gerrit.sshd.commands.IndexCommandsModule;
import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@@ -439,7 +440,8 @@ public class Daemon extends SiteProgram {
modules.add(new SshHostKeyModule());
}
modules.add(new DefaultCommandModule(slave,
sysInjector.getInstance(DownloadConfig.class)));
sysInjector.getInstance(DownloadConfig.class),
sysInjector.getInstance(LfsPluginAuthCommand.Module.class)));
if (!slave && indexType == IndexType.LUCENE) {
modules.add(new IndexCommandsModule());
}

View File

@@ -27,10 +27,13 @@ import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand;
/** Register the commands a Gerrit server supports. */
public class DefaultCommandModule extends CommandModule {
private final DownloadConfig downloadConfig;
private final LfsPluginAuthCommand.Module lfsPluginAuthModule;
public DefaultCommandModule(boolean slave, DownloadConfig downloadCfg) {
public DefaultCommandModule(boolean slave, DownloadConfig downloadCfg,
LfsPluginAuthCommand.Module module) {
slaveMode = slave;
downloadConfig = downloadCfg;
lfsPluginAuthModule = module;
}
@Override
@@ -124,7 +127,7 @@ public class DefaultCommandModule extends CommandModule {
alias(logging, "ls", ListLoggingLevelCommand.class);
alias(logging, "set", SetLoggingLevelCommand.class);
install(new LfsPluginAuthCommand.Module());
install(lfsPluginAuthModule);
}
private boolean sshEnabled() {

View File

@@ -16,11 +16,13 @@ package com.google.gerrit.sshd.plugin;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.sshd.CommandModule;
import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.jgit.lib.Config;
import org.kohsuke.args4j.Argument;
import java.util.ArrayList;
@@ -33,12 +35,21 @@ public class LfsPluginAuthCommand extends SshCommand {
}
public static class Module extends CommandModule {
private final boolean pluginProvided;
@Inject
Module(@GerritServerConfig Config cfg) {
pluginProvided = cfg.getString("lfs", null, "plugin") != null;
}
@Override
protected void configure() {
if (pluginProvided) {
command("git-lfs-authenticate").to(LfsPluginAuthCommand.class);
DynamicItem.itemOf(binder(), LfsSshPluginAuth.class);
}
}
}
private final DynamicItem<LfsSshPluginAuth> auth;
private final Provider<CurrentUser> user;

View File

@@ -72,6 +72,7 @@ import com.google.gerrit.sshd.SshKeyCacheImpl;
import com.google.gerrit.sshd.SshModule;
import com.google.gerrit.sshd.commands.DefaultCommandModule;
import com.google.gerrit.sshd.commands.IndexCommandsModule;
import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand;
import com.google.inject.AbstractModule;
import com.google.inject.CreationException;
import com.google.inject.Guice;
@@ -356,7 +357,8 @@ public class WebAppInitializer extends GuiceServletContextListener
modules.add(sysInjector.getInstance(SshModule.class));
modules.add(new SshHostKeyModule());
modules.add(new DefaultCommandModule(false,
sysInjector.getInstance(DownloadConfig.class)));
sysInjector.getInstance(DownloadConfig.class),
sysInjector.getInstance(LfsPluginAuthCommand.Module.class)));
if (indexType == IndexType.LUCENE) {
modules.add(new IndexCommandsModule());
}