Add properties for HTTP proxy setting

This commit is contained in:
Naoki Takezoe
2018-07-15 11:36:56 +09:00
parent 18a0c6c92a
commit 3ebc4e8e23

View File

@@ -70,6 +70,16 @@ trait SystemSettingsService {
props.setProperty(SkinName, settings.skinName.toString) props.setProperty(SkinName, settings.skinName.toString)
props.setProperty(ShowMailAddress, settings.showMailAddress.toString) props.setProperty(ShowMailAddress, settings.showMailAddress.toString)
props.setProperty(PluginNetworkInstall, settings.pluginNetworkInstall.toString) props.setProperty(PluginNetworkInstall, settings.pluginNetworkInstall.toString)
settings.proxy.foreach { proxy =>
props.setProperty(ProxyHost, proxy.host)
props.setProperty(ProxyPort, proxy.port.toString)
proxy.user.foreach { user =>
props.setProperty(ProxyUser, user)
}
proxy.password.foreach { password =>
props.setProperty(ProxyPassword, password)
}
}
using(new java.io.FileOutputStream(GitBucketConf)) { out => using(new java.io.FileOutputStream(GitBucketConf)) { out =>
props.store(out, null) props.store(out, null)
@@ -112,9 +122,7 @@ trait SystemSettingsService {
getOptionValue(props, SmtpFromName, None) getOptionValue(props, SmtpFromName, None)
) )
) )
} else { } else None,
None
},
getValue(props, LdapAuthentication, false), getValue(props, LdapAuthentication, false),
if (getValue(props, LdapAuthentication, false)) { if (getValue(props, LdapAuthentication, false)) {
Some( Some(
@@ -133,9 +141,7 @@ trait SystemSettingsService {
getOptionValue(props, LdapKeystore, None) getOptionValue(props, LdapKeystore, None)
) )
) )
} else { } else None,
None
},
getValue(props, OidcAuthentication, false), getValue(props, OidcAuthentication, false),
if (getValue(props, OidcAuthentication, false)) { if (getValue(props, OidcAuthentication, false)) {
Some( Some(
@@ -151,7 +157,17 @@ trait SystemSettingsService {
}, },
getValue(props, SkinName, "skin-blue"), getValue(props, SkinName, "skin-blue"),
getValue(props, ShowMailAddress, false), getValue(props, ShowMailAddress, false),
getValue(props, PluginNetworkInstall, false) getValue(props, PluginNetworkInstall, false),
if (getValue(props, ProxyHost, "").nonEmpty) {
Some(
Proxy(
getValue(props, ProxyHost, ""),
getValue(props, ProxyPort, 8080),
getOptionValue(props, ProxyUser, None),
getOptionValue(props, ProxyPassword, None)
)
)
} else None
) )
} }
} }
@@ -181,7 +197,8 @@ object SystemSettingsService {
oidc: Option[OIDC], oidc: Option[OIDC],
skinName: String, skinName: String,
showMailAddress: Boolean, showMailAddress: Boolean,
pluginNetworkInstall: Boolean pluginNetworkInstall: Boolean,
proxy: Option[Proxy]
) { ) {
def baseUrl(request: HttpServletRequest): String = def baseUrl(request: HttpServletRequest): String =
@@ -249,6 +266,13 @@ object SystemSettingsService {
fromName: Option[String] fromName: Option[String]
) )
case class Proxy(
host: String,
port: Int,
user: Option[String],
password: Option[String],
)
case class SshAddress(host: String, port: Int, genericUser: String) case class SshAddress(host: String, port: Int, genericUser: String)
case class Lfs(serverUrl: Option[String]) case class Lfs(serverUrl: Option[String])
@@ -298,6 +322,10 @@ object SystemSettingsService {
private val SkinName = "skinName" private val SkinName = "skinName"
private val ShowMailAddress = "showMailAddress" private val ShowMailAddress = "showMailAddress"
private val PluginNetworkInstall = "plugin.networkInstall" private val PluginNetworkInstall = "plugin.networkInstall"
private val ProxyHost = "proxy.host"
private val ProxyPort = "proxy.port"
private val ProxyUser = "proxy.user"
private val ProxyPassword = "proxy.password"
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = { private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = {
getSystemProperty(key).getOrElse(getEnvironmentVariable(key).getOrElse { getSystemProperty(key).getOrElse(getEnvironmentVariable(key).getOrElse {