Skip to content

Commit

Permalink
Reduce method complexity in order to improve its readability & perfor…
Browse files Browse the repository at this point in the history
…mance (apache#63)
  • Loading branch information
pfcoperez authored and jlopezmalla committed Sep 15, 2017
1 parent 67f274f commit 9d7a92a
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions core/src/main/scala/org/apache/spark/security/ConfigSecurity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,16 @@ object ConfigSecurity extends Logging{
}
}


private def prepareEnvironment(vaultHost: String,
vaultToken: String,
secretOptions: Map[String,
Map[String, String]]): Map[String, String] = {
val seqOp: (Map[String, String], (String, Map[String, String])) => Map[String, String] =
(agg: Map[String, String], value: (String, Map[String, String])) => {
val (key, options) = value
val secretOptions = key match {
case "kerberos" => KerberosConfig.prepareEnviroment(vaultHost,
vaultToken,
options)
case "datastore" => SSLConfig.prepareEnvironment(vaultHost,
vaultToken,
SSLConfig.sslTypeDataStore,
options)
case _ => Map[String, String]()
}
secretOptions ++ agg
}
val combOp: (Map[String, String], Map[String, String]) => Map[String, String] =
(agg1: Map[String, String], agg2: Map[String, String]) => agg1 ++ agg2

secretOptions.aggregate(Map[String, String]())(seqOp, combOp)
}
Map[String, String]]): Map[String, String] =
secretOptions flatMap {
case ("kerberos", options) =>
KerberosConfig.prepareEnviroment(vaultHost, vaultToken, options)
case ("datastore", options) =>
SSLConfig.prepareEnvironment(vaultHost, vaultToken, SSLConfig.sslTypeDataStore, options)
case _ => Map.empty[String, String]
}

}

0 comments on commit 9d7a92a

Please sign in to comment.