diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index bfca858..96a33e7 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -58,7 +58,10 @@ "tls" -> trim(label("Enable TLS", optional(boolean()))), "ssl" -> trim(label("Enable SSL", optional(boolean()))), "keystore" -> trim(label("Keystore", optional(text()))) - )(Ldap.apply)) + )(Ldap.apply)), + "lfs" -> mapping( + "serverUrl" -> trim(label("LDAP host", optional(text()))) + )(Lfs.apply) )(SystemSettings.apply).verifying { settings => Vector( if(settings.ssh && settings.baseUrl.isEmpty){ diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index c2aa28d..00199a4 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -53,6 +53,7 @@ ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x)) } } + settings.lfs.serverUrl.foreach { x => props.setProperty(LfsServerUrl, x) } using(new java.io.FileOutputStream(GitBucketConf)){ out => props.store(out, null) } @@ -109,7 +110,10 @@ getOptionValue(props, LdapKeystore, None))) } else { None - } + }, + Lfs( + getOptionValue(props, LfsServerUrl, None) + ) ) } } @@ -134,7 +138,8 @@ useSMTP: Boolean, smtp: Option[Smtp], ldapAuthentication: Boolean, - ldap: Option[Ldap]){ + ldap: Option[Ldap], + lfs: Lfs){ def baseUrl(request: HttpServletRequest): String = baseUrl.fold(request.baseUrl)(_.stripSuffix("/")) def sshAddress:Option[SshAddress] = @@ -176,6 +181,9 @@ port:Int, genericUser:String) + case class Lfs( + serverUrl: Option[String]) + val DefaultSshPort = 29418 val DefaultSmtpPort = 25 val DefaultLdapPort = 389 @@ -212,6 +220,7 @@ private val LdapTls = "ldap.tls" private val LdapSsl = "ldap.ssl" private val LdapKeystore = "ldap.keystore" + private val LfsServerUrl = "lfs.server_url" private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = defining(props.getProperty(key)){ value => diff --git a/src/main/scala/gitbucket/core/servlet/GitLfsBatchServlet.scala b/src/main/scala/gitbucket/core/servlet/GitLfsBatchServlet.scala index d592299..7b53ddf 100644 --- a/src/main/scala/gitbucket/core/servlet/GitLfsBatchServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitLfsBatchServlet.scala @@ -4,60 +4,59 @@ import org.json4s._ import org.json4s.jackson.Serialization.{read, write} - import java.util.Date +import gitbucket.core.service.SystemSettingsService + /** * Provides GitLFS Batch API. * * https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md */ -class GitLfsBatchServlet extends HttpServlet { +class GitLfsBatchServlet extends HttpServlet with SystemSettingsService { - // TODO GitLFS server url must be configurable - private val GitLfsServerUrl = "http://localhost:9090/git-lfs" - private implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats override protected def doPost(req: HttpServletRequest, res: HttpServletResponse): Unit = { val batchRequest = read[BatchRequest](req.getInputStream) + val settings = loadSystemSettings() - val batchResponse = batchRequest.operation match { - case "upload" => - BatchUploadResponse("basic", batchRequest.objects.map { requestObject => - BatchResponseObject( - requestObject.oid, - requestObject.size, - true, - Actions( - upload = Some(Action( - href = GitLfsServerUrl + "/" + requestObject.oid, - expires_at = new Date(System.currentTimeMillis + 60000) - )) - ) - ) - }) - case "download" => - BatchUploadResponse("basic", batchRequest.objects.map { requestObject => - BatchResponseObject( - requestObject.oid, - requestObject.size, - true, - Actions( - download = Some(Action( - href = GitLfsServerUrl + "/" + requestObject.oid, - expires_at = new Date(System.currentTimeMillis + 60000) - )) - ) - ) - }) + settings.lfs.serverUrl match { + case None => + throw new IllegalStateException("lfs.server_url is not configured.") + + case Some(serverUrl) => + val batchResponse = batchRequest.operation match { + case "upload" => + BatchUploadResponse("basic", batchRequest.objects.map { requestObject => + BatchResponseObject(requestObject.oid, requestObject.size, true, + Actions( + upload = Some(Action( + href = serverUrl + "/" + requestObject.oid, + expires_at = new Date(System.currentTimeMillis + 60000L) + )) + ) + ) + }) + case "download" => + BatchUploadResponse("basic", batchRequest.objects.map { requestObject => + BatchResponseObject(requestObject.oid, requestObject.size, true, + Actions( + download = Some(Action( + href = serverUrl + "/" + requestObject.oid, + expires_at = new Date(System.currentTimeMillis + 60000L) + )) + ) + ) + }) + } + + res.setContentType("application/vnd.git-lfs+json") + + val out = res.getWriter + out.print(write(batchResponse)) + out.flush() } - - res.setContentType("application/vnd.git-lfs+json") - - val out = res.getWriter - out.print(write(batchResponse)) - out.flush() } } diff --git a/src/main/scala/gitbucket/core/util/Directory.scala b/src/main/scala/gitbucket/core/util/Directory.scala index 6e24100..a1d603e 100644 --- a/src/main/scala/gitbucket/core/util/Directory.scala +++ b/src/main/scala/gitbucket/core/util/Directory.scala @@ -1,11 +1,9 @@ package gitbucket.core.util import java.io.File -import ControlUtil._ -import org.apache.commons.io.FileUtils /** - * Provides directories used by GitBucket. + * Provides directory locations used by GitBucket. */ object Directory { diff --git a/src/main/twirl/gitbucket/core/admin/system.scala.html b/src/main/twirl/gitbucket/core/admin/system.scala.html index b2a582d..fd63210 100644 --- a/src/main/twirl/gitbucket/core/admin/system.scala.html +++ b/src/main/twirl/gitbucket/core/admin/system.scala.html @@ -123,27 +123,25 @@
- Both of SSH host and Base URL are required if SSH access is enabled. -
@@ -157,14 +155,14 @@- Enable notification not only SMTP configuration if you want to send notification email. -
+