mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 19:15:59 +01:00
Add new extension point: sshCommandProvider
This commit is contained in:
@@ -8,6 +8,7 @@ import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
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
|
||||
|
||||
/**
|
||||
@@ -241,6 +242,17 @@ abstract class Plugin {
|
||||
*/
|
||||
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 @@ abstract class Plugin {
|
||||
(suggestionProviders ++ suggestionProviders(registry, context, settings)).foreach { suggestionProvider =>
|
||||
registry.addSuggestionProvider(suggestionProvider)
|
||||
}
|
||||
(sshCommandProviders ++ sshCommandProviders(registry, context, settings)).foreach { sshCommandProvider =>
|
||||
registry.addSshCommandProvider(sshCommandProvider)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.github.gitbucket.solidbase.Solidbase
|
||||
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 @@ class PluginRegistry {
|
||||
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 @@ class PluginRegistry {
|
||||
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 @@ class PluginRegistry {
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -223,12 +223,19 @@ class GitCommandFactory(baseUrl: String, sshUrl: Option[String]) extends Command
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user