mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-12 00:15:50 +01:00
(refs #115)ServletContext is passed to Command
This commit is contained in:
@@ -64,7 +64,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
val owner = paths(1)
|
val owner = paths(1)
|
||||||
val repository = paths(2).replaceFirst("\\.git$", "")
|
val repository = paths(2).replaceFirst("\\.git$", "")
|
||||||
val baseURL = request.getRequestURL.toString.replaceFirst("/git/.*", "")
|
val baseURL = request.getRequestURL.toString.replaceFirst("/git/.*", "") // TODO Use base URL in SystemSettings
|
||||||
|
|
||||||
logger.debug("repository:" + owner + "/" + repository)
|
logger.debug("repository:" + owner + "/" + repository)
|
||||||
logger.debug("baseURL:" + baseURL)
|
logger.debug("baseURL:" + baseURL)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.apache.sshd.server.command.UnknownCommand
|
|||||||
import servlet.{Database, CommitLogHook}
|
import servlet.{Database, CommitLogHook}
|
||||||
import service.SystemSettingsService
|
import service.SystemSettingsService
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
||||||
|
import javax.servlet.ServletContext
|
||||||
|
|
||||||
|
|
||||||
object GitCommand {
|
object GitCommand {
|
||||||
@@ -94,7 +95,7 @@ class GitUploadPack(override val command: String) extends GitCommand(command: St
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitReceivePack(override val command: String) extends GitCommand(command: String) with SystemSettingsService {
|
class GitReceivePack(context: ServletContext, override val command: String) extends GitCommand(command: String) with SystemSettingsService {
|
||||||
// TODO Correct this info. where i get base url?
|
// TODO Correct this info. where i get base url?
|
||||||
val BaseURL: String = loadSystemSettings().baseUrl.getOrElse("http://localhost:8080")
|
val BaseURL: String = loadSystemSettings().baseUrl.getOrElse("http://localhost:8080")
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ class GitReceivePack(override val command: String) extends GitCommand(command: S
|
|||||||
val repository = git.getRepository
|
val repository = git.getRepository
|
||||||
val receive = new ReceivePack(repository)
|
val receive = new ReceivePack(repository)
|
||||||
receive.setPostReceiveHook(new CommitLogHook(owner, repositoryName, user, BaseURL))
|
receive.setPostReceiveHook(new CommitLogHook(owner, repositoryName, user, BaseURL))
|
||||||
Database(SshServer.getServletContext) withTransaction {
|
Database(context) withTransaction {
|
||||||
receive.receive(in, out, err)
|
receive.receive(in, out, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,14 +113,14 @@ class GitReceivePack(override val command: String) extends GitCommand(command: S
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitCommandFactory extends CommandFactory {
|
class GitCommandFactory(context: ServletContext) extends CommandFactory {
|
||||||
private val logger = LoggerFactory.getLogger(classOf[GitCommandFactory])
|
private val logger = LoggerFactory.getLogger(classOf[GitCommandFactory])
|
||||||
|
|
||||||
override def createCommand(command: String): Command = {
|
override def createCommand(command: String): Command = {
|
||||||
logger.debug(s"command: $command")
|
logger.debug(s"command: $command")
|
||||||
command match {
|
command match {
|
||||||
case GitCommand.CommandRegex("upload", owner, repoName) => new GitUploadPack(command)
|
case GitCommand.CommandRegex("upload", owner, repoName) => new GitUploadPack(command)
|
||||||
case GitCommand.CommandRegex("receive", owner, repoName) => new GitReceivePack(command)
|
case GitCommand.CommandRegex("receive", owner, repoName) => new GitReceivePack(context, command)
|
||||||
case _ => new UnknownCommand(command)
|
case _ => new UnknownCommand(command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,15 @@ object SshServer {
|
|||||||
|
|
||||||
private val server = org.apache.sshd.SshServer.setUpDefaultServer()
|
private val server = org.apache.sshd.SshServer.setUpDefaultServer()
|
||||||
|
|
||||||
// TODO think other way. this is for create database session
|
|
||||||
private var context: ServletContext = null
|
|
||||||
|
|
||||||
|
|
||||||
private def configure() = {
|
private def configure() = {
|
||||||
server.setPort(DEFAULT_PORT) // TODO read from config
|
server.setPort(DEFAULT_PORT) // TODO read from config
|
||||||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
||||||
server.setPublickeyAuthenticator(new PublicKeyAuthenticator)
|
server.setPublickeyAuthenticator(new PublicKeyAuthenticator)
|
||||||
server.setCommandFactory(new GitCommandFactory)
|
server.setCommandFactory(new GitCommandFactory(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
def start(context: ServletContext) = this.synchronized {
|
def start(context: ServletContext) = this.synchronized {
|
||||||
if (SSH_SERVICE_ENABLE) {
|
if (SSH_SERVICE_ENABLE) {
|
||||||
this.context = context
|
|
||||||
configure()
|
configure()
|
||||||
server.start()
|
server.start()
|
||||||
logger.info(s"Start SSH Server Listen on ${server.getPort}")
|
logger.info(s"Start SSH Server Listen on ${server.getPort}")
|
||||||
@@ -38,8 +33,6 @@ object SshServer {
|
|||||||
def stop() = {
|
def stop() = {
|
||||||
server.stop(true)
|
server.stop(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getServletContext = this.context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user