-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of concept - add API to patch config
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 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
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,28 @@ | ||
import cats.effect._ | ||
import configuration.{Configuration, ConfigurationRedactor, ConfigurationUtils, MapAndFileAndSystemPropertyReader} | ||
import http.HttpClient | ||
import org.http4s._ | ||
import org.http4s.circe.CirceEntityCodec.circeEntityDecoder | ||
import org.http4s.dsl.io._ | ||
import org.slf4j.LoggerFactory | ||
|
||
object Routes { | ||
|
||
private val logger = LoggerFactory.getLogger(getClass) | ||
private def routes(configRef: Ref[IO, Configuration], client: HttpClient): HttpRoutes[IO] = HttpRoutes.of[IO] { | ||
|
||
case req @ PATCH -> Root / "config" => | ||
logger.info(s"Received request: $req") | ||
val result = for { | ||
rawConfiguration <- req.as[Map[String, String]] | ||
_ = logger.info(s"Parsed into $rawConfiguration") | ||
newConfiguration <- ConfigurationUtils.create(new MapAndFileAndSystemPropertyReader(rawConfiguration), client) | ||
_ = logger.info(s"New configuration: $newConfiguration") | ||
_ <- configRef.set(newConfiguration) | ||
} yield newConfiguration | ||
|
||
Ok(result.map(ConfigurationRedactor.redactToString)) | ||
} | ||
|
||
def service(configRef: Ref[IO, Configuration], client: HttpClient): HttpRoutes[IO] = routes(configRef, client) | ||
} |
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,8 @@ | ||
package configuration | ||
|
||
class MapAndFileAndSystemPropertyReader(map: Map[String, String]) extends ConfigurationReader { | ||
override def getConfigOption(key: String): Option[String] = map.get(key) match { | ||
case r@Some(_) => r | ||
case None => FileAndSystemPropertyReader.getConfigOption(key) | ||
} | ||
} |