problem: need to setup upstream auth w/o storing passwords in config

solution: use environment variable placeholders
This commit is contained in:
Igor Artamonov
2019-08-07 22:50:07 -04:00
parent 29691c4025
commit 24c325f83a
2 changed files with 33 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ import java.net.URI
class UpstreamsConfigReader {
private val log = LoggerFactory.getLogger(UpstreamsConfigReader::class.java)
private val envRegex = Regex("\\$\\{(\\w+?)}")
fun read(input: InputStream): UpstreamsConfig {
val yaml = Yaml()
@@ -198,12 +199,13 @@ class UpstreamsConfigReader {
private fun getListOfString(mappingNode: MappingNode?, key: String): List<String>? {
return getList<ScalarNode>(mappingNode, key)?.value
?.map { it.value }
?.map(this::postProcess)
}
private fun getValueAsString(mappingNode: MappingNode?, key: String): String? {
return getValue(mappingNode, key)?.let {
return@let it.value
}
}?.let(this::postProcess)
}
private fun getValueAsInt(mappingNode: MappingNode?, key: String): Int? {
@@ -233,4 +235,12 @@ class UpstreamsConfigReader {
throw IllegalArgumentException("Not a map")
}
}
fun postProcess(value: String): String {
return envRegex.replace(value) { m ->
m.groups[1]?.let { g ->
System.getProperty(g.value) ?: System.getenv(g.value) ?: ""
} ?: ""
}
}
}