-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSL option for Quine OSS, Enterprise, and Novelty
* Switch from deprecated java.net.URL constructor to Akka's Uri The public constructor for java.net.URL is deprecated. Akka's Uri class works, and has Scala-friendly methods, and generally seems nicer to work with. * Determine resolvable URL once, pass that into the Recipe for status query output. Previously this feature required setting an advertised URL in the settings, which I'm assuming was an oversight. It now defaults to a URL based on the bind address if an advertised URL is not set. * Use helper functions for bind address stuff Novelty just does its own thing as far as this bind address stuff. GitOrigin-RevId: b2a1b36c0c4d3f2bce5015a555de9f240b589971
- Loading branch information
1 parent
9c76634
commit b2bddd0
Showing
6 changed files
with
96 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 36 additions & 6 deletions
42
quine/src/main/scala/com/thatdot/quine/app/config/WebServerConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
package com.thatdot.quine.app.config | ||
|
||
import java.net.URL | ||
import java.io.File | ||
import java.net.InetAddress | ||
|
||
import akka.http.scaladsl.model.Uri | ||
|
||
import com.thatdot.quine.util.{Host, Port} | ||
sealed abstract class WebserverConfig { | ||
|
||
final case class SslConfig(path: File, password: Array[Char]) | ||
|
||
trait WebServerConfig { | ||
def address: Host | ||
def port: Port | ||
def toURL: URL = new URL("http", address.asString, port.asInt, "") | ||
def ssl: Option[SslConfig] | ||
} | ||
final case class WebServerBindConfig( | ||
address: Host, | ||
port: Port, | ||
enabled: Boolean = true | ||
) extends WebserverConfig | ||
enabled: Boolean = true, | ||
ssl: Option[SslConfig] = (sys.env.get("SSL_KEYSTORE_PATH"), sys.env.get("SSL_KEYSTORE_PASSWORD")) match { | ||
case (None, None) => None | ||
case (Some(path), Some(password)) => Some(SslConfig(new File(path), password.toCharArray)) | ||
case (Some(_), None) => sys.error("'SSL_KEYSTORE_PATH' was specified but 'SSL_KEYSTORE_PASSWORD' was not") | ||
case (None, Some(_)) => sys.error("'SSL_KEYSTORE_PASSWORD' was specified but 'SSL_KEYSTORE_PATH' was not") | ||
} | ||
) extends WebServerConfig { | ||
|
||
val asResolveableUrl: Uri = { | ||
val bindHost: Uri.Host = Uri.Host(address.asString) | ||
// If the host of the bindUri is set to wildcard (INADDR_ANY and IN6ADDR_ANY) - i.e. "0.0.0.0" or "::" | ||
// present the URL as "localhost" to the user. This is necessary because while | ||
// INADDR_ANY as a source address means "bind to all interfaces", it cannot necessarily be | ||
// used as a destination address | ||
val resolveableHost = | ||
if (bindHost.inetAddresses.head.isAnyLocalAddress) | ||
Uri.Host(InetAddress.getLoopbackAddress) | ||
else | ||
bindHost | ||
|
||
Uri(if (ssl.isDefined) "https" else "http", Uri.Authority(resolveableHost, port.asInt)) | ||
} | ||
} | ||
final case class WebserverAdvertiseConfig( | ||
address: Host, | ||
port: Port | ||
) extends WebserverConfig | ||
) { | ||
def overrideHostAndPort(uri: Uri): Uri = uri.withHost(address.asString).withPort(port.asInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters