From 7022b9f5dbc3cf2cb09678c49b987847b2acb8c3 Mon Sep 17 00:00:00 2001 From: To-om Date: Thu, 18 Mar 2021 10:57:01 +0100 Subject: [PATCH] #1843 Use map instead of foldLeft --- .../controllers/v1/MonitoringCtrl.scala | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala index a6dc213d67..3729b0a96d 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala @@ -23,8 +23,9 @@ 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") @@ -32,17 +33,15 @@ class MonitoringCtrl @Inject() ( 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)) ) }