diff --git a/src/main/kotlin/de/joshavg/Builds.kt b/src/main/kotlin/de/joshavg/Builds.kt index 5425f4c..ad9af1e 100644 --- a/src/main/kotlin/de/joshavg/Builds.kt +++ b/src/main/kotlin/de/joshavg/Builds.kt @@ -1,6 +1,8 @@ package de.joshavg import org.eclipse.microprofile.config.inject.ConfigProperty +import org.slf4j.Logger +import org.slf4j.LoggerFactory import java.io.File import java.nio.file.Files import java.nio.file.Paths @@ -12,24 +14,38 @@ import javax.enterprise.context.ApplicationScoped data class BuildConfig(val exec: String, val user: String, val dir: String, - val key: String? = null) { - fun asPublic() = copy(key = null) + val key: String, + val env: Map) { + fun asPublic() = copy(key = "") } @ApplicationScoped class Builds(@ConfigProperty(name = "ALFRED_HOME") - val home: String) { + private val home: String) { + + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + init { + logger.info("ALFRED_HOME is $home") + } fun buildConfig(build: String): BuildConfig { val path = Paths.get(home, "builds", "$build.properties") val props = Properties() props.load(path.toFile().inputStream()) + val env = props + .entries + .filter { it.key.toString() == it.key.toString().toUpperCase() } + .map { Pair(it.key.toString(), it.value.toString()) } + .toMap() + return BuildConfig( exec = props.getProperty("exec"), user = props.getProperty("user"), dir = props.getProperty("dir"), - key = props.getProperty("key")) + key = props.getProperty("key") ?: "", + env = env) } fun createLogFile(build: String): File { diff --git a/src/main/kotlin/de/joshavg/BuildsEndpoint.kt b/src/main/kotlin/de/joshavg/BuildsEndpoint.kt index 15f3b44..bee047a 100644 --- a/src/main/kotlin/de/joshavg/BuildsEndpoint.kt +++ b/src/main/kotlin/de/joshavg/BuildsEndpoint.kt @@ -52,12 +52,17 @@ class BuildsEndpoint( logger.info("preparing process for build $build with config ${config.asPublic()}") logger.info("log file: $logFile") - val builder = ProcessBuilder(config.exec) + val pid = ProcessBuilder(config.exec) .directory(File(config.dir)) .redirectOutput(logFile) .redirectError(logFile) - val process = builder.start() - val pid = process.toHandle().pid() + .apply { + environment().putAll(config.env) + environment()["ALFRED_LOG_FILE"] = logFile.absolutePath + } + .start() + .toHandle() + .pid() logger.info("pid for build $build is: $pid") }.start() diff --git a/src/main/kotlin/de/joshavg/ExampleResource.kt b/src/main/kotlin/de/joshavg/ExampleResource.kt deleted file mode 100644 index a8d7ff6..0000000 --- a/src/main/kotlin/de/joshavg/ExampleResource.kt +++ /dev/null @@ -1,14 +0,0 @@ -package de.joshavg - -import javax.ws.rs.GET -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.MediaType - -@Path("/hello") -class ExampleResource { - - @GET - @Produces(MediaType.TEXT_PLAIN) - fun hello() = "hello" -} diff --git a/src/main/kotlin/de/joshavg/Security.kt b/src/main/kotlin/de/joshavg/Security.kt index 17469cd..9faa97f 100644 --- a/src/main/kotlin/de/joshavg/Security.kt +++ b/src/main/kotlin/de/joshavg/Security.kt @@ -10,7 +10,7 @@ class Security(@Inject fun requireKey(build: String, key: String?, block: (BuildConfig) -> Any): Response { val buildConfig = builds.buildConfig(build) - if (buildConfig.key != key) { + if (buildConfig.key != "" && buildConfig.key != key) { return Response.status(Response.Status.UNAUTHORIZED).build() }