(refs #1101)Add GitLFS setting

This commit is contained in:
Naoki Takezoe
2017-01-03 13:40:35 +09:00
parent e1802978d3
commit c67441b6d4
5 changed files with 82 additions and 64 deletions

View File

@@ -58,7 +58,10 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
"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){

View File

@@ -53,6 +53,7 @@ trait SystemSettingsService {
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 @@ trait SystemSettingsService {
getOptionValue(props, LdapKeystore, None)))
} else {
None
}
},
Lfs(
getOptionValue(props, LfsServerUrl, None)
)
)
}
}
@@ -134,7 +138,8 @@ object SystemSettingsService {
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 @@ object SystemSettingsService {
port:Int,
genericUser:String)
case class Lfs(
serverUrl: Option[String])
val DefaultSshPort = 29418
val DefaultSmtpPort = 25
val DefaultLdapPort = 389
@@ -212,6 +220,7 @@ object SystemSettingsService {
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 =>

View File

@@ -4,60 +4,59 @@ import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
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()
}
}

View File

@@ -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 {

View File

@@ -123,27 +123,25 @@
<label class="checkbox">
<input type="checkbox" id="ssh" name="ssh"@if(context.settings.ssh){ checked}/>
Enable SSH access to git repository
<span class="muted normal">(Both of SSH host and Base URL are required if SSH access is enabled)</span>
</label>
</fieldset>
<div class="ssh">
<div class="form-group">
<label class="control-label col-md-3" for="sshHost">SSH Host</label>
<label class="control-label col-md-3" for="sshHost">SSH host</label>
<div class="col-md-9">
<input type="text" id="sshHost" name="sshHost" class="form-control" value="@context.settings.sshHost"/>
<span id="error-sshHost" class="error"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="sshPort">SSH Port</label>
<label class="control-label col-md-3" for="sshPort">SSH port</label>
<div class="col-md-9">
<input type="text" id="sshPort" name="sshPort" class="form-control" value="@context.settings.sshPort"/>
<span id="error-sshPort" class="error"></span>
</div>
</div>
</div>
<p class="muted">
Both of SSH host and Base URL are required if SSH access is enabled.
</p>
<!--====================================================================-->
<!-- Authentication -->
<!--====================================================================-->
@@ -157,14 +155,14 @@
</fieldset>
<div class="ldap">
<div class="form-group">
<label class="control-label col-md-3" for="ldapHost">LDAP Host</label>
<label class="control-label col-md-3" for="ldapHost">LDAP host</label>
<div class="col-md-9">
<input type="text" id="ldapHost" name="ldap.host" class="form-control" value="@context.settings.ldap.map(_.host)"/>
<span id="error-ldap_host" class="error"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="ldapPort">LDAP Port</label>
<label class="control-label col-md-3" for="ldapPort">LDAP port</label>
<div class="col-md-9">
<input type="text" id="ldapPort" name="ldap.port" class="form-control input-mini" value="@context.settings.ldap.map(_.port)"/>
<span id="error-ldap_port" class="error"></span>
@@ -178,7 +176,7 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="ldapBindPassword">Bind Password</label>
<label class="control-label col-md-3" for="ldapBindPassword">Bind password</label>
<div class="col-md-9">
<input type="password" id="ldapBindPassword" name="ldap.bindPassword" class="form-control" value="@context.settings.ldap.map(_.bindPassword)"/>
<span id="error-ldap_bindPassword" class="error"></span>
@@ -259,31 +257,32 @@
<label class="checkbox">
<input type="checkbox" id="useSMTP" name="useSMTP" @if(context.settings.useSMTP){ checked}/>
SMTP
<span class="muted normal">(Enable notification not only SMTP configuration if you want to send notification email)</span>
</label>
</fieldset>
<div class="useSMTP">
<div class="form-group">
<label class="control-label col-md-3" for="smtpHost">SMTP Host</label>
<label class="control-label col-md-3" for="smtpHost">SMTP host</label>
<div class="col-md-9">
<input type="text" id="smtpHost" name="smtp.host" class="form-control" value="@context.settings.smtp.map(_.host)"/>
<span id="error-smtp_host" class="error"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="smtpPort">SMTP Port</label>
<label class="control-label col-md-3" for="smtpPort">SMTP port</label>
<div class="col-md-9">
<input type="text" id="smtpPort" name="smtp.port" class="form-control input-mini" value="@context.settings.smtp.map(_.port)"/>
<span id="error-smtp_port" class="error"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="smtpUser">SMTP User</label>
<label class="control-label col-md-3" for="smtpUser">SMTP user</label>
<div class="col-md-9">
<input type="text" id="smtpUser" name="smtp.user" class="form-control" value="@context.settings.smtp.map(_.user)"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="smtpPassword">SMTP Password</label>
<label class="control-label col-md-3" for="smtpPassword">SMTP password</label>
<div class="col-md-9">
<input type="password" id="smtpPassword" name="smtp.password" class="form-control" value="@context.settings.smtp.map(_.password)"/>
</div>
@@ -295,13 +294,13 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="fromAddress">FROM Address</label>
<label class="control-label col-md-3" for="fromAddress">FROM address</label>
<div class="col-md-9">
<input type="text" id="fromAddress" name="smtp.fromAddress" class="form-control" value="@context.settings.smtp.map(_.fromAddress)"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="fromName">FROM Name</label>
<label class="control-label col-md-3" for="fromName">FROM name</label>
<div class="col-md-9">
<input type="text" id="fromName" name="smtp.fromName" class="form-control" value="@context.settings.smtp.map(_.fromName)"/>
</div>
@@ -311,10 +310,20 @@
<input type="text" id="testAddress" size="30"/>
<input type="button" id="sendTestMail" value="Send"/>
</div>
<p class="muted">
Enable notification not only SMTP configuration if you want to send notification email.
</p>
</div>
<!--====================================================================-->
<!-- GitLFS -->
<!--====================================================================-->
<hr>
<label class="strong">
GitLFS <span class="muted normal">(Put LFS server url to enable GitLFS support)</span>
</label>
<div class="form-group">
<label class="control-label col-md-3" for="smtpHost">LFS server url</label>
<div class="col-md-9">
<input type="text" id="lfsServerUrl" name="lfs.serverUrl" class="form-control" value="@context.settings.lfs.serverUrl"/>
<span id="error-lfs_serverUrl" class="error"></span>
</div>
</div>
</div>
</div>