Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSL support #57

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions app/org/elastic4play/database/DBConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class DBConfiguration(
baseIndexName: String,
xpackUsername: Option[String],
xpackPassword: Option[String],
xpackSSL: Boolean,
xpackCAPath: Option[String],
xpackCertificatePath: Option[String],
xpackKeyPath: Option[String],
lifecycle: ApplicationLifecycle,
val version: Int,
implicit val ec: ExecutionContext,
Expand All @@ -63,6 +67,10 @@ class DBConfiguration(
configuration.get[String]("search.index"),
configuration.getOptional[String]("search.username"),
configuration.getOptional[String]("search.password"),
configuration.getOptional[Boolean]("search.ssl.enabled").getOrElse(false),
configuration.getOptional[String]("search.ssl.ca"),
configuration.getOptional[String]("search.ssl.certificate"),
configuration.getOptional[String]("search.ssl.key"),
lifecycle,
version,
ec,
Expand All @@ -76,15 +84,21 @@ class DBConfiguration(
val settings = Settings.builder()
settings.put("cluster.name", searchCluster)

val xpackClient = for {
username ← xpackUsername
if username.nonEmpty
password ← xpackPassword
if password.nonEmpty
_ = settings.put("xpack.security.user", s"$username:$password")
} yield XPackElasticClient(settings.build(), uri)
if (xpackUsername.isDefined && xpackPassword.isDefined) {
settings.put("xpack.security.user", s"${xpackUsername.toString}:${xpackPassword.toString}")
}
if (xpackSSL) {
settings.put("xpack.security.transport.ssl.enabled", "true")
}
if (xpackCAPath.isDefined) {
settings.put("xpack.ssl.certificate_authorities", xpackCAPath.toString)
}
if (xpackCertificatePath.isDefined && xpackKeyPath.isDefined) {
settings.put("xpack.ssl.certificate", xpackCertificatePath.toString)
settings.put("xpack.ssl.key", xpackKeyPath.toString)
}

xpackClient.getOrElse(TcpClient.transport(settings.build(), uri))
XPackElasticClient(settings.build(), uri)
}

/**
Expand Down Expand Up @@ -155,5 +169,5 @@ class DBConfiguration(
/**
* return a new instance of DBConfiguration that points to the previous version of the index schema
*/
def previousVersion: DBConfiguration = new DBConfiguration(searchHost, searchCluster, baseIndexName, xpackUsername, xpackPassword, lifecycle, version - 1, ec, actorSystem)
def previousVersion: DBConfiguration = new DBConfiguration(searchHost, searchCluster, baseIndexName, xpackUsername, xpackPassword, xpackSSL, xpackCAPath, xpackCertificatePath, xpackKeyPath, lifecycle, version - 1, ec, actorSystem)
}