remove old http4k application props
This commit is contained in:
parent
5ac50e8412
commit
ae0d95b4cb
4 changed files with 3 additions and 192 deletions
|
|
@ -31,67 +31,3 @@ data class ApplicationProperties(
|
||||||
.loadConfigOrThrow()
|
.loadConfigOrThrow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//import dev.adamko.kafkatorio.processor.config.PortVal.Companion.portVal
|
|
||||||
//import java.nio.file.Path
|
|
||||||
//import java.time.Clock
|
|
||||||
//import java.util.Properties
|
|
||||||
//import kotlin.io.path.Path
|
|
||||||
//import org.http4k.cloudnative.env.Environment
|
|
||||||
//import org.http4k.cloudnative.env.EnvironmentKey
|
|
||||||
//import org.http4k.lens.nonEmptyString
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Load properties, in descending priority order, from
|
|
||||||
// *
|
|
||||||
// * 1. Environment variables
|
|
||||||
// * 2. This app's env file (as defined by the environment variable [Lenses.APPLICATION_PROPERTIES_FILE_PATH])
|
|
||||||
// * # 3. A resources-dir yaml file
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
//internal class ApplicationProperties(
|
|
||||||
// vararg environments: Environment = arrayOf(
|
|
||||||
// Environment.env(),
|
|
||||||
// Environment.fromEnvVarPath(),
|
|
||||||
// Environment.fromResourcesFile(".secret.config.yml")
|
|
||||||
// )
|
|
||||||
//) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// private val appProps: Environment =
|
|
||||||
// environments.reduce { acc, environment -> acc.overrides(environment) }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// fun clock(): Clock = Clock.systemUTC()
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * The port of the server
|
|
||||||
// *
|
|
||||||
// * Set by GCP ([docs](https://cloud.google.com/run/docs/reference/container-contract#env-vars)).
|
|
||||||
// */
|
|
||||||
// val serverPort: PortVal
|
|
||||||
// get() = EnvironmentKey.portVal().defaulted("PORT", PortVal.DEFAULT)[appProps]
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// val kafkaConfig: Properties
|
|
||||||
// get() = EnvironmentKey
|
|
||||||
// .nonEmptyString()
|
|
||||||
// .map { srcString ->
|
|
||||||
// srcString.reader().use { stringReader ->
|
|
||||||
// Properties().also { properties ->
|
|
||||||
// properties.load(stringReader)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// .required("kafka.config")[appProps]
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// val webmapTileDir: Path
|
|
||||||
// get() = EnvironmentKey
|
|
||||||
// .nonEmptyString()
|
|
||||||
// .map(::Path)
|
|
||||||
// .required("tileServer.webmapTileDir")[appProps]
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
package dev.adamko.kafkatorio.processor.config
|
|
||||||
|
|
||||||
//import java.io.File
|
|
||||||
//import org.http4k.cloudnative.env.Environment
|
|
||||||
//import org.http4k.cloudnative.env.EnvironmentKey
|
|
||||||
//import org.http4k.core.Credentials
|
|
||||||
//import org.http4k.lens.BiDiLens
|
|
||||||
//import org.http4k.lens.BiDiMapping
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//internal object Lenses {
|
|
||||||
//
|
|
||||||
// /** The location of this app's env file. */
|
|
||||||
// val APPLICATION_PROPERTIES_FILE_PATH: BiDiLens<Environment, File?> =
|
|
||||||
// EnvironmentKey
|
|
||||||
// .map(
|
|
||||||
// { path: String -> File(path) },
|
|
||||||
// { file: File -> file.canonicalPath },
|
|
||||||
// )
|
|
||||||
// .optional("APPLICATION_PROPERTIES_FILE_PATH")
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /** Bidirectional [String] and [Credentials] mapper. */
|
|
||||||
// val credentialsLens: BiDiMapping<String, Credentials> = run {
|
|
||||||
// val separator = ":"
|
|
||||||
// BiDiMapping(
|
|
||||||
// // from String to Credentials
|
|
||||||
// { property ->
|
|
||||||
// property.split(separator, limit = 2)
|
|
||||||
// .takeIf { it.size == 2 }
|
|
||||||
// ?.let { (user, pass) -> Credentials(user, pass) }
|
|
||||||
// ?: throw IllegalArgumentException("Credentials are invalid")
|
|
||||||
// },
|
|
||||||
// // from Credentials to String
|
|
||||||
// { it.user + separator + it.password }
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
package dev.adamko.kafkatorio.processor.config
|
package dev.adamko.kafkatorio.processor.config
|
||||||
|
|
||||||
import org.http4k.cloudnative.env.Port
|
import org.http4k.cloudnative.env.Port
|
||||||
import org.http4k.lens.BiDiLensSpec
|
|
||||||
import org.http4k.lens.StringBiDiMappings.int
|
|
||||||
import org.http4k.lens.map
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Improved (slightly) version of http4k's [Port].
|
/** Improved (slightly) version of http4k's [Port]. */
|
||||||
*/
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class PortVal(val value: Int) {
|
value class PortVal(val value: Int) {
|
||||||
|
|
||||||
|
|
@ -21,10 +17,6 @@ value class PortVal(val value: Int) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT = PortVal(8080)
|
val DEFAULT = PortVal(8080)
|
||||||
val VALID_RANGE: IntRange
|
val VALID_RANGE: IntRange = 1..65535
|
||||||
get() = (1..65535)
|
|
||||||
|
|
||||||
fun <IN : Any> BiDiLensSpec<IN, String>.portVal(): BiDiLensSpec<IN, PortVal> =
|
|
||||||
map(int().map(::PortVal, PortVal::value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
package dev.adamko.kafkatorio.processor.config
|
|
||||||
|
|
||||||
//import java.io.File
|
|
||||||
//import java.io.FileNotFoundException
|
|
||||||
//import org.http4k.cloudnative.env.Environment
|
|
||||||
//import org.http4k.cloudnative.env.MapEnvironment
|
|
||||||
//import org.http4k.cloudnative.env.fromYaml
|
|
||||||
//import org.http4k.lens.Lens
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Load properties from either a `.yaml` or `.env` file.
|
|
||||||
// *
|
|
||||||
// * (An improved version of [Environment.fromResource])
|
|
||||||
// */
|
|
||||||
//fun Environment.Companion.fromResourcesFile(
|
|
||||||
// resource: String,
|
|
||||||
// default: Environment = EMPTY
|
|
||||||
//): Environment {
|
|
||||||
// return try {
|
|
||||||
// val file =
|
|
||||||
// this::class.java
|
|
||||||
// .getResource("/${resource.removePrefix("/")}")
|
|
||||||
// ?.file
|
|
||||||
// ?.let { File(it) }
|
|
||||||
// fromFile(file, default)
|
|
||||||
// } catch (e: FileNotFoundException) {
|
|
||||||
// default
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Try fetching a properties file the location provided by the
|
|
||||||
// * [`JVM`][jvmProperties] or [`System`][env] environment variable
|
|
||||||
// * [Lenses.APPLICATION_PROPERTIES_FILE_PATH], if it exists.
|
|
||||||
// *
|
|
||||||
// * If it does not exist, return [default].
|
|
||||||
// */
|
|
||||||
//fun Environment.Companion.fromEnvVarPath(
|
|
||||||
// location: Lens<Environment, File?> = Lenses.APPLICATION_PROPERTIES_FILE_PATH,
|
|
||||||
// default: Environment = EMPTY,
|
|
||||||
//): Environment {
|
|
||||||
// val file = (jvmProperties() overrides env())[location]
|
|
||||||
//
|
|
||||||
// return fromFile(file, default)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Load properties from either a `.yaml` or `.env` file.
|
|
||||||
// *
|
|
||||||
// * (An improved version of [Environment.from])
|
|
||||||
// */
|
|
||||||
//internal fun Environment.Companion.fromFile(
|
|
||||||
// file: File?,
|
|
||||||
// default: Environment = EMPTY,
|
|
||||||
//): Environment {
|
|
||||||
// return file
|
|
||||||
// ?.takeIf { it.isFile }
|
|
||||||
// .let {
|
|
||||||
// when (it?.extension) {
|
|
||||||
// "yml", "yaml" -> fromYaml(it)
|
|
||||||
// "env" -> from(it)
|
|
||||||
// else -> default
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///** The same as [Environment.ENV], but refreshes on each invocation (which is useful for testing). */
|
|
||||||
//fun Environment.Companion.env(): Environment =
|
|
||||||
// MapEnvironment.from(System.getenv().toProperties())
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///** The same as [Environment.JVM_PROPERTIES], but refreshes on each invocation (which is useful for testing). */
|
|
||||||
//internal fun Environment.Companion.jvmProperties(): Environment =
|
|
||||||
// MapEnvironment.from(System.getProperties())
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue