Merge branch 'stable-2.13'

* stable-2.13:
  Fix gitweb review link
  Install "git-lfs-authenticate" SSH command when lfs.plugin is configured
  Introduce "git-lfs-authenticate" SSH Command for LFS plugins

Change-Id: I368009619cb8550e059a60e9de9e7ac83e173090
This commit is contained in:
David Pursehouse
2017-01-20 10:46:43 +09:00
5 changed files with 28 additions and 9 deletions

View File

@@ -238,10 +238,11 @@ class GitwebServlet extends HttpServlet {
p.print(" if (( $secure && $ENV{'SERVER_PORT'} != 443)\n"); p.print(" if (( $secure && $ENV{'SERVER_PORT'} != 443)\n");
p.print(" || (!$secure && $ENV{'SERVER_PORT'} != 80)\n"); p.print(" || (!$secure && $ENV{'SERVER_PORT'} != 80)\n");
p.print(" );\n"); p.print(" );\n");
p.print(" $http_url .= qq{$ENV{'GERRIT_CONTEXT_PATH'}};\n"); p.print(" my $context = $ENV{'GERRIT_CONTEXT_PATH'};\n");
p.print(" chop($context);\n");
p.print(" $http_url .= qq{$context};\n");
p.print(" $http_url .= qq{/a}\n"); p.print(" $http_url .= qq{/a}\n");
p.print(" unless $ENV{'GERRIT_ANONYMOUS_READ'};\n"); p.print(" unless $ENV{'GERRIT_ANONYMOUS_READ'};\n");
p.print(" \n");
p.print(" push @git_base_url_list, $http_url;\n"); p.print(" push @git_base_url_list, $http_url;\n");
p.print("}\n"); p.print("}\n");
@@ -551,7 +552,7 @@ class GitwebServlet extends HttpServlet {
env.set("HTTP_" + name.toUpperCase().replace('-', '_'), value); env.set("HTTP_" + name.toUpperCase().replace('-', '_'), value);
} }
env.set("GERRIT_CONTEXT_PATH", req.getContextPath()); env.set("GERRIT_CONTEXT_PATH", req.getContextPath() + "/");
env.set("GERRIT_PROJECT_NAME", project.getProject().getName()); env.set("GERRIT_PROJECT_NAME", project.getProject().getName());
env.set("GITWEB_PROJECTROOT", env.set("GITWEB_PROJECTROOT",

View File

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

View File

@@ -27,10 +27,13 @@ import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand;
/** Register the commands a Gerrit server supports. */ /** Register the commands a Gerrit server supports. */
public class DefaultCommandModule extends CommandModule { public class DefaultCommandModule extends CommandModule {
private final DownloadConfig downloadConfig; 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; slaveMode = slave;
downloadConfig = downloadCfg; downloadConfig = downloadCfg;
lfsPluginAuthModule = module;
} }
@Override @Override
@@ -124,7 +127,7 @@ public class DefaultCommandModule extends CommandModule {
alias(logging, "ls", ListLoggingLevelCommand.class); alias(logging, "ls", ListLoggingLevelCommand.class);
alias(logging, "set", SetLoggingLevelCommand.class); alias(logging, "set", SetLoggingLevelCommand.class);
install(new LfsPluginAuthCommand.Module()); install(lfsPluginAuthModule);
} }
private boolean sshEnabled() { 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.extensions.registration.DynamicItem;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.sshd.CommandModule; import com.google.gerrit.sshd.CommandModule;
import com.google.gerrit.sshd.SshCommand; import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import org.eclipse.jgit.lib.Config;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import java.util.ArrayList; import java.util.ArrayList;
@@ -33,10 +35,19 @@ public class LfsPluginAuthCommand extends SshCommand {
} }
public static class Module extends CommandModule { public static class Module extends CommandModule {
private final boolean pluginProvided;
@Inject
Module(@GerritServerConfig Config cfg) {
pluginProvided = cfg.getString("lfs", null, "plugin") != null;
}
@Override @Override
protected void configure() { protected void configure() {
command("git-lfs-authenticate").to(LfsPluginAuthCommand.class); if (pluginProvided) {
DynamicItem.itemOf(binder(), LfsSshPluginAuth.class); command("git-lfs-authenticate").to(LfsPluginAuthCommand.class);
DynamicItem.itemOf(binder(), LfsSshPluginAuth.class);
}
} }
} }

View File

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