From 7c7015f8b1a39122798198b8529559fdf64e9ce2 Mon Sep 17 00:00:00 2001
From: Leonardo Menezes <mail@lmenezes.com>
Date: Thu, 4 Jan 2018 13:05:23 +0100
Subject: [PATCH] fixed deprecations

---
 app/controllers/AuthController.scala           |  2 +-
 app/controllers/auth/AuthConfig.scala          |  2 +-
 .../auth/AuthenticationModule.scala            |  2 +-
 .../auth/basic/BasicAuthService.scala          |  2 +-
 .../auth/ldap/LDAPAuthService.scala            |  2 +-
 app/dao/RestHistoryDAO.scala                   |  6 +++---
 app/dao/RestRequest.scala                      |  2 +-
 app/elastic/HTTPElasticClient.scala            |  2 +-
 app/models/Hosts.scala                         | 18 +++++++++++-------
 conf/reference.conf                            |  2 +-
 10 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/app/controllers/AuthController.scala b/app/controllers/AuthController.scala
index e798f07..e7699c4 100644
--- a/app/controllers/AuthController.scala
+++ b/app/controllers/AuthController.scala
@@ -60,7 +60,7 @@ class AuthController @Inject()(system: ActorSystem,
   }
 
   def logout = Action { _ =>
-    val prefix = configuration.getString("play.http.context").getOrElse("/")
+    val prefix = configuration.getOptional[String]("play.http.context").getOrElse("/")
     Redirect(s"${prefix}login").withNewSession
   }
 
diff --git a/app/controllers/auth/AuthConfig.scala b/app/controllers/auth/AuthConfig.scala
index 7f125f2..e702712 100644
--- a/app/controllers/auth/AuthConfig.scala
+++ b/app/controllers/auth/AuthConfig.scala
@@ -5,7 +5,7 @@ import play.api.Configuration
 trait AuthConfig {
 
   def getSetting(setting: String)(implicit config: Configuration) = {
-    config.getString(setting).getOrElse(throw MissingSettingException(setting))
+    config.getOptional[String](setting).getOrElse(throw MissingSettingException(setting))
   }
 
 }
diff --git a/app/controllers/auth/AuthenticationModule.scala b/app/controllers/auth/AuthenticationModule.scala
index f17ddff..9d6efa3 100644
--- a/app/controllers/auth/AuthenticationModule.scala
+++ b/app/controllers/auth/AuthenticationModule.scala
@@ -17,7 +17,7 @@ trait AuthenticationModule {
 @Singleton
 class AuthenticationModuleImpl @Inject()(config: Configuration) extends AuthenticationModule {
 
-  val service = config.getString("auth.type") match {
+  val service = config.getOptional[String]("auth.type") match {
     case Some("ldap")  => Some(new LDAPAuthService(config))
     case Some("basic") => Some(new BasicAuthService(config))
     case _             => None
diff --git a/app/controllers/auth/basic/BasicAuthService.scala b/app/controllers/auth/basic/BasicAuthService.scala
index bd073c6..9d23e63 100644
--- a/app/controllers/auth/basic/BasicAuthService.scala
+++ b/app/controllers/auth/basic/BasicAuthService.scala
@@ -6,7 +6,7 @@ import play.api.Configuration
 
 class BasicAuthService @Inject()(globalConfig: Configuration) extends AuthService {
 
-  private implicit final val config = new BasicAuthConfig(globalConfig.getConfig("auth.settings").get)
+  private implicit final val config = new BasicAuthConfig(globalConfig.get[Configuration]("auth.settings"))
 
   def auth(username: String, password: String): Option[String] = {
     (username, password) match {
diff --git a/app/controllers/auth/ldap/LDAPAuthService.scala b/app/controllers/auth/ldap/LDAPAuthService.scala
index f23d624..a26dbe8 100644
--- a/app/controllers/auth/ldap/LDAPAuthService.scala
+++ b/app/controllers/auth/ldap/LDAPAuthService.scala
@@ -14,7 +14,7 @@ class LDAPAuthService @Inject()(globalConfig: Configuration) extends AuthService
 
   private val log = org.slf4j.LoggerFactory.getLogger(classOf[LDAPAuthService])
 
-  private final val config = new LDAPAuthConfig(globalConfig.getConfig("auth.settings").get)
+  private final val config = new LDAPAuthConfig(globalConfig.get[Configuration]("auth.settings"))
 
   def auth(username: String, password: String): Option[String] = {
     val env = new Hashtable[String, String](11)
diff --git a/app/dao/RestHistoryDAO.scala b/app/dao/RestHistoryDAO.scala
index 8a3ab88..f5d61c2 100644
--- a/app/dao/RestHistoryDAO.scala
+++ b/app/dao/RestHistoryDAO.scala
@@ -5,8 +5,8 @@ import java.util.Date
 import com.google.inject.{ImplementedBy, Inject}
 import play.api.Configuration
 import play.api.db.slick.DatabaseConfigProvider
-import slick.driver.JdbcProfile
-import slick.driver.SQLiteDriver.api._
+import slick.jdbc.JdbcProfile
+import slick.jdbc.SQLiteProfile.api._
 import slick.lifted.TableQuery
 
 import scala.concurrent.ExecutionContext.Implicits.global
@@ -28,7 +28,7 @@ trait RestHistoryDAO {
 class RestHistoryDAOImpl @Inject()(dbConfigProvider: DatabaseConfigProvider,
                                    config: Configuration) extends RestHistoryDAO {
 
-  private val max = config.getInt("rest.history.size").getOrElse(50)
+  private val max = config.getOptional[Int]("rest.history.size").getOrElse(50)
 
   private val dbConfig = dbConfigProvider.get[JdbcProfile]
 
diff --git a/app/dao/RestRequest.scala b/app/dao/RestRequest.scala
index 9b02a90..9178e44 100644
--- a/app/dao/RestRequest.scala
+++ b/app/dao/RestRequest.scala
@@ -3,7 +3,7 @@ package dao
 import java.security.MessageDigest
 import java.util.Date
 
-import slick.driver.SQLiteDriver.api._
+import slick.jdbc.SQLiteProfile.api._
 import slick.lifted.Tag
 
 case class HashedRestRequest(path: String, method: String, body: String, username: String, createdAt: Long, md5: String)
diff --git a/app/elastic/HTTPElasticClient.scala b/app/elastic/HTTPElasticClient.scala
index 3498b5f..80a05c2 100644
--- a/app/elastic/HTTPElasticClient.scala
+++ b/app/elastic/HTTPElasticClient.scala
@@ -322,7 +322,7 @@ class HTTPElasticClient @Inject()(client: WSClient) extends ElasticClient {
     val authentication = target.authentication
     val url = s"${target.host.replaceAll("/+$", "")}$uri"
     val request =
-      authentication.foldLeft(client.url(url).withMethod(method).withHeaders(headers: _*)) {
+      authentication.foldLeft(client.url(url).withMethod(method).withHttpHeaders(headers: _*)) {
       case (request, auth) =>
         request.withAuth(auth.username, auth.password, WSAuthScheme.BASIC)
     }
diff --git a/app/models/Hosts.scala b/app/models/Hosts.scala
index 17d96a6..0516078 100644
--- a/app/models/Hosts.scala
+++ b/app/models/Hosts.scala
@@ -5,6 +5,10 @@ import javax.inject.Singleton
 import com.google.inject.{ImplementedBy, Inject}
 import play.api.Configuration
 
+import scala.collection.JavaConverters._
+import scala.util.{Failure, Success, Try}
+
+
 @ImplementedBy(classOf[HostsImpl])
 trait Hosts {
 
@@ -17,18 +21,18 @@ trait Hosts {
 @Singleton
 class HostsImpl @Inject()(config: Configuration) extends Hosts {
 
-  val hosts: Map[String, ElasticServer] = config.getConfigSeq("hosts") match {
-    case Some(hostsConf) => hostsConf.map { hostConf =>
-      val host = hostConf.getString("host").get
-      val name = hostConf.getString("name").getOrElse(host)
-      val username = hostConf.getString("auth.username")
-      val password = hostConf.getString("auth.password")
+  val hosts: Map[String, ElasticServer] = Try(config.underlying.getConfigList("hosts").asScala.map(Configuration(_))) match {
+    case Success(hostsConf) => hostsConf.map { hostConf =>
+      val host = hostConf.getOptional[String]("host").get
+      val name = hostConf.getOptional[String]("name").getOrElse(host)
+      val username = hostConf.getOptional[String]("auth.username")
+      val password = hostConf.getOptional[String]("auth.password")
       (username, password) match {
         case (Some(username), Some(password)) => (name -> ElasticServer(host, Some(ESAuth(username, password))))
         case _ => (name -> ElasticServer(host, None))
       }
     }.toMap
-    case _ => Map()
+    case Failure(_) => Map()
   }
 
   def getHostNames() = hosts.keys.toSeq
diff --git a/conf/reference.conf b/conf/reference.conf
index da6cf2e..6ebc38a 100644
--- a/conf/reference.conf
+++ b/conf/reference.conf
@@ -1,6 +1,6 @@
 # Secret key
 secret = "changeme"
-play.crypto.secret = ${secret}
+play.http.secret.key = ${secret}
 
 es {
   gzip = false
-- 
GitLab