diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index 7f135e5..3cb5a48 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -8,6 +8,7 @@ import gitbucket.core.service.SystemSettingsService.SystemSettings import gitbucket.core.util.SyntaxSugars._ import io.github.gitbucket.solidbase.model.Version +import org.apache.sshd.server.Command import play.twirl.api.Html /** @@ -242,6 +243,17 @@ def suggestionProviders(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[SuggestionProvider] = Nil /** + * Override to add ssh command providers. + */ + val sshCommandProviders: Seq[PartialFunction[String, Command]] = Nil + + /** + * Override to add ssh command providers. + */ + def sshCommandProviders(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[PartialFunction[String, Command]] = Nil + + + /** * This method is invoked in initialization of plugin system. * Register plugin functionality to PluginRegistry. */ @@ -312,6 +324,9 @@ (suggestionProviders ++ suggestionProviders(registry, context, settings)).foreach { suggestionProvider => registry.addSuggestionProvider(suggestionProvider) } + (sshCommandProviders ++ sshCommandProviders(registry, context, settings)).foreach { sshCommandProvider => + registry.addSshCommandProvider(sshCommandProvider) + } } /** diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index ac3f20e..1517e60 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -22,6 +22,7 @@ import io.github.gitbucket.solidbase.manager.JDBCVersionManager import io.github.gitbucket.solidbase.model.Module import org.apache.commons.io.FileUtils +import org.apache.sshd.server.Command import org.slf4j.LoggerFactory import play.twirl.api.Html @@ -40,12 +41,9 @@ private val accountHooks = new ConcurrentLinkedQueue[AccountHook] private val receiveHooks = new ConcurrentLinkedQueue[ReceiveHook] receiveHooks.add(new ProtectedBranchReceiveHook()) - private val repositoryHooks = new ConcurrentLinkedQueue[RepositoryHook] private val issueHooks = new ConcurrentLinkedQueue[IssueHook] - private val pullRequestHooks = new ConcurrentLinkedQueue[PullRequestHook] - private val repositoryHeaders = new ConcurrentLinkedQueue[(RepositoryInfo, Context) => Option[Html]] private val globalMenus = new ConcurrentLinkedQueue[(Context) => Option[Link]] private val repositoryMenus = new ConcurrentLinkedQueue[(RepositoryInfo, Context) => Option[Link]] @@ -57,9 +55,9 @@ private val issueSidebars = new ConcurrentLinkedQueue[(Issue, RepositoryInfo, Context) => Option[Html]] private val assetsMappings = new ConcurrentLinkedQueue[(String, String, ClassLoader)] private val textDecorators = new ConcurrentLinkedQueue[TextDecorator] - private val suggestionProviders = new ConcurrentLinkedQueue[SuggestionProvider] suggestionProviders.add(new UserNameSuggestionProvider()) + private val sshCommandProviders = new ConcurrentLinkedQueue[PartialFunction[String, Command]]() def addPlugin(pluginInfo: PluginInfo): Unit = plugins.add(pluginInfo) @@ -178,6 +176,10 @@ def addSuggestionProvider(suggestionProvider: SuggestionProvider): Unit = suggestionProviders.add(suggestionProvider) def getSuggestionProviders: Seq[SuggestionProvider] = suggestionProviders.asScala.toSeq + + def addSshCommandProvider(sshCommandProvider: PartialFunction[String, Command]): Unit = sshCommandProviders.add(sshCommandProvider) + + def getSshCommandProviders: Seq[PartialFunction[String, Command]] = sshCommandProviders.asScala.toSeq } /** diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index 3be9f87..59a0b1f 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -223,12 +223,19 @@ import GitCommand._ logger.debug(s"command: $command") - command match { - case SimpleCommandRegex ("upload" , repoName) if(pluginRepository(repoName)) => new PluginGitUploadPack (repoName, routing(repoName)) - case SimpleCommandRegex ("receive", repoName) if(pluginRepository(repoName)) => new PluginGitReceivePack(repoName, routing(repoName)) - case DefaultCommandRegex("upload" , owner, repoName) => new DefaultGitUploadPack (owner, repoName) - case DefaultCommandRegex("receive", owner, repoName) => new DefaultGitReceivePack(owner, repoName, baseUrl, sshUrl) - case _ => new UnknownCommand(command) + val pluginCommand = PluginRegistry().getSshCommandProviders.collectFirst { + case f if f.isDefinedAt(command) => f(command) + } + + pluginCommand match { + case Some(x) => x + case None => command match { + case SimpleCommandRegex ("upload" , repoName) if(pluginRepository(repoName)) => new PluginGitUploadPack (repoName, routing(repoName)) + case SimpleCommandRegex ("receive", repoName) if(pluginRepository(repoName)) => new PluginGitReceivePack(repoName, routing(repoName)) + case DefaultCommandRegex("upload" , owner, repoName) => new DefaultGitUploadPack (owner, repoName) + case DefaultCommandRegex("receive", owner, repoName) => new DefaultGitReceivePack(owner, repoName, baseUrl, sshUrl) + case _ => new UnknownCommand(command) + } } }