diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index 413ef4c..bb81092 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -23,6 +23,7 @@ "notification" -> trim(label("Notification", boolean())), "activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))), "ssh" -> trim(label("SSH access", boolean())), + "sshHost" -> trim(label("SSH host", optional(text()))), "sshPort" -> trim(label("SSH port", optional(number()))), "useSMTP" -> trim(label("SMTP", boolean())), "smtp" -> optionalIfNotChecked("useSMTP", mapping( @@ -50,9 +51,14 @@ "keystore" -> trim(label("Keystore", optional(text()))) )(Ldap.apply)) )(SystemSettings.apply).verifying { settings => - if(settings.ssh && settings.baseUrl.isEmpty){ - Seq("baseUrl" -> "Base URL is required if SSH access is enabled.") - } else Nil + Vector( + if(settings.ssh && settings.baseUrl.isEmpty){ + Some("baseUrl" -> "Base URL is required if SSH access is enabled.") + } else None, + if(settings.ssh && settings.sshHost.isEmpty){ + Some("sshHost" -> "SSH host is required if SSH access is enabled.") + } else None + ).flatten } private val pluginForm = mapping( diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index 082f05d..f23e63b 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -22,6 +22,7 @@ props.setProperty(Notification, settings.notification.toString) settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString)) props.setProperty(Ssh, settings.ssh.toString) + settings.sshHost.foreach(x => props.setProperty(SshHost, x.trim)) settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString)) props.setProperty(UseSMTP, settings.useSMTP.toString) if(settings.useSMTP) { @@ -76,6 +77,7 @@ getValue(props, Notification, false), getOptionValue[Int](props, ActivityLogLimit, None), getValue(props, Ssh, false), + getOptionValue[String](props, SshHost, None).map(_.trim), getOptionValue(props, SshPort, Some(DefaultSshPort)), getValue(props, UseSMTP, getValue(props, Notification, false)), // handle migration scenario from only notification to useSMTP if(getValue(props, UseSMTP, getValue(props, Notification, false))){ @@ -127,6 +129,7 @@ notification: Boolean, activityLogLimit: Option[Int], ssh: Boolean, + sshHost: Option[String], sshPort: Option[Int], useSMTP: Boolean, smtp: Option[Smtp], @@ -136,18 +139,10 @@ def sshAddress:Option[SshAddress] = for { - host <- sshHostFromBaseUrl + host <- sshHost if ssh } yield SshAddress(host, sshPort.getOrElse(DefaultSshPort)) - - // TODO host should be configured separately - private def sshHostFromBaseUrl:Option[String] = - for { - baseUrl <- baseUrl - m <- """^https?://([^:/]+)""".r.findFirstMatchIn(baseUrl) - } - yield m.group(1) } case class Ldap( @@ -186,6 +181,7 @@ private val Notification = "notification" private val ActivityLogLimit = "activity_log_limit" private val Ssh = "ssh" + private val SshHost = "ssh.host" private val SshPort = "ssh.port" private val UseSMTP = "useSMTP" private val SmtpHost = "smtp.host" diff --git a/src/main/twirl/gitbucket/core/admin/system.scala.html b/src/main/twirl/gitbucket/core/admin/system.scala.html index 33d94d0..3f07d07 100644 --- a/src/main/twirl/gitbucket/core/admin/system.scala.html +++ b/src/main/twirl/gitbucket/core/admin/system.scala.html @@ -111,15 +111,24 @@ Enable SSH access to git repository -
- -
- - +
+
+ +
+ + +
+
+
+ +
+ + +

- Base URL is required if SSH access is enabled. + Base URL is required if SSH access is enabled.

diff --git a/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala index 75b9744..c45b3e2 100644 --- a/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala +++ b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala @@ -102,6 +102,7 @@ notification = false, activityLogLimit = None, ssh = false, + sshHost = None, sshPort = None, useSMTP = false, smtp = None,