Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config parameters optional #122

Merged
merged 11 commits into from
Jan 9, 2022
Merged

Conversation

rr83019
Copy link
Contributor

@rr83019 rr83019 commented Jan 7, 2022

closes #105

@hrj
Copy link
Contributor

hrj commented Jan 9, 2022

I was able to get it to work after some trial and error:

When using Option for extraction, we need to use java types instead of scala types. So this works:

case class ConfigField(
                        port: Option[Integer],
                        address: Option[String],
                        throttle: Option[Integer],
                        seed: Option[Integer],
                        captchaExpiryTimeLimit: Option[Integer],
                        threadDelay: Option[Integer],
                        boolTest: Option[java.lang.Boolean],
                        corsHeader: Option[String],
                        maxAttempts: Option[Integer]
                      )

Needs to be converted to the correct Scala type later. So I did this hack:

 case class ConfigField(
  port: Option[Integer],
  address: Option[String],
  throttle: Option[Integer],
  seed: Option[Integer],
  captchaExpiryTimeLimit: Option[Integer],
  threadDelay: Option[Integer],
  boolTest: Option[java.lang.Boolean],
  corsHeader: Option[String],
  maxAttempts: Option[Integer]
) {
  val portInt = port.map(_ + 0)
  val boolTestBoolean = boolTest.map(_ || true)
}

...

  val fields = configJson.extract[ConfigField]

  val port1: Int = fields.portInt.getOrElse(8888)
  val address1: String = fields.address.getOrElse("0.0.0.0")
  val boolTest: Boolean = fields.boolTestBoolean.getOrElse(true)

@rr83019 rr83019 requested a review from hrj January 9, 2022 16:10
src/main/scala/lc/core/models.scala Outdated Show resolved Hide resolved
src/main/scala/lc/core/config.scala Outdated Show resolved Hide resolved
@rr83019 rr83019 requested a review from hrj January 9, 2022 17:05
@hrj hrj merged commit 715758a into librecaptcha:master Jan 9, 2022
@rr83019 rr83019 deleted the opt-config-param branch January 9, 2022 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config parameters that have defaults should be optional
2 participants