-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iss #24: universal config: postprocessors, config parsers
- Loading branch information
Showing
22 changed files
with
432 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
20 changes: 0 additions & 20 deletions
20
ambient7-webapp/src/main/scala/ru/maizy/ambient7/webapp/WebAppConfigParser.scala
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
ambient7-webapp/src/main/scala/ru/maizy/ambient7/webapp/WebAppConfigReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ru.maizy.ambient7.webapp | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
import ru.maizy.ambient7.core.config.{ MainDbConfigReader, UniversalConfigReader } | ||
|
||
object WebAppConfigReader | ||
extends UniversalConfigReader | ||
with MainDbConfigReader | ||
{ | ||
override def appName: String = "java -jar ambient7-webapp.jar" | ||
|
||
override def fillReader(): Unit = { | ||
fillConfigOptions(requireUniversalConfig = true) | ||
fillDbOptions() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// sample production config | ||
db { | ||
url = "jdbc:h2:file:/var/ambient7/analysis;AUTO_SERVER=TRUE" | ||
user = "ambient7" | ||
password = "" | ||
} | ||
|
||
co2-devices = [ | ||
{ | ||
id = "main" | ||
agent-name = "main" | ||
agent-tags = "" | ||
model = "mt8057" | ||
} | ||
|
||
{ | ||
id = "additional" | ||
agent-name = "additional" | ||
agent-tags = "place=livingroom,altitude=200" | ||
model = "mt8057" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
core/src/main/scala/ru/maizy/ambient7/core/config/InfluxDbConfigReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package ru.maizy.ambient7.core.config | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
trait InfluxDbConfigReader extends UniversalConfigReader { | ||
|
||
private def influxDbOpts(opts: Ambient7Options)(fill: InfluxDbOptions => InfluxDbOptions): Ambient7Options = { | ||
opts.copy(influxDb = Some(fill(opts.influxDb.getOrElse(InfluxDbOptions())))) | ||
} | ||
|
||
private def appendInfluxDbOptsCheck(check: InfluxDbOptions => Either[IndexedSeq[String], Unit]): Unit = | ||
appendCheck { appOpts => | ||
appOpts.influxDb match { | ||
case Some(influxDbOptions) => check(influxDbOptions) | ||
case _ => Left(IndexedSeq("InfluxDB opts not defined")) | ||
} | ||
} | ||
|
||
// private def appendInfluxDbOptsPostprocessor(postprocessor: InfluxDbOptions => ParseResult): Unit = | ||
// appendPostprocessor { appOpts => | ||
// appOpts.influxDb match { | ||
// case Some(influxDbOptions) => postprocessor(influxDbOptions) | ||
// case _ => Right(appOpts) | ||
// } | ||
// } | ||
|
||
def fillInfluxDbOptions(): Unit = { | ||
|
||
cliParser.opt[String]("influxdb-baseurl") | ||
.valueName { s"<${Defaults.INFLUXDB_BASEURL}>" } | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(baseUrl = value)) } | ||
|
||
|
||
cliParser.opt[String]("influxdb-database") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(database = Some(value))) } | ||
.required() | ||
|
||
appendInfluxDbOptsCheck({ | ||
opts => Either.cond(opts.database.isDefined, (), IndexedSeq("influxdb-database is required")) | ||
}) | ||
|
||
|
||
cliParser.opt[String]("influxdb-user") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(user = Some(value))) } | ||
|
||
appendInfluxDbOptsCheck({ | ||
opts => Either.cond(opts.user.isDefined, (), IndexedSeq("influxdb-user is required")) | ||
}) | ||
|
||
|
||
cliParser.opt[String]("influxdb-password") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(password = Some(value))) } | ||
|
||
appendInfluxDbOptsCheck({ | ||
opts => Either.cond(opts.password.isDefined, (), IndexedSeq("influxdb-password is required")) | ||
}) | ||
|
||
|
||
cliParser.opt[String]("influxdb-readonly-baseurl") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(readonlyBaseUrl = Some(value))) } | ||
.text("By default --influxdb-baseurl") | ||
|
||
|
||
cliParser.opt[String]("influxdb-readonly-user") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(readonlyUser = Some(value))) } | ||
.text("By default --influxdb-user") | ||
|
||
appendInfluxDbOptsCheck({ | ||
opts => Either.cond(opts.readonlyUser.isDefined, (), IndexedSeq("influxdb-readonly-user is required")) | ||
}) | ||
|
||
|
||
cliParser.opt[String]("influxdb-readonly-password") | ||
.action { (value, opts) => influxDbOpts(opts)(_.copy(readonlyPassword = Some(value))) } | ||
.text("By default --influxdb-password") | ||
|
||
appendInfluxDbOptsCheck({ | ||
opts => Either.cond(opts.readonlyPassword.isDefined, (), IndexedSeq("influxdb-readonly-password is required")) | ||
}) | ||
|
||
// TODO: uni config rules | ||
|
||
// TODO: config postprocessors | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
core/src/main/scala/ru/maizy/ambient7/core/config/UniversalConfigParser.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.