mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-02-11 18:58:06 -05:00
Make config parameters optional with defaults
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
8a87da88c0
commit
8e39505644
@ -42,15 +42,15 @@ class Config(configFilePath: String) {
|
|||||||
|
|
||||||
private val configJson = parse(configString)
|
private val configJson = parse(configString)
|
||||||
|
|
||||||
val port: Int = (configJson \ AttributesEnum.PORT.toString).extract[Int]
|
val port: Int = getOptionalConfigParam(AttributesEnum.PORT.toString, "8888").toInt
|
||||||
val address: String = (configJson \ AttributesEnum.ADDRESS.toString).extract[String]
|
val address: String = getOptionalConfigParam(AttributesEnum.ADDRESS.toString, "0.0.0.0")
|
||||||
val throttle: Int = (configJson \ AttributesEnum.THROTTLE.toString).extract[Int]
|
val throttle: Int = getOptionalConfigParam(AttributesEnum.THROTTLE.toString, "1000").toInt
|
||||||
val seed: Int = (configJson \ AttributesEnum.RANDOM_SEED.toString).extract[Int]
|
val seed: Int = getOptionalConfigParam(AttributesEnum.RANDOM_SEED.toString, "375264328").toInt
|
||||||
val captchaExpiryTimeLimit: Int = (configJson \ AttributesEnum.CAPTCHA_EXPIRY_TIME_LIMIT.toString).extract[Int]
|
val captchaExpiryTimeLimit: Int = getOptionalConfigParam(AttributesEnum.CAPTCHA_EXPIRY_TIME_LIMIT.toString, "5").toInt
|
||||||
val threadDelay: Int = (configJson \ AttributesEnum.THREAD_DELAY.toString).extract[Int]
|
val threadDelay: Int = getOptionalConfigParam(AttributesEnum.THREAD_DELAY.toString, "2").toInt
|
||||||
val playgroundEnabled: Boolean = (configJson \ AttributesEnum.PLAYGROUND_ENABLED.toString).extract[Boolean]
|
val playgroundEnabled: Boolean = getOptionalConfigParam(AttributesEnum.PLAYGROUND_ENABLED.toString, "true").toBoolean
|
||||||
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
|
val corsHeader: String = getOptionalConfigParam(AttributesEnum.CORS_HEADER.toString, "")
|
||||||
val maxAttempts: Int = (configJson \ AttributesEnum.MAX_ATTEMPTS.toString).extract[Int]
|
val maxAttempts: Int = getOptionalConfigParam(AttributesEnum.MAX_ATTEMPTS.toString, "10").toInt
|
||||||
|
|
||||||
private val captchaConfigJson = (configJson \ "captchas")
|
private val captchaConfigJson = (configJson \ "captchas")
|
||||||
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
||||||
@ -63,6 +63,19 @@ class Config(configFilePath: String) {
|
|||||||
|
|
||||||
HelperFunctions.setSeed(seed)
|
HelperFunctions.setSeed(seed)
|
||||||
|
|
||||||
|
private def getOptionalConfigParam(paramName: String, defaultValue: String): String = {
|
||||||
|
val param: Option[(String, JValue)] = (configJson findField({
|
||||||
|
case JField(`paramName`, _) => true
|
||||||
|
case _ => false
|
||||||
|
}))
|
||||||
|
|
||||||
|
if(param.isDefined){
|
||||||
|
param.get._2.extract[String]
|
||||||
|
} else {
|
||||||
|
defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def getDefaultConfig(): String = {
|
private def getDefaultConfig(): String = {
|
||||||
val defaultConfigMap =
|
val defaultConfigMap =
|
||||||
(AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~
|
(AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user