Skip to content

Commit

Permalink
#1843 Use map instead of foldLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 18, 2021
1 parent fbc042d commit 7022b9f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ class MonitoringCtrl @Inject() (
implicit val format: Format[PartitionConfig] = Json.format[PartitionConfig]
}

val diskLocations: ConfigItem[Seq[PartitionConfig], Seq[PartitionConfig]] =
val diskLocationsConfig: ConfigItem[Seq[PartitionConfig], Seq[PartitionConfig]] =
appConfig.item[Seq[PartitionConfig]]("monitor.disk", "disk locations to monitor")
def diskLocations: Seq[PartitionConfig] = diskLocationsConfig.get

def diskUsage: Action[AnyContent] =
entrypoint("monitor disk usage")
.authPermittedTransaction(db, Permissions.managePlatform)(implicit request =>
implicit graph =>
for {
_ <- Success(())
locations =
diskLocations
.get
.foldLeft[JsArray](JsArray.empty)((array, p) =>
array :+ Json.obj(
"location" -> p.location,
"freeSpace" -> new File(p.location).getFreeSpace,
"totalSpace" -> new File(p.location).getTotalSpace
)
)
} yield Results.Ok(locations)
locations = diskLocations.map { dl =>
val file = new File(dl.location)
Json.obj(
"location" -> dl.location,
"freeSpace" -> file.getFreeSpace,
"totalSpace" -> file.getTotalSpace
)
}
} yield Results.Ok(JsArray(locations))
)

}

0 comments on commit 7022b9f

Please sign in to comment.