Commit 792b6c51 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

Merge branch 'develop'

parents fab0c1f5 4180991d
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -5,30 +5,31 @@ import javax.inject.Inject
import controllers.auth.AuthenticationModule
import elastic.ElasticClient
import models.CerebroResponse
import play.api.Play
import play.api.Configuration
import play.api.libs.json.{JsArray, Json}
import play.api.mvc.Controller


class ConnectController @Inject()(val authentication: AuthenticationModule,
                                  config: Configuration,
                                  client: ElasticClient) extends Controller with AuthSupport {

  def index = AuthAction(authentication) {
    request => {
      val hosts = Play.current.configuration.getConfigSeq("hosts") match {
        case Some(configs) =>
          configs.map { config =>
            val username = config.getString("auth.username")
            val password = config.getString("auth.password")
      val hosts = config.getConfigSeq("hosts") match {
        case Some(hostsConfig) =>
          hostsConfig.map { hostConfig =>
            val username = hostConfig.getString("auth.username")
            val password = hostConfig.getString("auth.password")
            (username, password) match {
              case (Some(username), Some(password)) =>
                Json.obj(
                  "host" -> config.getString("host").get,
                  "host" -> hostConfig.getString("host").get,
                  "username" -> username,
                  "password" -> password
                )
              case _ =>
                Json.obj("host" -> config.getString("host").get)
                Json.obj("host" -> hostConfig.getString("host").get)
            }
          }
        case None =>
+5 −0
Original line number Diff line number Diff line
package models

import play.api.libs.json.JsValue

case class UnexpectedResponseFormatException(response: JsValue) extends RuntimeException(s"Unexpected format for [${response.toString}]")
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ object Nodes {
    val load = (nodeStats \ "os" \ "cpu" \ "load_average" \ "1m").asOpt[Float].getOrElse( // 5.X
      (nodeStats \ "os" \ "load_average").asOpt[Float].getOrElse(0f) // FIXME: 2.X
    )
    JsNumber(BigDecimal(load))
    JsNumber(BigDecimal(load.toDouble))
  }

  def cpuPercent(nodeStats: JsValue): JsNumber = {
+2 −0
Original line number Diff line number Diff line
package models.repository

import models.UnexpectedResponseFormatException
import play.api.libs.json.{JsArray, JsObject, JsValue, Json}

object Repositories {
@@ -16,6 +17,7 @@ object Repositories {
            )
          }.toSeq
        )
      case _ => throw UnexpectedResponseFormatException(json)
    }
  }

+6 −6
Original line number Diff line number Diff line
@@ -2,14 +2,14 @@ name := "cerebro"

version := "0.5.0"

scalaVersion := "2.11.6"
scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play"          % "2.4.6",
  "com.typesafe.play" %% "play-ws"       % "2.4.6",
  "org.specs2"        %% "specs2-junit"  % "3.6.5" % "test",
  "org.specs2"        %% "specs2-core"   % "3.6.5" % "test",
  "org.specs2"        %% "specs2-mock"   % "3.6.5" % "test"
  "com.typesafe.play" %% "play"          % "2.5.10",
  "com.typesafe.play" %% "play-ws"       % "2.5.10",
  "org.specs2"        %% "specs2-junit"  % "3.8.4" % "test",
  "org.specs2"        %% "specs2-core"   % "3.8.4" % "test",
  "org.specs2"        %% "specs2-mock"   % "3.8.4" % "test"
)

lazy val root = (project in file(".")).enablePlugins(PlayScala)
Loading