mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
feature: add settings for the ssh host
This commit is contained in:
@@ -23,6 +23,7 @@ trait SystemSettingsControllerBase extends ControllerBase {
|
|||||||
"notification" -> trim(label("Notification", boolean())),
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
||||||
"ssh" -> trim(label("SSH access", boolean())),
|
"ssh" -> trim(label("SSH access", boolean())),
|
||||||
|
"sshHost" -> trim(label("SSH host", optional(text()))),
|
||||||
"sshPort" -> trim(label("SSH port", optional(number()))),
|
"sshPort" -> trim(label("SSH port", optional(number()))),
|
||||||
"useSMTP" -> trim(label("SMTP", boolean())),
|
"useSMTP" -> trim(label("SMTP", boolean())),
|
||||||
"smtp" -> optionalIfNotChecked("useSMTP", mapping(
|
"smtp" -> optionalIfNotChecked("useSMTP", mapping(
|
||||||
@@ -50,9 +51,14 @@ trait SystemSettingsControllerBase extends ControllerBase {
|
|||||||
"keystore" -> trim(label("Keystore", optional(text())))
|
"keystore" -> trim(label("Keystore", optional(text())))
|
||||||
)(Ldap.apply))
|
)(Ldap.apply))
|
||||||
)(SystemSettings.apply).verifying { settings =>
|
)(SystemSettings.apply).verifying { settings =>
|
||||||
|
Vector(
|
||||||
if(settings.ssh && settings.baseUrl.isEmpty){
|
if(settings.ssh && settings.baseUrl.isEmpty){
|
||||||
Seq("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
Some("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
||||||
} else Nil
|
} 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(
|
private val pluginForm = mapping(
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ trait SystemSettingsService {
|
|||||||
props.setProperty(Notification, settings.notification.toString)
|
props.setProperty(Notification, settings.notification.toString)
|
||||||
settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString))
|
settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString))
|
||||||
props.setProperty(Ssh, settings.ssh.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))
|
settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString))
|
||||||
props.setProperty(UseSMTP, settings.useSMTP.toString)
|
props.setProperty(UseSMTP, settings.useSMTP.toString)
|
||||||
if(settings.useSMTP) {
|
if(settings.useSMTP) {
|
||||||
@@ -76,6 +77,7 @@ trait SystemSettingsService {
|
|||||||
getValue(props, Notification, false),
|
getValue(props, Notification, false),
|
||||||
getOptionValue[Int](props, ActivityLogLimit, None),
|
getOptionValue[Int](props, ActivityLogLimit, None),
|
||||||
getValue(props, Ssh, false),
|
getValue(props, Ssh, false),
|
||||||
|
getOptionValue[String](props, SshHost, None).map(_.trim),
|
||||||
getOptionValue(props, SshPort, Some(DefaultSshPort)),
|
getOptionValue(props, SshPort, Some(DefaultSshPort)),
|
||||||
getValue(props, UseSMTP, getValue(props, Notification, false)), // handle migration scenario from only notification to useSMTP
|
getValue(props, UseSMTP, getValue(props, Notification, false)), // handle migration scenario from only notification to useSMTP
|
||||||
if(getValue(props, UseSMTP, getValue(props, Notification, false))){
|
if(getValue(props, UseSMTP, getValue(props, Notification, false))){
|
||||||
@@ -127,6 +129,7 @@ object SystemSettingsService {
|
|||||||
notification: Boolean,
|
notification: Boolean,
|
||||||
activityLogLimit: Option[Int],
|
activityLogLimit: Option[Int],
|
||||||
ssh: Boolean,
|
ssh: Boolean,
|
||||||
|
sshHost: Option[String],
|
||||||
sshPort: Option[Int],
|
sshPort: Option[Int],
|
||||||
useSMTP: Boolean,
|
useSMTP: Boolean,
|
||||||
smtp: Option[Smtp],
|
smtp: Option[Smtp],
|
||||||
@@ -136,18 +139,10 @@ object SystemSettingsService {
|
|||||||
|
|
||||||
def sshAddress:Option[SshAddress] =
|
def sshAddress:Option[SshAddress] =
|
||||||
for {
|
for {
|
||||||
host <- sshHostFromBaseUrl
|
host <- sshHost
|
||||||
if ssh
|
if ssh
|
||||||
}
|
}
|
||||||
yield SshAddress(host, sshPort.getOrElse(DefaultSshPort))
|
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(
|
case class Ldap(
|
||||||
@@ -186,6 +181,7 @@ object SystemSettingsService {
|
|||||||
private val Notification = "notification"
|
private val Notification = "notification"
|
||||||
private val ActivityLogLimit = "activity_log_limit"
|
private val ActivityLogLimit = "activity_log_limit"
|
||||||
private val Ssh = "ssh"
|
private val Ssh = "ssh"
|
||||||
|
private val SshHost = "ssh.host"
|
||||||
private val SshPort = "ssh.port"
|
private val SshPort = "ssh.port"
|
||||||
private val UseSMTP = "useSMTP"
|
private val UseSMTP = "useSMTP"
|
||||||
private val SmtpHost = "smtp.host"
|
private val SmtpHost = "smtp.host"
|
||||||
|
|||||||
@@ -111,13 +111,22 @@
|
|||||||
Enable SSH access to git repository
|
Enable SSH access to git repository
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="form-group ssh">
|
<div class="ssh">
|
||||||
|
<div class="form-group">
|
||||||
|
<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="@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">
|
<div class="col-md-9">
|
||||||
<input type="text" id="sshPort" name="sshPort" class="form-control" value="@settings.sshPort"/>
|
<input type="text" id="sshPort" name="sshPort" class="form-control" value="@settings.sshPort"/>
|
||||||
<span id="error-sshPort" class="error"></span>
|
<span id="error-sshPort" class="error"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<p class="muted">
|
<p class="muted">
|
||||||
Base URL is required if SSH access is enabled.
|
Base URL is required if SSH access is enabled.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ class AvatarImageProviderSpec extends Specification with Mockito {
|
|||||||
notification = false,
|
notification = false,
|
||||||
activityLogLimit = None,
|
activityLogLimit = None,
|
||||||
ssh = false,
|
ssh = false,
|
||||||
|
sshHost = None,
|
||||||
sshPort = None,
|
sshPort = None,
|
||||||
useSMTP = false,
|
useSMTP = false,
|
||||||
smtp = None,
|
smtp = None,
|
||||||
|
|||||||
Reference in New Issue
Block a user